Zeraw 0 Posted February 5, 2019 Hey Guys! I would need your help regarding a piece of script that I'm trying to write. I try to simulate the player returning several items to an AI in order to complete a task. The intended behavior of this script is: _Check for a specific numbers of Items in the player's inventory ex.: 5 x firstAidkit, 1 x ToolBox, 5 x AntiRad etc, etc... _Remove the items that have been requested to complete the task _Set the task RECOVER ITEM to SUCCEEDED _Remove the "Give Item" action (quest_22) _Save the game _Add an Item to giftbox2 This is what I came out with : _questitems1 = [["FirstAidKit",5],["rvg_antiRad",5,6],["rvg_money",1000,1],["rvg_canisterFuel",1,20],["rvg_toolkit",1,3],["rvg_purificationTablets",5,6]]; if (_questitems1 in magazines player) then { player removeMagazine _questitems1; } else { if (_questitems1 in (backpackItems player)) then { player removeItemFromBackpack _questitems1; } else { if (_questitems1 in (vestItems player)) then { player removeItemFromVest _questitems1; } else { if (_questitems1 in (uniformItems player)) then { player removeItemFromUniform _questitems1; } else { if (_questitems1 in weapons player) then { player removeWeaponGlobal _questitems1; } else { player removeItem _questitems1; }; }; }; }; }; ["RECOVER ITEM", "SUCCEEDED",true] spawn BIS_fnc_taskSetState; quest2 removeAction quest_22; sleep 3; saveGame; quest2 addAction ["Talk to Theo",{cutText ["<t size='2'>Thanks for blablabla.</t>","PLAIN", -1, true, true],nil,1,true, true,"","true",3,false}]; giftbox2 addItemCargo ["Item_B_UavTerminal", 1]; I'm missing something in my nested statements as I tried to get it work with a unique item at first and it doesn't work. I'm not sure about the use of multi-dimensional array here but I don't see/know other ways to set differrent item with different quantities under one array. Some of the relevant pages I've checked out so far: https://community.bistudio.com/wiki/Array#Multi-dimensional_arrays https://community.bistudio.com/wiki/Control_Structures https://forums.bohemia.net/forums/topic/145490-check-player-for-a-item/ http://killzonekid.com/arma-scripting-tutorials-arrays-part-1/ I've been looking at it for too long now so I could use a fresh pair of eyes. Thank you. UPDATE: The solution to my problem. { if ((_x select 0) in magazines player) then {for "_i" from 1 to (_x select 1) do { player removeMagazine (_x select 0)}; } else { if ((_x select 0) in items player) then {for "_i" from 1 to (_x select 1) do { player removeItem (_x select 0)}; } else { if ((_x select 0) in backpackItems player) then { for "_i" from 1 to (_x select 1) do { player removeItemFromBackpack (_x select 0)}; } else { if ((_x select 0) in vestItems player) then { for "_i" from 1 to (_x select 1) do { player removeItemFromVest (_x select 0)}; } else { if ((_x select 0) in uniformItems player) then {for "_i" from 1 to (_x select 1) do { player removeItemFromUniform (_x select 0)}; } else { if ((_x select 0) in weapons player) then {for "_i" from 1 to (_x select 1) do { player removeWeaponGlobal (_x select 0)}; }; }; }; }; }; }; }foreach [["FirstAidKit",5],["rvg_antiRad",5],["rvg_money",1000],["rvg_canisterFuel",1],["rvg_toolkit",1],["rvg_purificationTablets",5]]; Enjoy! Share this post Link to post Share on other sites
killzone_kid 1332 Posted February 5, 2019 Check forEach https://community.bistudio.com/wiki/forEach Share this post Link to post Share on other sites
Zeraw 0 Posted February 5, 2019 Thanks for the reply! I spent hours on your website, a lot of very intersting stuff! Would you mind giving me a bit more of a push? These are my first scripts in .sqf. Ths is what I've tried.... not working... {if (_x in magazines player) then { player removeMagazine _x; } else { if (_x in (backpackItems player)) then { player removeItemFromBackpack _x; } else { if (_x in (vestItems player)) then { player removeItemFromVest _x; } else { if (_x in (uniformItems player)) then { player removeItemFromUniform _x; } else { if (_x1 in weapons player) then { player removeWeaponGlobal _x; } else { player removeItem _x; }; }; }; }; };} foreach [["FirstAidKit",5],["rvg_antiRad",5,6],["rvg_money",1000,1],["rvg_canisterFuel",1,20],["rvg_toolkit",1,3],["rvg_purificationTablets",5,6]]; Share this post Link to post Share on other sites
Mr H. 402 Posted February 5, 2019 Replace each _x by (_× select 0) Share this post Link to post Share on other sites
killzone_kid 1332 Posted February 5, 2019 4 hours ago, Zeraw said: Would you mind giving me a bit more of a push? what are the numbers after class names in your arrays? Share this post Link to post Share on other sites
Zeraw 0 Posted February 6, 2019 Hey! sorry for the late reply. @Mr H. Tried that and it's still telling me that it is expecting a string not an array @killzone_kid The 1st number represents the quantity of items the second the number of "bullets" in the item as interactive items in Ravage are treated as magazines. I tried without the second number as I want the Items to be brought back at full capacity but it didn't work either. I'm getting stuck here because I would like different quantities of several different Items to be in the player inventory in order to trigger the script and I'm trying to put them in an array to be able to use it as a template for other tasks that would have the same goal but with different items. Share this post Link to post Share on other sites
Dedmen 2716 Posted February 6, 2019 5 minutes ago, Zeraw said: Tried that and it's still telling me that it is expecting a string not an array Then you didn't do it correctly ^^ How about: _questitems1 = ["FirstAidKit","rvg_antiRad","rvg_money","rvg_canisterFuel","rvg_toolkit","rvg_purificationTablets"]; { if (_questitems1 in magazines player) then { player removeMagazine _questitems1; } else { if (_questitems1 in (backpackItems player)) then { player removeItemFromBackpack _questitems1; } else { if (_questitems1 in (vestItems player)) then { player removeItemFromVest _questitems1; } else { if (_questitems1 in (uniformItems player)) then { player removeItemFromUniform _questitems1; } else { if (_questitems1 in weapons player) then { player removeWeaponGlobal _questitems1; } else { player removeItem _questitems1; }; }; }; }; }; } forEach _questitems1; Your code snippet only uses the array for removing items, so I don't see the reason to have the numbers and stuff in there. Share this post Link to post Share on other sites
Zeraw 0 Posted February 6, 2019 Hey man! Thanks for your reply Ok I'll try Mr H. solution again maybe I F**** up somewhere else. Your snippet would only remove one of each item and I would like to have a certain number of each items to be removed. Share this post Link to post Share on other sites
Mr H. 402 Posted February 6, 2019 4 minutes ago, Zeraw said: Your snippet would only remove one of each item and I would like to have a certain number of each items to be removed. This explains that, your arrays are not all of the same size BTW ["FirstAidKit",5],["rvg_antiRad",5,6],["rvg_money",1000,1],["rvg_canisterFuel",1,20],["rvg_toolkit",1,3],["rvg_purificationTablets",5,6] let's say you are at the firs forEach loop: _x is read by the engine as ["FirstA idKit",5] so "FirstAidKid" is _x select 0, and the number is _x select 1. so your line would be something like : { if ((_x select 0) in items player) then { for "_i" from 1 to (_x select 1) do {player removeItem (_x select 0)}; }; }forEach [["itemstring",itemnumber],["itemstring2",itemnumber2]]; Share this post Link to post Share on other sites
Zeraw 0 Posted February 6, 2019 I'm going to write that right now, thanks! Dumb question first though... What would be "_i"? because I understand that _x select 0 and _x select 1 is selecting the position in the array and storing it in _x but i don't understand "_i".... Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted February 6, 2019 11 minutes ago, Zeraw said: I'm going to write that right now, thanks! Dumb question first though... What would be "_i"? because I understand that _x select 0 and _x select 1 is selecting the position in the array and storing it in _x but i don't understand "_i".... _i is simply a variable name, in this case it's used by the for loop to hold the current iteration and increases each iteration by the amount chosen by step (default by 1). for "_i" from 0 to 1 do { systemchat str _i; }; //will print //0 //1 for "_i" from 0 to 100 step 10 do { systemchat str _i; }; //will print //0 //10 //etc. You can name it whatever you want, as long as the same variable doesn't exist already. Might as well be _bananas, it doesn't matter. For practical purposes it's common to use _i though. Cheers Share this post Link to post Share on other sites
Zeraw 0 Posted February 6, 2019 Thank you very much! That's more than I was expecting! Made It work thanks again! I'm updating the thread If someone needs it. Thanks again guys! Share this post Link to post Share on other sites