Jump to content
Sign in to follow this  
PixeL_GaMMa

Event handler ContainerClosed server side?

Recommended Posts

_this addEventHandler ["ContainerClosed", { .... etc

 

As the title.... is it possible to get this event to fire server side? or will it only fire on the client?

Share this post


Link to post
Share on other sites

What are you trying to do? Why do you need it on server? You can PV code across network but I don't see the need for this.

Share this post


Link to post
Share on other sites

I want to fire a server only function when a container is closed (specifically in this case a vehicle), without relying/trusting the client to call the function remotely....

Share this post


Link to post
Share on other sites

It will only fire for the client opening the container. You can use remoteExecCall or CBA events to alert the server. Like:

_this addEventHandler ["ContainerClosed", {["PX_ContainerClosed", _this] call CBA_fnc_serverEvent}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Will this still work if the event is assigned from the server? (wiki says it is global)

Share this post


Link to post
Share on other sites

Not sure what you mean? The wiki says the argument to addEventHandler can be global, in this case the container. But as the note says, it will only fire where the player opening it is local.

 

So, I guess no, you have to addEventHandler on all player machines. Basically if (hasInterface)...

  • Like 1

Share this post


Link to post
Share on other sites

Here is a full example of what I had it mind.

// for example in init.sqf
if (isServer) then {
    ["PX_ContainerClosed", {
        params ["_container", "_unit"];
        // What you want to do on the server here
        // ....
    }] call CBA_fnc_addEventHandler;  
};

if (hasInterface) then {
    {
        _x addEventHandler ["ContainerClosed", {
            ["PX_ContainerClosed", _this] call CBA_fnc_serverEvent;
        }];
    } forEach [MyContainer1, MyContainer2];
};

 

  • Like 1

Share this post


Link to post
Share on other sites

The problem with this is containers are dynamic and can be 100s, so to add event handler to all containers on all clients would be too much, I will try to come up with an alternative method. Thanks for help.

Share this post


Link to post
Share on other sites

Event handlers are totally client side so you should be fine. I mean most object each has dozen of event handlers on anyway.

 

But are you sure you cannot use InventoryClosed instead?

  • Like 1

Share this post


Link to post
Share on other sites

Yep I'm thinking about using InventoryClosed which can then remote call server side function (assuming, it is the correct type of container) ... probably this will be fine. Thanks again.

Share this post


Link to post
Share on other sites

InventoryClosed could be added locally to the player. The EVH wouldn't really care what inventory of what box is being opened though, so you may want to do an extra check if that is something you need.

Share this post


Link to post
Share on other sites

You don't even need to remote call. At least according to BIKI you can add remote units. Some skilled SQF'ers on the Discord informed me the BIKI was wrong. The event handler only runs if the object/player is local.

 

You need something like this:

// for example in: initPlayerLocal.sqf
params ["_player", "_didJIP"];

_player addEventHandler ["InventoryClosed", {
    ["PX_InventoryClosed", _this] call CBA_fnc_serverEvent;
}];

And on the server you handle the event

// for example in: initServer.sqf
["PX_InventoryClosed", {
    params ["_unit", "_container"];
    // Do your stuff here.
}]

 

You are probably going to want to check the type of the _container, since the player can open inventory arbitrary. If the player opens inventory on nothing, or on stuff put on the ground,  _container isKindOf "GroundWeaponHolder". Idea: maybe do as much processing as possible involving the _container on the player side before sending the event. Since you are closing a container, it might be a GroundWeaponHolder becoming empty, and thus it might have been deleted when the message get processed on the server.

  • Like 2
  • Thanks 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
Sign in to follow this  

×