Page 1 of 1

[?] Can the number of entities a ship be randomized

Posted: Fri Apr 07, 2017 10:54 pm
by cbr
1] Can the number of entities a ship be randomized?
(For example the number containers a cargoship carries on his hull)

2] Does the shipdata list have any conditional options to do such a thing?

Re: [?] Can the number of entities a ship be randomized

Posted: Sat Apr 08, 2017 12:12 am
by Norby
HammerHead contain a solution. The shipdata contain twelve cargo subentities and a line:

Code: Select all

script = "aquatics_hammerHead.js";
The relevant lines in this ship script:

Code: Select all

this.shipSpawned = function()
	{
	this.randomiseCargo();
	}

this.randomiseCargo = function()
	{
	if(Math.random() < (Math.random() / 3) 
		&& this.ship.subEntities && this.ship.subEntities.length > 2)
		{
		this.ship.subEntities[0].remove();
		this.randomiseCargo();
		}
	}

Re: [?] Can the number of entities a ship be randomized

Posted: Sat Apr 08, 2017 12:51 pm
by cbr
Thanks, if I read this correctly,

1) define all subentities in the shipdata.
2) when spawning the ship remove a random number of subentities ( which in this case are all the same ) via an external .js script.

Re: [?] Can the number of entities a ship be randomized

Posted: Sat Apr 08, 2017 2:24 pm
by Norby
Yes. If your subentities are not the same then check the dataKey first.