VoidExpanse/Consumable scripting: Difference between revisions

From AtomicTorchWiki
(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...")
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Draft}}
== Consumables Scripting ==
== Consumables Scripting ==


In most cases, standard xml-structures are more then enough to implement consumable effect. However, if we need
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 ship, you'll need scripts.
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 about consumables scripting. Here are just a couple of tips.
There are no hard rules for scripting consumables, here are just a couple of tips.
For example, we need to create a consumable, that refills ammo in all ballistic weapons.
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 an empty consumable xml. Under "empty" I mean with no effects.
First of all, we need to create a basic consumable xml, with an empty effects node.
<pre>
<pre>
<effects>
<effects>
Line 13: Line 15:
</pre>
</pre>


Then, you create a new global script in folder /scripts/globals/, in which you hooks some function to a special trigger:
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 23:
}
}
</pre>
</pre>
After then, every time you use consumable with xml-id "consumable_ballistic_ammo", function "onBallisticAmmoConsumableUsed" will be called.
(Please note: OnInit() method is executed only for Global and Internal scripts)


Now, all that's left is to implement ammo refill:
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:
<pre>
<pre>
function onBallisticAmmoConsumableUsed( args )
function onBallisticAmmoConsumableUsed( args )
Line 37: Line 41:
</pre>
</pre>


That's all, now we have consumable, that refills ammo of ballistic weapons!
That's all, now we have a consumable that refills ammo the of all ballistic weapons!
 
{{Modding}}

Latest revision as of 08:08, 20 April 2015


This article is a draft and may contain incomplete or even incorrect information. You can help by expanding it.

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"});
}

(Please note: OnInit() method is executed only for Global and Internal scripts)

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!


VoidExpanse Modding (Edit template)

Using mods: Installing and using mods

Overview articles: Modding (main article), Package files structure

Topic specific articles: Assets modding, Content Modding, Scripting overview, Scripting API, Scripting Events system, Localization

Detailed scripting articles: Internal scripts, Global scripts, object scripts, Device scripts, Consumable scripting

Tools: VE Physics Adjuster, VE Mod Uploader (Steam), AT Localization Utility