Page 1 of 3

Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 6:40 pm
by Smivs
I'm baffled :?:
For an OXP idea I'm working on, I have an asteroid as a sub-entity of a ship - the idea is it's a space wreck and the asteroid has hit the ship at low speed and the ship is now 'crunched' onto the asteroid. So far so good. However I want to be able to salvage stuff from the ship by destroying it. Again so far so good. The problem is that sometimes the asteroid breaks into boulders during this and sometimes it doesn't. I would like to guarantee that the asteroid breaks into about 4-5 boulders every time.
The weird thing is, I tried increasing the 'likely cargo' to 100 to generate boulders on the destruction of the asteroid, and this works very well....except the 100 boulders appear about 10 000Km from the original asteroid. :shock:
Any thoughts/ideas?

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 8:15 pm
by Thargoid
Have the asteroid entity not have boulders at all in the game-sense (it's one of the shipdata keys iirc), but on shipDied just have it spawn the boulders by script instead.

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 8:31 pm
by Commander McLane
That would be the no_boulders key, which should be set to yes.

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 8:59 pm
by Thargoid
Dat's der pebble...

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 9:04 pm
by Smivs
Thanks chaps.
@Thargoid, I tried that but they seem to appear some distance from where the asteroid was, as opposed to the 'normal' formation of boulders that replace the asteroid in exactly the same position.
@McLane, if I set "no_boulders" = yes; won't that give me no boulders? I want the boulders. I'll try "no_boulders" = no; and see what happens.

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 9:15 pm
by Okti
Hi Smivs,

Try spawn function for the ship.shipDied event handler. That might help.

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 9:23 pm
by Commander McLane
Smivs wrote:
Thanks chaps.
@Thargoid, I tried that but they seem to appear some distance from where the asteroid was, as opposed to the 'normal' formation of boulders that replace the asteroid in exactly the same position.
@McLane, if I set "no_boulders" = yes; won't that give me no boulders? I want the boulders. I'll try "no_boulders" = no; and see what happens.
'Yes' is the default, and does not guarantee boulders. Only 'no' guarantees that there will be none.

Setting it to 'no' only enables you to spawn them in another way, without worrying that the populator would interfere.

About the distance (10000 m, not km): please post the code snippet, then we can see if there is some error, or slip of logic, in it.

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 9:41 pm
by Smivs
It's mostly a C&P from the core shipdata.plist.

Code: Select all

"wreck_asteroid" =
	{
		ai_type = "dumbAI.plist";
		bounty = 10;
		cargo_type = "CARGO_NOT_CARGO";
		energy_recharge_rate = 0;
		density = 5;
		forward_weapon_type = "WEAPON_NONE";
		has_ecm = no;
		has_escape_pod = no;
		has_scoop = no;
		max_energy = 600;
		max_flight_pitch = 0.1;
		max_flight_roll = 0.1;
		max_flight_speed = 0;
		missiles = 0;
		model = "wreck_asteroid.dat";
		name = "Asteroid";
		roles = "asteroid";
		scan_class = "CLASS_ROCK";
		smooth = yes;
		thrust = 0;
		unpiloted = yes;
		weapon_energy = 0;
		materials =
		{
			"rock_SS.png" =
			{
			shininess = 2;
			specular_color = (0.1, 0.1, 0.1, 1.0);
			};
		};
		likely_cargo = 100;
		debris_role = "boulder";
		heat_insulation = 5;
	};
I've just given it a custom .dat and texture, and increased the energy to 600 to try and make it more durable. Ideally I'd like between 5 and 10 boulders when it 'goes'. I'm hitting it with military lasers which is probably not helping.
Oddly I cannot now reproduce the hundred boulders thing. It just explodes and leaves nothing anywhere.

On a related note, can sub-entities spawn items as a death action?

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 11:18 pm
by Commander McLane
Thargoid wrote:
Have the asteroid entity not have boulders at all in the game-sense (it's one of the shipdata keys iirc), but on shipDied just have it spawn the boulders by script instead.
Smivs wrote:
@Thargoid, I tried that.
Can you post the script where you tried to create the boulders inside the this.shipDied event handler? The shipdata are not really helpful for that (except for seeing that it's already missing the script key which is needed to activate the script in the first place.

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 11:44 pm
by Smivs
I removed the script key when it didn't work.
The script key in the shipdata.plist was

Code: Select all

script = "spacewreck_boulders.js";
and the script (called "spacewreck_boulders.js") was

Code: Select all

this.shipDied = function ()
{
	this.ship.spawn("boulder");
};
I thought I'd start with one boulder, to keep it simple and I don't know how to script more than one anyway. That would have been my next question :roll:
The asteroid is a sub-entity, and I haven't been able to spawn anything as a death action from a sub-ent. Is this relevant?

Re: Boulders from asteroids question(s)

Posted: Sun Mar 06, 2011 11:55 pm
by Commander McLane
Smivs wrote:
I thought I'd start with one boulder, to keep it simple and I don't know how to script more than one anyway. That would have been my next question :roll:
It's all in the manual. What you want is this.ship.spawn("boulder", <number>);.
Smivs wrote:
The asteroid is a sub-entity, and I haven't been able to spawn anything as a death action from a sub-ent. Is this relevant?
Perhaps it is. I'm not sure whether a subentity can spawn something. Perhaps it can't. Alternatively you could make the main entity spawn the boulders. this.ship.owner.spawn("boulder", <number>);

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 12:01 am
by Smivs
I did try this the other way round, with the ship being a sub-ent of the asteroid, and found it couldn't spawn anything, so it seems that sub-ents can't spawn stuff.
I'll certainly try "this.ship.owner.spawn("boulder", <number>);" , although it might have to wait till the morning now.
I assume that goes in the sub-ents part of shipdata, yes?.

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 12:33 am
by Commander McLane
Smivs wrote:
I did try this the other way round, with the ship being a sub-ent of the asteroid, and found it couldn't spawn anything, so it seems that sub-ents can't spawn stuff.
I'll certainly try "this.ship.owner.spawn("boulder", <number>);" , although it might have to wait till the morning now.
I assume that goes in the sub-ents part of shipdata, yes?.
It has nothing to do with the sub-ents part of the shipdata, not even with shipdata at all. It's a JS-script, only a tiny variation of your JS-script. You are only supposed to add 'owner.' and a comma plus a number (less than 64).

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 5:45 am
by Thargoid
Try replacing

Code: Select all

this.ship.spawn("boulder");
with

Code: Select all

system.addShips("boulder", 10, this.ship.position, 500);
That will add 10 boulders within 500m of the ships current position (or in this case the position it held when it died).

For exact details of what's done there, see the wiki.[/color]

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 8:02 am
by Smivs
Thanks, both. I now have boulders, and am a happy fellow :D

You know I spent most of yesterday looking at various Wiki pages, and you still managed to find things I hadn't found. :oops:
Am I the only person who finds the js sections almost impossible to navigate? Is there an index page or something I've missed?