wesley32 4 Posted October 20, 2014 Hi guys, I have a question regarding getWeaponCargo: https://community.bistudio.com/wiki/getWeaponCargo It returns an array of all weapons plus counts the amount. However the return value, e.g. [["arifle_Katiba_F","launch_B_Titan_short_F"],[2,1]] is unusable by AddWeaponCargoGlobal. When I try to use: this addWeaponCargoGlobal [["arifle_Katiba_F","launch_B_Titan_short_F"],[2,1]] nothing happens.. Anyone any suggestions on how to make this work? Thanks in advance. Share this post Link to post Share on other sites
654wak654 25 Posted October 20, 2014 Yeah that's a really annoying issue that I also had to figure out while doing the crate saving functions for Boydee. Here is an example, hope it's clear enough: [color=#FF8040][color=#1874CD]_weapons[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getWeaponCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color] [color=#006400][i]//Just get the contents like usual.[/i][/color] [color=#191970][b]clearWeaponCargoGlobal[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color] [color=#006400][i]//Clear cargo, then add everything back.[/i][/color] [color=#191970][b]for[/b][/color] [color=#7A7A7A]"_i"[/color] [color=#191970][b]from[/b][/color] [color=#FF0000]0[/color] [color=#191970][b]to[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]-[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]do[/b][/color] [color=#8B3E2F][b]{[/b][/color] [color=#1874CD]_crate[/color] [color=#191970][b]addWeaponCargoGlobal[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color] Made with KK's SQF to BBCode Converter. Also thanks to the good old arrays thread. Share this post Link to post Share on other sites
iceman77 19 Posted October 20, 2014 (edited) _content = getWeaponCargo someVeh; clearWeaponCargoGlobal myVeh; { myVeh addWeaponCargoGlobal [( _content select 0 ) select _forEachIndex,( _content select 1 ) select _forEachindex]; } forEach _content; Oops ninja'd as I was wiki'n, writing, tinkering and testing :p Edited October 20, 2014 by Iceman77 May aswell post a working snippet lol Share this post Link to post Share on other sites
wesley32 4 Posted October 20, 2014 _content = getWeaponCargo someVeh; clearWeaponCargoGlobal myVeh; { myVeh addWeaponCargoGlobal [( _content select 0 ) select _forEachIndex,( _content select 1 ) select _forEachindex]; } forEach _content; Oops ninja'd as I was writing / tinkering / testing :p It's working but it only adds the first weapon in the array, say theres a MX and a Sniper in myVeh, I only get an MX in myVeh2. Share this post Link to post Share on other sites
iceman77 19 Posted October 20, 2014 Hmm. I just tested it. It added 2 rifles and a launcher to the vehicle :p. I did re-edit it (note the little edit foot note above). You ment to quote the old code I think. ---------- Post added at 10:57 ---------- Previous post was at 10:52 ---------- Yeah, totally works bro ;) ---------- Post added at 11:01 ---------- Previous post was at 10:57 ---------- - Put down an ammo crate named myVeh. - Put down a hunter named myVeh2 - Past code into init.sqf - Tested _content = getWeaponCargo myVeh; clearWeaponCargoGlobal myVeh2; { myVeh2 addWeaponCargoGlobal [( _content select 0 ) select _forEachIndex,( _content select 1 ) select _forEachindex]; } forEach _content; Pretty sure you somehow quoted the new code (edit) after you tried the previous code and it failed. Which the first snippet I posted did infact only add the first weapon. Which is why i had to edit the post =) Share this post Link to post Share on other sites
wesley32 4 Posted October 20, 2014 Yes you're right lol. Now 2 weapons save but when I put in a rifle,launcher and pistol, the pistol still disappears :( Share this post Link to post Share on other sites
iceman77 19 Posted October 20, 2014 (edited) There! Long day :p Adds all weapons! _content = getWeaponCargo myVeh; clearWeaponCargoGlobal myVeh2; { { myVeh2 addWeaponCargoGlobal [( _content select 0 ) select _forEachIndex,( _content select 1 ) select _forEachindex]; } foreach _x; } forEach _content; Edited October 20, 2014 by Iceman77 Share this post Link to post Share on other sites
wesley32 4 Posted October 20, 2014 Thanks, it works. You're a hero!:D Share this post Link to post Share on other sites
iceman77 19 Posted October 20, 2014 I love being a hero! You may want to give Wak's a go! I do believe that the for loop is faster maybe ?? Idk, I'm not going to test it... or am I?! Share this post Link to post Share on other sites
wesley32 4 Posted October 20, 2014 Another problem just occured, in myVeh2 every weapon it duplicated so theres twice as much stuff in there. Haven't been able to get that one to work yet, this one almost works!:) Share this post Link to post Share on other sites
654wak654 25 Posted October 20, 2014 Whole point of my code is that the for is faster! Because we're only working with integers. Just something left from Java (Ironical thinking of yesterday's conversation ;)) Though I'd like to know your 2C. Wesley32 here is almost the same code with Iceman's way, hope you can get it to work: [color=#FF8040][color=#006400][i]//Will make myVeh_1's weapon cargo the same as myVeh_0's.[/i][/color] [color=#1874CD]_weapons[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getWeaponCargo[/b][/color] myVeh_0[color=#8B3E2F][b];[/b][/color] [color=#1874CD]_index[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color] [color=#191970][b]clearWeaponCargoGlobal[/b][/color] myVeh_1[color=#8B3E2F][b];[/b][/color] [color=#191970][b]for[/b][/color] [color=#7A7A7A]"_i"[/color] [color=#191970][b]from[/b][/color] [color=#FF0000]0[/color] [color=#191970][b]to[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]count[/b][/color] [color=#1874CD]_index[/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]-[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]do[/b][/color] [color=#8B3E2F][b]{[/b][/color] myVeh_1 [color=#191970][b]addWeaponCargoGlobal[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_index[/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color] Made with KK's SQF to BBCode Converter Share this post Link to post Share on other sites
iceman77 19 Posted October 21, 2014 (edited) Thanks Wak. Okay I'm back! Transfers all cargo and no duplicates. Took me long enough LOL. Cheers. _content = getWeaponCargo myVeh; clearWeaponCargoGlobal myVeh2; { myVeh2 addWeaponCargoGlobal [( _content select 0 ) select _forEachIndex,( _content select 1 ) select _forEachindex]; } forEach ( _content select 0 ); Note: may want to use Wak's for loop. I just wanted to post this as it was bugging me that what I posted earlier kept having issues. Took me 4ever to realize I only neded to iterate the first _content array / element... /derp Edited October 21, 2014 by Iceman77 Share this post Link to post Share on other sites
654wak654 25 Posted October 21, 2014 Oh it took me a whole night and then the morning of the next day to get mine working, you're still way faster :p. Share this post Link to post Share on other sites
wesley32 4 Posted October 21, 2014 Yay all works great now. Thank you both for your help! Share this post Link to post Share on other sites
iceman77 19 Posted October 22, 2014 Yay all works great now. Thank you both for your help! That's fantastic! I'm glad to have been a part of helping you. Cheers. Oh it took me a whole night and then the morning of the next day to get mine working, you're still way faster :p. Didn't you post your solution like ~10 minutes after the thread was created? I know it took me awhile. Not only having a snag, but up and down at my computer doing rl stuff. Anyhoo... tallyho! Share this post Link to post Share on other sites
654wak654 25 Posted October 22, 2014 Yeah that's a really annoying issue that I also had to figure out while doing the crate saving functions for Boydee. First sentence of that first post, see? Share this post Link to post Share on other sites