Jump to content
Sign in to follow this  
SgtBatten

How can i check if i player has one of an array of weapons?

Recommended Posts

Hi guys. first post and HAVE searched for days so go easy on me :) as the title says im trying to check if a player has one of an array of weapons defined in an sqs file.

i want the player to pick up one of the weapons in the crate and then the script will continue.

_mycrate = _this select 0

clearMagazineCargo _mycrate
clearWeaponCargo _mycrate


; Pistols

_mycrate addMagazineCargo ["17Rnd_9x19_glock17", 10]
_mycrate addWeaponCargo ["glock17_EP1", 1]
_mycrate addMagazineCargo ["15Rnd_9x19_M9", 10]
_mycrate addWeaponCargo ["M9", 1]

; Rifles

_mycrate addMagazineCargo ["30Rnd_556x45_G36", 10]
_mycrate addWeaponCargo ["G36C_camo, 1", 1]
_mycrate addMagazineCargo ["30Rnd_556x45_G36", 10]
_mycrate addWeaponCargo ["G36K_camo", 1]
_mycrate addMagazineCargo ["30Rnd_556x45_Stanag", 10]
_mycrate addWeaponCargo ["M4A3_CCO_EP1", 1]
_mycrate addMagazineCargo ["30Rnd_556x45_StanagSD", 10]
_mycrate addWeaponCargo ["M4A3_RCO_GL_EP1", 1]
_mycrate addMagazineCargo ["20rnd_762x51_B_SCAR", 10]
_mycrate addMagazineCargo ["100Rnd_556x45_BetaCMag", 10]
_mycrate addMagazineCargo ["20Rnd_556x45_Stanag", 10]
_mycrate addWeaponCargo ["SCAR_L_STD_EGLM_RCO", 1]
_mycrate addWeaponCargo ["SCAR_L_STD_HOLO", 1]
_mycrate addWeaponCargo ["SCAR_H_STD_EGLM_Spect", 1]

_mycrate addmagazinecargo ["1Rnd_HE_M203", 10]

; machine guns

_mycrate addMagazineCargo ["100Rnd_762x51_M240", 10]
_mycrate addWeaponCargo ["Mk_48_DES_EP1", 1]

; snipers


_mycrate addWeaponCargo ["SCAR_H_LNG_Sniper", 1]


; array of all available weapons

weaponsarray= ["G36C_camo","G36K_camo","M4A3_CCO_EP1","M4A3_RCO_GL_EP1","SCAR_L_STD_EGLM_RCO","SCAR_L_STD_HOLO","SCAR_H_STD_EGLM_Spect","Mk_48_DES_EP1","SCAR_H_LNG_Sniper", 1]

; Check if player has picked up one of the weapons

waitUntil {player hasweapon _x} count weaponsarray > 0;

tsk4 settaskstate "SUCCEEDED";

hint "New Task Added";

tsk5 = player createSimpleTask ["Regroup"]
tsk5 setSimpleTaskDescription ["So you've finally got yourself kitted out. Well done! head back to the team and await further orders.", "Regroup", "Regroup"]
tsk5 setSimpleTaskDestination "campfire"
player setCurrentTask tsk5

as you can see i am currently trying to use something like this

waitUntil {player hasweapon _x} count weaponsarray > 0;

but no joy as yet.

the sqs is executed in the init line of the crate and the weapons are added so it works up til the weapon check part.

thanks for any help

Batten

Share this post


Link to post
Share on other sites
waitUntil {player hasweapon _x} count weaponsarray > 0;
i dont think that will work well. you mix sqs and sqf in your script

there are several other ways to do this also

waitUntil {{player hasweapon _x} foreach weaponsarray};

or

waitUntil {primaryWeapon player in weaponsarray};

or something like

_hasweapon = false;
while {!_hasweapon} do
{
   _wep = primaryWeapon player 
   if (_wep in weaponsarray) then {_hasweapon = true;};
   sleep 1;
};

ps: please start using sqf instead of sqs, sqs is old and not as good as sqf

Edited by nuxil

Share this post


Link to post
Share on other sites

