Jump to content
slothstronaut

Blocking other players from opening containers

Recommended Posts

I'd like to block players from opening a crate that another player is currently accessing. I had thought to set a variable on the container (inUse or something) on the ContainerOpened event, which was reset on ContainerClosed, then have anyone attempting to open the container check against that variable.

 

The logic, I think, is sound. I just don't know how to prevent bringing up the container dialog. 

 

Any assistance would be fantastic!

Share this post


Link to post
Share on other sites
Fn_IsRestrictedBoxForPlayerAccess = { // implement this function to return true if player restricted to access given box, otherwise false
	params ["_unt", "_box"]; false};

player addEventHandler ["InventoryOpened", Fn_IsRestrictedBoxForPlayerAccess];

UPD: Fixed handler code

Share this post


Link to post
Share on other sites

For example:

player setVariable ["AccessLevel", 1];

box001 setVariable ["AccessLevel", 0]; // accessible by player
box002 setVariable ["AccessLevel", 1]; // accessible by player
box003 setVariable ["AccessLevel", 2]; // not accessible by player


Fn_IsRestrictedBoxForPlayerAccess = {	
	params ["_unt", "_box"];
	_unt getVariable ["AccessLevel", 0] < _box getVariable ["AccessLevel", 0]};
  • Like 1

Share this post


Link to post
Share on other sites
Fn_IsRestrictedBoxForPlayerAccess = { // implement this function to return true if player restricted to access given box, otherwise false
	params ["_unt", "_box"]; false};

player addEventHandler ["InventoryOpened", {	
	if (_this call Fn_IsRestrictedBoxForPlayerAccess) then {
		_this spawn {
			waitUntil {not isNull (findDisplay 602)};
			(findDisplay 602) closeDisplay 2}}}];

 

closeDisplay? I know there are many ways to make life difficult in Arma, but why not make life easy and return true to override the opening?

  • Like 1

Share this post


Link to post
Share on other sites

closeDisplay? I know there are many ways to make life difficult in Arma, but why not make life easy and return true to override the opening?

 

Then just:

player addEventHandler ["InventoryOpened", Fn_IsRestrictedBoxForPlayerAccess];

Share this post


Link to post
Share on other sites

Thanks for the code example serena and the documentation link killzone_kid!

The example you've given is close to what I have now but on ContainerOpened. I am guessing that doesn't make sense as the event is for the container, not the player, whereas the opposite is true for InventoryOpened. I'll adjust my script today and see how I go.

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

×