PixeL_GaMMa 31 Posted May 15, 2018 _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
HazJ 1289 Posted May 15, 2018 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
PixeL_GaMMa 31 Posted May 15, 2018 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
Muzzleflash 111 Posted May 15, 2018 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}]; 1 Share this post Link to post Share on other sites
PixeL_GaMMa 31 Posted May 15, 2018 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
Muzzleflash 111 Posted May 15, 2018 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)... 1 Share this post Link to post Share on other sites
PixeL_GaMMa 31 Posted May 15, 2018 ok thanks will do some tests. Share this post Link to post Share on other sites
Muzzleflash 111 Posted May 15, 2018 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]; }; 1 Share this post Link to post Share on other sites
PixeL_GaMMa 31 Posted May 15, 2018 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
Muzzleflash 111 Posted May 15, 2018 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? 1 Share this post Link to post Share on other sites
PixeL_GaMMa 31 Posted May 15, 2018 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
HazJ 1289 Posted May 15, 2018 You can filter type of container. targetContainer: Object - connected container or weaponholder https://community.bistudio.com/wiki/typeOf Share this post Link to post Share on other sites
mudnut 5 Posted May 15, 2018 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
Muzzleflash 111 Posted May 15, 2018 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. 2 1 Share this post Link to post Share on other sites
Muzzleflash 111 Posted May 16, 2018 I updated the post above, since it was based upon a false assumption. 1 Share this post Link to post Share on other sites