Jump to content
BadHabitz

Script for filling boxes on a dedicated server.

Recommended Posts

Greetings esteemed Arma scripters! I humbly come to you with a problem I'm hoping someone can solve.

 

So, I'm working on a mod for my unit to have individual supply boxes for each unit member. The objects are available in the mission editor and are also Zeus placeable. That I've got without problems. The hangup comes in when someone crashes. When they go back to their supply box the things they previously took out are gone, because they crashed.

 

My solution is to add "reset" addAction, which is a sqf to clear the box and then addItemCargoGlobal to refill the box. These boxes are also not local to the mission file, but are created with a pbo in the modpack. To sucessfully code it into the config.cpp I use this code in the box's cfgVehicles class:


class EventHandlers: EventHandlers

{
init = "(_this select 0) addAction [""<t color='#ffffff'>Reset</t>"", ""\Gearboxes\scripts\frostbox.sqf"",[],1,false,true,"""",""_this distance _target < 3""];";
};

 In the header of the sqf I use the following (with an example item added):


if (! isServer) exitWith {};

_crate = _this select 0;

clearItemCargoGlobal _crate;

_crate additemcargoglobal ["acc_flashlight_pistol", 1];

 

All of this works as intended in local and local multiplayer. The config adds the addAction to the box and the script removes all of the items and them reloads the desired items.

 

The issue is the box doesn't clear or reload on a dedicated server. The addAction is present but there is zero effect. The purpose of this project is to use it on a dedicated server, so it's a problem that needs solving.

 

If I change "_this select 0" in "_crate = _this select 0;" to a variable assigned to the box then it works fine. Example "_crate = frostbox;"

 

So I think that's the bit of code I need to change to get this to work without having to assign variables to all of the boxes and to align the sqf's to match.

 

Anyone have an idea?

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 9/30/2020 at 3:39 AM, BadHabitz said:

if (! isServer) exitWith {};

You have addAction applied via config init EH, so the action is available to all.

Yet the script exits if the action is not used on the server? I don't see how that works for anything but SP, MP Hosted just for host, MP Dedicated it will work for no one.

Share this post


Link to post
Share on other sites

I admit I don't know much about why certain things are in the sqf. That bit of code entered my usage some time in the past and wherever I've used it it seems to work, or at least it doesn't stop anything from working (that I can tell).

 

I do want the addAction to be able to be used by anyone specific to the designated box. It works in SP, MP mode through the editor, but in the MP Dedicated the addAction is on the box but does nothing.

 

So do you think if I get rid of that line it will work? Or is your reply solely focused on asking why I use that line?

 

Thanks for replying, either way.

Share this post


Link to post
Share on other sites
3 hours ago, BadHabitz said:

So do you think if I get rid of that line it will work?

Yes.

 

3 hours ago, BadHabitz said:

I do want the addAction to be able to be used by anyone specific to the designated box.

What is "anyone specific to the designated box" ?

As you have shown above the action is in the crates init EH, so the action will be available to everyone.

Share this post


Link to post
Share on other sites
8 hours ago, Larrow said:

What is "anyone specific to the designated box" ?

 

Sorry, I was just trying to clarify that I didn't want the box designated for each individual to only be able to be used by that individual. I want anyone to be able to reset the contents of any box. 

 

I'll be packing up a pbo with the change and it will get tested tonight. I'll let you know how it works out.

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

×