Does waitUntil even work in SQS? I'm not sure, haven't touched that stuff since OFP. :( I think it was the @ symbol back then.

Either way, the waitUntil condition needs to be surrounded by code brackets:

waitUntil {{player hasweapon _x} count weaponsarray > 0};

Share this post


Link to post
Share on other sites

thanks guys i will try that this afternoon.

i originally had the scipt as sqf but it would not execute even the weapons in crate part.

is there a sqf syntax guide for beginners?

im very new to scripting and sometimes in threads it is hard to tell if the person is using sqf or sqs.

---------- Post added at 06:56 ---------- Previous post was at 05:00 ----------

thankyou nuxil for some very sound advice.

i am now in the process of converting my mix of sqs and sqf files all to sqf.

i changed my code to this and it works perfectly so thankyou

_mycrate = _this select 0;

clearMagazineCargo _mycrate;
clearWeaponCargo _mycrate;


// Pistols

_mycrate addMagazineCargo ["17Rnd_9x19_glock17", 10];
_mycrate addWeaponCargo ["glock17_EP1", 1];
_mycrate addMagazineCargo ["15Rnd_9x19_M9", 10];
_mycrate addWeaponCargo ["M9", 1];

// Rifles

_mycrate addMagazineCargo ["30Rnd_556x45_G36", 10];
_mycrate addWeaponCargo ["G36C_camo, 1", 1];
_mycrate addMagazineCargo ["30Rnd_556x45_G36", 10];
_mycrate addWeaponCargo ["G36K_camo", 1];
_mycrate addMagazineCargo ["30Rnd_556x45_Stanag", 10];
_mycrate addWeaponCargo ["M4A3_CCO_EP1", 1];
_mycrate addMagazineCargo ["30Rnd_556x45_StanagSD", 10];
_mycrate addWeaponCargo ["M4A3_RCO_GL_EP1", 10];
_mycrate addMagazineCargo ["20rnd_762x51_B_SCAR", 10];
_mycrate addMagazineCargo ["100Rnd_556x45_BetaCMag", 10];
_mycrate addMagazineCargo ["20Rnd_556x45_Stanag", 10];
_mycrate addWeaponCargo ["SCAR_L_STD_EGLM_RCO", 1];
_mycrate addWeaponCargo ["SCAR_L_STD_HOLO", 1];
_mycrate addWeaponCargo ["SCAR_H_STD_EGLM_Spect", 1];

_mycrate addmagazinecargo ["1Rnd_HE_M203", 10];

// machine guns

_mycrate addMagazineCargo ["100Rnd_762x51_M240", 10];
_mycrate addWeaponCargo ["Mk_48_DES_EP1", 1];

// snipers


_mycrate addWeaponCargo ["SCAR_H_LNG_Sniper", 1];


// template



// array of all available weapons

weaponsarray= ["G36C_camo","G36K_camo","M4A3_CCO_EP1","M4A3_RCO_GL_EP1","SCAR_L_STD_EGLM_RCO","SCAR_L_STD_HOLO","SCAR_H_STD_EGLM_Spect","Mk_48_DES_EP1","SCAR_H_LNG_Sniper", 1];

// Check if player has picked up one of the weapons

waitUntil {primaryWeapon player in weaponsarray};



sleep 4

tsk4 settaskstate "SUCCEEDED";

hint "Tasks Updated";

tsk5 = player createSimpleTask ["Regroup"];
tsk5 setSimpleTaskDescription ["So you've finally got yourself kitted out. Well done! Head back to the team and await further orders.", "Regroup", "Regroup"];
tsk5 setSimpleTaskDestination "campfire";
player setCurrentTask tsk5;

Share this post


Link to post
Share on other sites
is there a sqf syntax guide for beginners?

Commands are basically the same, just the way it's written is different. It's also a lot more efficient in terms of performance.

More info here, here and here.

Share this post


Link to post
Share on other sites
Commands are basically the same, just the way it's written is different. It's also a lot more efficient in terms of performance.

More info here, here and here.

thanks mate, very helpful

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  

×