legacy_spawn
Moderators: winston, another_commander, Getafix
legacy_spawn
legacy_spawn doesn't work similiar to the old legacy-scripting method. If a ship script uses the js-method the spawned thing (cargo,...) will be positioned at the players position. And if the player is slowly travelling he will possibly collide.
The same for legacy_spawnShip. The difference is that the spawned item is sometimes positioned (0,0,0).
The old legacy scripting methods in shipdata.plist are working as expected.
The same for legacy_spawnShip. The difference is that the spawned item is sometimes positioned (0,0,0).
The old legacy scripting methods in shipdata.plist are working as expected.
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Possibly misuse of the function?? I used it already intensively in my tests and in UPS. it is working as expected in the death actions:legacy_spawn doesn't work similiar to the old legacy-scripting method. If a ship script uses the js-method the spawned thing (cargo,...) will be positioned at the players position. And if the player is slowly travelling he will possibly collide.
Code: Select all
player.commsMessage("I'll be back with help for revenge!!", 5);
system.legacy_spawn("ups-container", 5);
system.legacy_spawn("textilepod", 15);
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Seems like a problem with setting up the legacy scripting target. Worse, fixing it could be problematic. Hmm.
Tracked as bug #013086.
Tracked as bug #013086.
E-mail: [email protected]
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
spawnShip: is a very unused function. It uses no placements co-ordinates but instead of that it uses the internal spawn directory for placement as Cmdr McLane writes. This function has to be used for very exact placements of objects as it also contains a orientation field. It is used for example to place the racing rings around Lave.Commander McLane wrote:As far as spawnShip: is concerned: Remember that it requires the specification of the desired position in the spawn-directory the entity's shipdata. If this is missing, I guess the entity could easily end up in position (0,0,0).
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
@TGHC: No, it could only be used to give each Generation Ship its own, unique spawning-location. But the same can be achieved by other ways.
@Eric: I would love you to dig deeper into the orientation-key in the spawn-directory. I have no idea why it seems to work with the racing rings (probably it doesn't, but their correct orientation is due to something else?), because I never got it to work with any entity I tried with. No matter what orientation I give it, it is always spawned with its z-axis along the internal (absolute) z-axis. See the Hacker Outposts in Anarchies1.0.oxp as an example (which I am to upload soon).
EDIT: It seems I have run into a problem, that will further delay the release of Anarchies1.0.oxp. Ironically it is related to the very method discussed here.
@Eric: I would love you to dig deeper into the orientation-key in the spawn-directory. I have no idea why it seems to work with the racing rings (probably it doesn't, but their correct orientation is due to something else?), because I never got it to work with any entity I tried with. No matter what orientation I give it, it is always spawned with its z-axis along the internal (absolute) z-axis. See the Hacker Outposts in Anarchies1.0.oxp as an example (which I am to upload soon).
EDIT: It seems I have run into a problem, that will further delay the release of Anarchies1.0.oxp. Ironically it is related to the very method discussed here.
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
Re: legacy_spawn
No, I have just encountered a case where an object spawned in the old plist style with spawnShip: was created at (0,0,0).Svengali wrote:The same for legacy_spawnShip. The difference is that the spawned item is sometimes positioned (0,0,0).
The old legacy scripting methods in shipdata.plist are working as expected.
So both the old spawnShip: and the new legacy_spawnShip seem to be broken in the same way in 1.70.
Ok, after some more testing:
The position of the spawned thing is only sometimes (0,0,0) and sometimes the players position. Or maybe the ones position who has killed the ship. So it is necessary to correct the position after spawning.
Currently I'm using:But it is not always working. The problem is that if the player==killer and if he moves very slow the script will position the cargo to close to the player, so he will collide. And the other problem is that the sorting order is only based on the distance.
Any solutions?
The position of the spawned thing is only sometimes (0,0,0) and sometimes the players position. Or maybe the ones position who has killed the ship. So it is necessary to correct the position after spawning.
Currently I'm using:
Code: Select all
this.shipDied = function()
{
System.legacy_spawn('harkov_honeypod', 8);
let posto = this.ship.position.add(3,1,5.6);
let allpods = System.shipsWithRole('harkov_honeypod');
allpods.reverse();
for (let a = 8; a > 0; a--)
{
allpods[0].setPosition(posto.add(Math.random(),Math.random(),Math.random()));
allpods.shift();
}
}
Any solutions?
The solution to spawn is already on svn, as reported here. Hopefully, it won't be too long before the release of Oolite 1.71...
Edit: As far as js is concerned, you could check the distance to the player with & then move posto accordingly if it's less than the distance desired....
Edit 2: in case player is already dereferenced, you could store a reference to player inside the ship script :
then inside the this.shipDied function:
Edit: As far as js is concerned, you could check the distance to the player with
Code: Select all
player.position.distanceTo(posto)
Edit 2: in case player is already dereferenced, you could store a reference to player inside the ship script :
Code: Select all
this.beingAttacked = function(whom)
{
//find the player
if (whom.isPlayer) this.Player=whom;
//other stuff
}
Code: Select all
if(this.Player && this.Player.position.distanceTo(posto)<20){
//stuff
}
Sorry Kaks,
maybe the problem was not clear. Just as explanation. My problem was that the moved pods were possibly not the spawned pods, because it is possible that there were already some of them out there. But after a little bit more thinking about it I found the solution. It is not totally safe, but a good workaround for the legacy_spawn problem in V1.70.
sort() does the trick. Ahruman has told us that scooper is a concatenated string. And the other thing is to limit the number of loops, because it is possible that some pods were destroyed. I know that it is a timeintensive solution and maybe there is a better way. But it is a working solution. I have tested it with 3 Transports at the same time and the result was no reference error and they are doing their job.
Cheerio
maybe the problem was not clear. Just as explanation. My problem was that the moved pods were possibly not the spawned pods, because it is possible that there were already some of them out there. But after a little bit more thinking about it I found the solution. It is not totally safe, but a good workaround for the legacy_spawn problem in V1.70.
Code: Select all
/*
this.name = "harkov_transporter";
this.author = "Svengali";
this.copyright = "Feb2008";
this.description = "Localhero Part I - V1.03.5";
this.version = "1.00";
*/
this.shipDied = function() { this.localhero_transport(); }
this.localhero_transport = function()
{
system.legacy_spawn('harkov_honeypod', 8);
let posto = this.ship.position.add(3,1,5.6);
let allpods = system.shipsWithRole('harkov_honeypod');
allpods.sort().reverse();
for (let a = Math.min(8, allpods.length); a > 0; a--)
{
allpods[0].setPosition(posto.add(Math.random(),Math.random(),Math.random()));
allpods.shift();
}
}
Cheerio
Not quite sure what you mean, scooper is an object, and I don't remember Ahruman saying 'scooper is a concatenated string.'Ahruman has told us that scooper is a concatenated string.
Still, we weren't talking about scooper, and I'm glad you found a solution for the actual problem you had.
Cheers,
Kaks
Ok Kaks. You are right . He saidKaks wrote:Not quite sure what you mean, scooper is an object, and I don't remember Ahruman saying 'scooper is a concatenated string.'
That gave me the hint to search for string-handling-methods. And allpods is similiar to scooper. A array with more infos in it (Name, ID, Position,...).Ahruman wrote:The square brackets don’t indicate an array. The standard behaviour of toString() for general objects is to return “[Object something]”, where “something” is the class of the object. Oolite’s toString() implementations use a variant of that syntax.
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
This may not really be what you want, since the range of Math.random() is [0, 1). If you want a random offset, you’d be better off with something like:Svengali wrote:Code: Select all
allpods[0].setPosition(posto.add(Math.random(),Math.random(),Math.random()));
Code: Select all
this.randomDirection = function()
{
// Returns vectors distributed reasonably evenly over the unit sphere.
function myRandom() { return Math.random() * 2 - 1; }
let v;
do
{
v = new Vector(myRandom(), myRandom(), myRandom());
} while (v.magnitude() == 0); // Catch the unlikely event of v = (0, 0, 0)
return v.direction();
}
this.randomVector = function(scale)
{
// Returns vectors distributed reasonably evenly in a sphere of radius "scale".
if (scale === undefined) scale = 1;
return this.randomDirection(). multiply(scale * Math.random());
}
E-mail: [email protected]
Muchas gracias, Ahruman.
Another case will come to use your snippet. Thanks a lot.
That's all I wanted. There are 8 pods nearby to that position where the ship died. The explosion could possibly give the spawned cargo pods a momentum. That's what I wanted. The momentum isn't that high ( added(3,1,5.6) before) , so they will be more scattered. And the used AI will stop them. But maybe it would be better to define a variable for that case instead of calling Math.random() 3 times on every loop.Ahruman wrote:This may not really be what you want, since the range of Math.random() is [0, 1).
Another case will come to use your snippet. Thanks a lot.