VoidExpanse/Consumable scripting

From AtomicTorchWiki
Revision as of 10:27, 7 March 2014 by Damonwall (talk | contribs) (Created page with "== Consumables Scripting == In most cases, standard xml-structures are more then enough to implement consumable effect. However, if we need to do something special, for examp...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Consumables Scripting

In most cases, standard xml-structures are more then enough to implement consumable effect. However, if we need to do something special, for example, restock ammo, self-destruct, teleport or kill all ships in front of ship, you'll need scripts.

There are no hard rules about consumables scripting. Here are just a couple of tips. For example, we need to create a consumable, that refills ammo in all ballistic weapons. First of all, we need to create an empty consumable xml. Under "empty" I mean with no effects.

	<effects>
		<!-- no effects here -->
	</effects>

Then, you create a new global script in folder /scripts/globals/, in which you hooks some function to a special trigger:

function OnInit()
{
	actions.BindToTrigger("onConsumableUsed", "onBallisticAmmoConsumableUsed",
		{id: "consumable_ballistic_ammo"});
}

After then, every time you use consumable with xml-id "consumable_ballistic_ammo", function "onBallisticAmmoConsumableUsed" will be called.

Now, all that's left is to implement ammo refill:

function onBallisticAmmoConsumableUsed( args )
{
	var ballisticWeapons = ship.GetWeaponsOfType( args.ship_id, 2 );
	if(ballisticWeapons == null) return;
	
	for(var i =0; i < ballisticWeapons.length; i++)
	{
		ship.RefillAmmoForWeapon( args.ship_id, ballisticWeapons[i] );
	}
}

That's all, now we have consumable, that refills ammo of ballistic weapons!