VoidExpanse/Consumable scripting: Difference between revisions
(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...") |
m (Grammar, punctuation, phrasing edits.) |
||
Line 1: | Line 1: | ||
== Consumables Scripting == | == Consumables Scripting == | ||
In most cases | In most cases the standard xml-structures are more than enough to implement consumable effects. However, if we need | ||
to do something special, for example, restock ammo, self-destruct, teleport or kill all ships in front of | to do something special, for example, restock ammo, self-destruct, teleport or kill all ships in front of the player, you will need scripts. | ||
There are no hard rules | There are no hard rules for scripting consumables, here are just a couple of tips. | ||
For example, we need to create a consumable | For example, if we need to create a consumable that refills ammo in all of the players ballistic weapons. | ||
First of all, we need to create | First of all, we need to create a basic consumable xml, with an empty effects node. | ||
<pre> | <pre> | ||
<effects> | <effects> | ||
Line 13: | Line 13: | ||
</pre> | </pre> | ||
Then, you create a new global script in folder /scripts/globals/, in which you | Then, you create a new global script in folder /scripts/globals/, in which you hook some function to a special trigger: | ||
<pre> | <pre> | ||
function OnInit() | function OnInit() | ||
Line 21: | Line 21: | ||
} | } | ||
</pre> | </pre> | ||
After | After that, every time a player uses a consumable with the xml-id "consumable_ballistic_ammo", function "onBallisticAmmoConsumableUsed" will be called. | ||
Now, all that's left is to implement ammo refill: | Now, all that's left is to implement the actual ammo refill: | ||
<pre> | <pre> | ||
function onBallisticAmmoConsumableUsed( args ) | function onBallisticAmmoConsumableUsed( args ) | ||
Line 37: | Line 37: | ||
</pre> | </pre> | ||
That's all, now we have consumable | That's all, now we have a consumable that refills ammo the of all ballistic weapons! |
Revision as of 03:16, 25 July 2014
Consumables Scripting
In most cases the standard xml-structures are more than enough to implement consumable effects. However, if we need to do something special, for example, restock ammo, self-destruct, teleport or kill all ships in front of the player, you will need scripts.
There are no hard rules for scripting consumables, here are just a couple of tips. For example, if we need to create a consumable that refills ammo in all of the players ballistic weapons. First of all, we need to create a basic consumable xml, with an empty effects node.
<effects> <!-- no effects here --> </effects>
Then, you create a new global script in folder /scripts/globals/, in which you hook some function to a special trigger:
function OnInit() { actions.BindToTrigger("onConsumableUsed", "onBallisticAmmoConsumableUsed", {id: "consumable_ballistic_ammo"}); }
After that, every time a player uses a consumable with the xml-id "consumable_ballistic_ammo", function "onBallisticAmmoConsumableUsed" will be called.
Now, all that's left is to implement the actual 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 a consumable that refills ammo the of all ballistic weapons!