Jump to content
Hotfixx

How to addItemCargo via variable?

Recommended Posts

Hi all,

I'm just posting to see if anyone could give some helpful advice on how I could fix a little problem that I am having! :)

 

I am currently creating a script that copy and pastes the content of a crate into another one. I am making use of the getItemCargo and addItemCargo scripting commands in order to achieve this. I am storing the getItemCargo in a variable, for example: 

 

variableItems = getItemCargo cursorTarget;

 

This returns an array of items that looks like this: [["30Rnd_556x45_Stanag","Chemlight_blue"],[3,1]]

 

However I am unable to add the items succesfully to the other crate with the supplyBox addItemCargo [variableItems];

 

This does not add the items to the create though and I think the reason behind this is because the actual command is split into [item, count] and is not just one array. From an analytical standpoint, I think the best point forward is to split the array, but here's the thing, I don't know how. This mean's I would split ["30Rnd_556x45_Stanag","Chemlight_blue"] into a variable item, and [3,1] into count. I tried the select command but I think I am using it wrong because the full array returns. 

 

I am fairly new to SQF and have been making good use of the wiki, but if someone could give a snippet of code on how to split this array into two variables, that would be fantastic!

 

- Hotfix =)

 

Share this post


Link to post
Share on other sites

Try this:

variableItems params ["_classes","_count"];
for "_i" from 0 to count _classes - 1 do {
    supplyBox addItemCargo [_classes select _i,_count select _i]
};

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, das attorney said:

Try this:


variableItems params ["_classes","_count"];
for "_i" from 0 to count _classes - 1 do {
    supplyBox addItemCargo [_classes select _i,_count select _i]
};

 

 

Just impemented this now as it seems to work! I didn't know you could declare each index of the array with params, and I'll be sure to make use of "count" in the future!  Thank's for helping a newbie out!

+1 for Das Attorney!

  • Like 1

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

×