Jump to content
Sign in to follow this  
SilverRanger

magazines array

Recommended Posts

I'm having some trouble understanding why the magazines command returns an array that doesn't seem to function properly. I'm writing a small script that needs to count the number of a specific magazine, but the magazines array, while formated properly, doesn't seem to work

I did a quick search in the forums but couldn't find any relevant posts so I wrote this script to test it

_magazines = magazines player
hint format ["%1",_magazines]
_handgrenades = "handgrenade" count _magazines
_string = format ["%1",_handgrenades]
cuttext [_string,"plain down",1]
~1
? "handgrenade" in _magazines : hint "player has handgrenades"

the hint box correctly shows all magz the player holds, but the _string returns a 0 even though the player has handgrenades on him. in _magazines doesn't seem to work either

am I doing something wrong? is there a workaround to this problem?

Share this post


Link to post
Share on other sites

Well, if you just wanna count and display the number of handgrenades, just try :

_handgrenades = "handgrenade" count magazines player
~1
if (_hangrenades != 0) then {call format [{titletext ["player has %1 handgrenades","PLAIN"]}, _hangrenades]}
exit

If you prefer a hint, then :

_handgrenades = "handgrenade" count magazines player
~1
if (_hangrenades != 0) then {hint format ["player has %1 handgrenades", _hangrenades]}
exit

Share this post


Link to post
Share on other sites

my problem is not how to display the result, but the result itself

"handgrenade" count magazines player returns 0

Share this post


Link to post
Share on other sites

you my friend are a god damn genius! :notworthy: it worked! :D

however, I now have a more disturbing problem... when I throw all my handgrenades, the script still returns 1! oddly enough, it returns 0 if I just drop them :(

_magazines = magazines player
hint format ["%1",_magazines]
_handgrenades = {_x == "handgrenade"} count _magazines 
_string = format ["%1",_handgrenades]
cuttext [_string,"plain down",1]

any thoughts?

Share this post


Link to post
Share on other sites

That's how magazines command work. Last mag stays in the array.

You can combine it with player ammo "throw" but that will only work with CWC weapons.

Share this post


Link to post
Share on other sites

I have already considered the ammo command, but it's not reliable for my purpose

the "throw" weapon uses both handgrenades and smokeshells as mags so if you have 0 handgrenades and 1 smokeshell, the script will return 1 and 1, while "throw" ammo player will return 1.

I need a way to tell if the given unit is carrying more handgrenades or more smokeshells. I already wrote a simple config to add two separate throw weapons (1 for grenades and 1 for smokeshells), but I now need to add more grenade types and I really don't want to be adding more throw weapons for each new type...

Share this post


Link to post
Share on other sites

I have one ammo command

#magazines
_magazines = magazines player
_m16a2 = {_x == "M16"} count _magazines 
_string = format ["%1",_m16a2]
cuttext [_string,"plain down",1]
titletext ["      you have    M16 magazines","plain down",1]   
~4.44
goto "magazines";

IMPORTANT!!!

don't change nothing in this code, if you wanna use them!

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  

×