Jump to content
Sign in to follow this  
Maurdekye

InventoryOpen handler only triggering task completion from host

Recommended Posts

I have a couple of optional objectives in my map that are attached to crates, and are supposed to complete once any of the players opens one. I have the following code in my init.sqf to handle this;

{
_x addEventHandler ["InventoryOpened", {
	_inv = str (_this select 1);
	if (_inv == "back") then {
		back_taken = true;
	};
	if (_inv == "medi") then {
		medi_taken = true;
	};
	if (["snipe", _inv] call BIS_fnc_inString) then {
		snipe_taken = true;
	};
	if (["antitank", _inv] call BIS_fnc_inString) then {
		at_taken = true;
	};
}];
} foreach [unit0, unit1, unit2, unit3];

However, the objectives are only completed once the host opens the crates, even though the listener is being called for the other players.

Share this post


Link to post
Share on other sites

Most likely a locality issue, as the code inside the event handler will be run locally on the unit which triggered the EH.

So in this case, it will be setting the variables (which I assume the objectives are `bound` to) to true on the client and not on the server/host - using publicVariable to broadcast the values should resolve the issue.

Share this post


Link to post
Share on other sites

Do I call this when I initialize the variable, or after I change it?

Share this post


Link to post
Share on other sites
Do I call this when I initialize the variable, or after I change it?

After the value has changed, you want to broadcast it to the server/other players

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  

×