Jump to content
BeaniePope.

Spawning items into container

Recommended Posts

So, I have a mission file where I want players to open containers with the variable names  "container1" to "containerX", and they will contain randomized loot items. My attempt at the script is below, and it doesn't throw any errors, but it also doesn't do anything. 

If anyone knows why my script doesn't work, please let me know! Would be a great help!

(The reason it iterates through a containers array is for future usage of the array)
 

private _loot = ["Item_AM_scrapelectronics", "Item_AM_mataljunk", "Item_AM_ductape"];

private _containerCount = 4;
// ------------------------------------------------
private _containers = [""];

_containers resize _containerCount;


{
    private _lootIndex = 0;
    private _lootAmount = 0;
    _lootSize = count _loot; 
    _lootIndex random _lootSize;
    _lootAmount random 10;
    _lootItem = _loot select _lootIndex; 
    private _index = _forEachIndex;

    _x = "container" + str _index;
    private _variable = _x;
    private _container = missionNamespace getVariable _variable;
    _container addItemCargoGlobal [_lootItem, _lootAmount];
    
} forEach _containers;

 

Share this post


Link to post
Share on other sites

I'm not sure that _loot var contains correct class names, so check them.

There is also for loop that is more suitable for your case.

Share this post


Link to post
Share on other sites

You could start with a simple version and build on it.

Choose one item and place just one in the container via a script.

 

When you get that to work, build on it.

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

×