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

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

Post Reply
User avatar
cbr
---- E L I T E ----
---- E L I T E ----
Posts: 1377
Joined: Thu Aug 27, 2015 4:24 pm

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

Post 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?
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

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

Post 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();
		}
	}
User avatar
cbr
---- E L I T E ----
---- E L I T E ----
Posts: 1377
Joined: Thu Aug 27, 2015 4:24 pm

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

Post 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.
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

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

Post by Norby »

Yes. If your subentities are not the same then check the dataKey first.
Post Reply