Jump to content
Sign in to follow this  
Trixta

Query Units Magazines

Recommended Posts

Any way of checking if a unit has at least one magazine of a certain type?

Obviously hasweapon only checks the weaponslots for weapons. I'm looking to check if the unit has picked up a particular magazine (pipebomb). I'm playing about with reading the unit's magazine array slot by slot to see if pipebomb comes up but am not having much joy.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_mags=magazines uspc;

_magcount=0;

#getbomb

?(_mags select _magcount="pipebomb"):goto "havebomb";

_magcount=_magcount+1;

goto "getbomb"

#havebomb

titletext ["Okay, I'm tooled up. Let's get outta here.","plain down"];

ammodumpdone=true;

exit

All I need to know is if unit's magazines include a pipebomb.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

{

scopename magcheck;

if (_x == "Pipebomb") then {

titletext ["Okay, I'm tooled up. Let's get outta here.","PLAIN DOWN"];

ammodumpdone = true;

breakout magcheck;

};

} foreach magazines uspc;

EDIT: If you insist on doing it with SQS, you have an error in your script:

?(_mags select _magcount="pipebomb"):goto "havebomb";

Needs to be

?(_mags select _magcount == "pipebomb"):goto "havebomb";

Share this post


Link to post
Share on other sites

Thanks Shuko - that's the very thing. thumbs-up.gif

Just for the sake of tidying up and closing the post I've pasted in the full script which I run from [] exec "havebomb.sqs" in uspc's init line.

havebomb.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#getbomb

{scopename magcheck;if (_x == "Pipebomb") then {ammodumpdone = true;breakout magcheck;};} foreach magazines uspc;

?(ammodumpdone):goto "havebomb";

goto "getbomb"

#havebomb

titletext ["Okay, I'm tooled up. Let's get outta here.","PLAIN DOWN"];

exit

Share this post


Link to post
Share on other sites

Ermh... does that actually work? You have mixed SQS and SQF, and created useless lines.

You could have just pasted my example into a file (havebomb.sqf for example) and called it with:

nul=[] execVM "havebomb.sqf";

Share this post


Link to post
Share on other sites

Why do you need a script?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_X == "Pipebomb"} count (magazines unit) > 0

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  

×