PDA

View Full Version : addAction question.



Schilly
Jul 23 2009, 15:38
I am in the process of making a plane loadout script for an A10.

The script has a few variables that it needs, ie: the planes name, and what type of loadout.


Normally if you get it by a trigger or in an init line it would look like this:



nul=[name,"CAS"] execVM "A10Loadout.sqf";



What I am trying to do, is use this in an addAction but have not yet come to a conclusion as to how to pass the variables along with it. I tried doing that above, didnt work, also tried without the "nul=" part, also didnt work.



Anyone have any suggestions?

whisper
Jul 23 2009, 16:05
see "parameters" part here : http://community.bistudio.com/wiki/addAction

_actionID = myUnit addAction ["my action text", "A10Loadout.sqf", [name, "CAS"]]
You have an optional third parameter to addAction to set the parameters passed to the script named in the second parameter of addAction

You even have more nifty optional parameters possible

Big Dawg KS
Jul 23 2009, 16:07
Look up the alternative snytax for addaction... should be something like this:


object addAction ["Action Name","A10Loadout.sqf",[name,"CAS"],1,true,true,"","true"]

You will have to modify your script though because it will pass these parameters as _this select 3:

name: (_this select 3) select 0;
"CAS": (_this select 3) select 1;

Schilly
Jul 23 2009, 16:10
Tried that as well... Also did not work.

---------- Post added at 04:10 PM ---------- Previous post was at 04:09 PM ----------

Unfortunately neither of the suggestions above worked :|

Big Dawg KS
Jul 23 2009, 16:13
Post the code for A10Loadout.sqf please.

Schilly
Jul 23 2009, 16:15
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: Robert Larson, larson@<hidden>
// Edited by: Patrick Schillemat, schillemat@<hidden>
//
// Usage: nul=["plane","type"] execVM "A10Loadout.sqf";
// Variable "plane" is the name of the A10
// Variable "type" is the type of loadout.
//
// Available Loadouts:
// - CAS (4 LGB, 6 Mk 82)
// - LGB (8 LGB)
// - ATG (8 Mavericks)
// - Standard (2 Sidewinder, 2 Maverick, 4 LGB)
//
// All loadouts include: 1350 Rounds of 30mm AP, and 38 FFARs
//////////////////////////////////////////////////////////////////

_plane = _this select 0;
_type = _this select 1;


switch(_type) do
{
case "CAS":
{
// Weapon and Magazine Arrays

_weapons = ["GAU8", "Mk82BombLauncher_6", "BombLauncherA10", "FFARLauncher"];
_magazines = ["1350Rnd_30mmAP_A10", "6Rnd_Mk82", "4Rnd_GBU12", "38Rnd_FFAR"];

_plane setVehicleAmmo 0;
{_plane removeWeapon _x} foreach (weapons _plane);
sleep 0.5;
{
_plane addmagazine _x;
sleep 0.1;
} foreach _magazines;
{
_plane addWeapon _x;
sleep 0.1;
} foreach _weapons;
};
case "LGB":
{
_weapons = ["GAU8", "BombLauncherA10", "BombLauncherA10", "FFARLauncher"];
_magazines = ["1350Rnd_30mmAP_A10", "4Rnd_GBU12", "4Rnd_GBU12", "38Rnd_FFAR"];

_plane setVehicleAmmo 0;
{_plane removeWeapon _x} foreach (weapons _plane);
sleep 0.5;
{
_plane addmagazine _x;
sleep 0.1;
} foreach _magazines;
{
_plane addWeapon _x;
sleep 0.1;
} foreach _weapons;
};
case "ATG":
{
_weapons = ["GAU8", "MaverickLauncher", "FFARLauncher"];
_magazines = ["1350Rnd_30mmAP_A10", "2Rnd_Maverick_A10", "2Rnd_Maverick_A10", "2Rnd_Maverick_A10", "2Rnd_Maverick_A10", "38Rnd_FFAR"];

_plane setVehicleAmmo 0;
{_plane removeWeapon _x} foreach (weapons _plane);
sleep 0.5;
{
_plane addmagazine _x;
sleep 0.1;
} foreach _magazines;
{
_plane addWeapon _x;
sleep 0.1;
} foreach _weapons;
};
case "STD":
{
_weapons = ["GAU8", "MaverickLauncher", "SidewinderLaucher_AH1Z", "BombLauncherA10", "FFARLauncher"];
_magazines = ["1350Rnd_30mmAP_A10", "2Rnd_Maverick_A10", "2Rnd_Sidewinder_AH1Z", "4Rnd_GBU12", "38Rnd_FFAR"];

_plane setVehicleAmmo 0;
{_plane removeWeapon _x} foreach (weapons _plane);
sleep 0.5;
{
_plane addmagazine _x;
sleep 0.1;
} foreach _magazines;
{
_plane addWeapon _x;
sleep 0.1;
} foreach _weapons;
};
};



---------- Post added at 04:15 PM ---------- Previous post was at 04:14 PM ----------

On a side note, this script works perfectly with a trigger or in the init line... Just not from addAction

Big Dawg KS
Jul 23 2009, 16:17
You have 2 options.

1. Modify A10Loadout.sqf:


_plane = (_this select 3) select 0;
_type = (_this select 3) select 1;

And use this for adding the action:

object addAction ["Action Name", "A10Loadout.sqf", [name, "CAS"]]

2. Create a helper script (call it A10LoadoutAct.sqf):


_plane = (_this select 3) select 0;
_type = (_this select 3) select 1;

[_plane,_type] execVM "A10Loadout.sqf"

And use this for adding the action:

object addAction ["Action Name", "A10LoadoutAct.sqf", [name, "CAS"]]

Schilly
Jul 23 2009, 17:41
Ahh i missed the "modify" the script part of your post. Let me try that and see if it works.

---------- Post added at 04:26 PM ---------- Previous post was at 04:18 PM ----------

Perfect. Thanks mate.

---------- Post added at 05:41 PM ---------- Previous post was at 04:26 PM ----------

One question I have is I am wanting to put these addAction on an A10.... Only thing is as I want it to only function if the plane is on the ground and turned off...

Any ideas on that one?

Big Dawg KS
Jul 23 2009, 17:48
Use the full addAction syntax, you can give the action a condition:


object addAction ["Action Name","A10Loadout.sqf",[name,"CAS"],1,true,true,"","<CODE>"]

And where I wrote <CODE> you can put any code thate evaluates to a boolean, with reserved variables _this (person who uses the action) and _target (object the action is added to). Ex:


speed _target <= 3 && !isEngineOn _target

Substitute this in for <CODE> and the action will only appear when the A10 is not moving and the engine off.

Schilly
Jul 23 2009, 20:33
Awesome...


Works perfectly! Thanks mate.