Jump to content
Sign in to follow this  
eggbeast

weapons array - help request!

Recommended Posts

Hiya

I'm trying to modify my Evolution mission which already enables classes of player to build static weapons based on the weapon they are carrying (e.g. grenadier makes Mk19 if he is carrying an M203, AT guy makes TOW if he has an RPG, AA guy makes zu23 ifhe has a stinger etc)

as i've recently added a lot of new custom weapons, and becuase others may mod these missions, i wouldprefer to make an array of weapons of a certain type in the init file which the players weapon is checked against when he tries to spawn his new static weapon.

e.g.

in init

BIS_EVO_AAirweapons = ["Stinger","Strela","Igla"]; // All weapons that count for AA class static bonus

BIS_EVO_ATweapons = ["Javelin","MetisLauncher","RPG18","SMAW","M136","RPG7V","FFAA_Armas_C90","FFAA_Armas_C100","ukf_law80launcher"]; // All weapons that count for AT class static bonus

BIS_EVO_MGweapons = ["M240","M249","PK","RPK_74","Pecheneg","MK_48","m8_SAW","MG36"]; // All weapons that count for MG class static bonus

BIS_EVO_GLweapons = ["M16A2GL","M16A4_GL","M16A4_ACG_GL","M4A1_HWS_GL","M4A1_RCO_GL","M4A1_HWS_GL_camo","M4A1_HWS_GL_SD_Camo","m8_carbineGL","AK_74_GL","AK_107_GL_pso","AK_107_GL_kobra"]; // All weapons that count for GL class static bonus

These are stock items at present for testing - later will add a huge list of vilas, FFAA and RH weapons etc

spawn.sqf adds an action to each type of player as they respawn as follows:

if ((player isKindOf "USMC_Soldier_GL" or player isKindOf "FR_Assault_GL" or player isKindOf "FR_GL" or player isKindOf "UK_SFD1" or player isKindOf "UK_SFMSKT1") and (perkparam == 1)) then {_actionId8 = player addAction ["Build MK19 Nest", "actions\static\makestatic.sqf",[_this,2],1, false, true,"test2"]};

if ((player isKindOf "USMC_Soldier_AA" or player isKindOf "UK_SFD3" or player isKindof "UK_SFT5") and (perkparam == 1)) then {_actionId8 = player addAction ["Build AntiAir Nest", "actions\static\makestatic.sqf",[_this,3],1, false, true,"test2"]};

if ((player isKindOf "USMC_Soldier_HAT" or player isKindOf "UK_SFMSKD3" or player isKindof "UK_SFT3") and (perkparam == 1)) then {_actionId8 = player addAction ["Build Antitank Nest", "actions\static\makestatic.sqf",[_this,4],1, false, true,"test2"]};

if ((player isKindOf "USMC_Soldier_MG" or player isKindOf "FR_AR" or player isKindOf "USMC_Soldier_AR" or player isKindOf "UK_SFMSKD2" or player isKindOf "UK_SFT2") and (perkparam == 1)) then {_actionId8 = player addAction ["Build MG Nest", "actions\static\makestatic.sqf",[_this,5],1, false, true,"test2"]};

then makestatic.sqf script is actioned by the player as follows:

