Jump to content
Sign in to follow this  
copper2010

Task completed if player has certain items in his inventory.

Recommended Posts

So in my WIP mission, I want to player to have a certain amount, and certain items in his inventory (One MX, one P07, both with seven mags each, and ten first aid kits to be exact). I know there is some way for the game to check to see if the player has these items in his inventory, I just don't know how to make the game check.

Can anyone point me in the right direction?

Share this post


Link to post
Share on other sites

Thanks, but how would the coding go.

In other words, what do I type to have the system say, "OK, the player now has these items, the task is complete". Do I have to sync the trigger with the Set Task State module?

Also, I am assuming there are also "hasItem" and "hasMagazine" syntax's too.

Share this post


Link to post
Share on other sites

There are, but those don't count how many you have. YOu could use the new magazinesDetail command, but that output looks like this:

["9mm 16Rnd Mag(16/16)[id:91]","9mm 16Rnd Mag(16/16)[id:92]","6.5mm 30Rnd STANAG Mag(30/30)[id:98]","9mm 16Rnd Mag(16/16)[id:93]","6.5mm 30Rnd STANAG Mag(30/30)[id:99]","9mm 16Rnd Mag(16/16)[id:94]","6.5mm 30Rnd STANAG Mag(30/30)[id:100]","6.5mm 30Rnd STANAG Mag(30/30)[id:101]","6.5mm 30Rnd STANAG Mag(30/30)[id:102]","6.5mm 30Rnd STANAG Mag(30/30)[id:103]","9mm 16Rnd Mag(16/16)[id:95]","9mm 16Rnd Mag(16/16)[id:96]"]

Which doesn't look easily parse able. :) Also not sure if the id: numbers will change from player to player.

Since you're looking for a whole loadout you might consider just putting the stuff in a box and checking for the box to be empty instead of checking that each little bit is on the player.

Share this post


Link to post
Share on other sites

I never knew you could do that, well that makes it a lot easier.

Could you give me the command for that please? I can't find anything that looks like it on the Arma wiki.

Share this post


Link to post
Share on other sites

Place your ammo box named toybox with this as it's init field:

clearWeaponCargoGlobal this; clearMagazineCargoGlobal this; this addItemCargoGlobal ["FirstAidKit", 10]; this addWeaponCargoGlobal ["hgun_P07_F", 1]; this addWeaponCargoGlobal ["arifle_MX_F", 1]; this addMagazineCargoGlobal ["16Rnd_9x21_Mag", 7]; this addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", 7];

Place a trigger with this as it's condition:

count (getWeaponCargo toybox select 1) == 0 && count (getMagazineCargo toybox select 1) == 0 && count (getItemCargo toybox select 1) == 0

and this as it's onAct:

hint "Toybox is empty!"

When you remove the last item from the box you'll get the "Toybox is empty!" message. Use that trigger going off as your task condition.

getWeaponCargo results in something like this: [["weapon"],[1]]. So an array with two arrays within it. First subarray lists the weapons classnames and the second subarray lists the count of weapons in it. So one rifle and two pistols would look like: [["rifle","pistol"],[1,2]]; If it's empty it looks like [[],[]].

So the trick I use is to count how many elements are in the second array (select 1, remember arrays start at 0) which would be the count of weapons. If there's no result it means it's empty.

Ex: [["weapon"],[1]]
box getWeaponCargo select 1 = [1]
count box getWeaponCargo select 1 = 1 (only one element in the array)

Ex: [["rifle","pistol"],[1,2]]
box getWeaponCargo select 1 = [1,2]
count box getWeaponCargo select 1 = 2 (note that it's 2, not 3, because it's counting how many elements not adding them together)

Edited by kylania
Added some explanation
  • Like 1

Share this post


Link to post
Share on other sites

Or

player hasWeapon "arifle_mx_aco_pointer_f" [b]AND[/b] player hasweapon "hgun_p07_f" [b]AND[/b] (({_x == "30Rnd_65x39_caseless_mag"} count magazines player) >= 7) [b]AND[/b] (({_x == "16Rnd_9x21_Mag"} count magazines player) >= 7)

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  

×