_statparam = _params select 1;
switch (_statparam) do
//returns _stattype and _mkr_name
{
//removed some code for brevity
 case 2: //Grenade Launcher Nest 
{
	if (not (primaryWeapon player in List BIS_EVO_GLweapons)) exitWith {hint "You cannot build a Grenade Launcher Nest without an underslung grenade launcher"};
	_stattype = "MK19_TriPod";
	_mkr_name = format ["MK19_Nest %1", name player];
	_custom = 1;
	_dist = 3;
};
 case 3: //AA Nest
{
	if (not (secondaryWeapon player in List BIS_EVO_AAirweapons)) exitWith {hint "You cannot build an AA Nest without a Shoulder Launched Surface-to-Air Missile"};
	_allstat = ["KORD","Stinger_Pod","Igla_AA_pod_East","ZU23_CDF"];
	_maxb = (count _allstat)-1;
	_stattype = _allstat select (round random _maxb);
	_mkr_name = format ["AA Nest %1", name player];
	_custom = 1;
	_dist = 4;
};
 case 4: //AT Nest
{
	if (not (secondaryWeapon player in List BIS_EVO_ATweapons)) exitWith {hint "You cannot build an Antitank Nest without an Anti-Tank Rocket Launcher"};
	_allstat = ["TOW_TriPod","M119","SPG9_CDF","Metis"];
	_maxb = (count _allstat)-1;
	_stattype = _allstat select (round random _maxb);
	_mkr_name = format ["Antitank Nest %1", name player];
	_custom = 1;
	_dist = 6;
};
 case 5: //MG Nest
{
	if (not (primaryWeapon player in List BIS_EVO_MGweapons)) exitWith {hint "You cannot build an MG Nest without a Heavy Machine Gun"};
	_allstat = ["KORD","DSHkM_Mini_TriPod_CDF","Fort_Nest_M240","M2HD_mini_TriPod","M2StaticMG"];
	_maxb = (count _allstat)-1;
	_stattype = _allstat select (round random _maxb);
	_mkr_name = format ["MG Nest %1", name player];
	_custom = 1;
	_dist = 4;
};
etc

so when I run this (which otherwise works perfectly if i list the weapons directly in makestatic, rather than referring to the array) I get an error

Error:List Type Array Expected Object

so how do I check if object

primaryWeapon player

is in the array

BIS_EVO_MGweapons

?

cheers for help...

Share this post


Link to post
Share on other sites

thanks man - that worked a peach.

ok next one.

I'm also tryingto make an array of player types to check if the player is one of them etc for adding the functions, e.g.

spawn.sqf checks if you are a pilot then adds the action

if ((player isKindOf "USMC_Soldier_Pilot") and (perkparam == 1)) then {_actionId8 = player addAction ["Build Refuel Depot", "actions\static\makestatic.sqf",[_this,7],1, false, true,"test2"]};

I'd like to make an array of all possible types of pilot to avoid having to dig this stuff out of various scripts each time i mod the mission with new types of unit etc.

so if i put this in the init

//pilot classes
BIS_EVO_playerPilot = ["USMC_Soldier_Pilot","RU_Soldier_Pilot","Ins_Soldier_Pilot","AFR_Soldier_Pilot","MOL_Soldier_Pilot"];

would I then amend the spawn script to say

_playertype = typeOf vehicle player;
if ((_playertype in BIS_EVO_playerPilot) and (perkparam == 1)) then {_actionId8 = player addAction ["Build Refuel Depot", "actions\static\makestatic.sqf",[_this,7],1, false, true,"test2"]};

is this syntax ok? I'll test it now, but hoping it will work - any thoughts?

Edited by eggbeast

Share this post


Link to post
Share on other sites

Yes, mostly it is correct with just one quirk: _actionId8 won't be accessible outside of the if condition if you ever need it. Local variables only exist for the scope they are first declared in (in this case the if-then block) and its children. You can use the command "private" to declare local variables without assigning them a value.

How many values can perkparam have? If only 2 (true and false) you should use a boolean instead of a number so it takes up less memory. Although the difference is negligent with such small implementation it is still a good practice.

You should also think about tagging your global variables properly. BIS is used by, eh, BIS so you might want to come up with something unique (ref. OFPEC tags) to avoid conflicts ;)

To demonstrate the above:

EGG_perkparam = true; //Using bool and a proper tag
// ...
// Some code
// ...

private "_actionId8"; //Declare _actionId8 for this scope
_playertype = typeOf (vehicle player);
if ((_playertype in EGG_EVO_playerPilot) && EGG_perkparam) then
{
    _actionId8 = player addAction ["Build Refuel Depot", "actions\static\makestatic.sqf",[_this,7],1, false, true,"test2"];
};

Share this post


Link to post
Share on other sites

huge thanks - great advice! and dead fast too!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×