Jump to content
Sign in to follow this  
boydee

Player locker system

Recommended Posts

I'm just wondering if anyone knows of a way to lock and unlock ammo boxes to certain players to create a "locker" kind of ammo box.

I've had a play with triggers set to unlock objects when triggered but was hoping to have an interaction code or locked to a player ID.

Share this post


Link to post
Share on other sites

Hmm, I tried to remove all box related actions (Rearm etc.):

for "_i" from 0 to 10 do {_box removeAction _i;};

...but that didn't work. Seems like some actions are sort of "static" since you can't remove all actions from the player as well.

I don't think you can do this without adding a custom crate array to the box.

EDIT: Well, again I have been disabused (see DreadedEntity's post below). But if interested for some reason:

_box = ["Box_NATO_Wps_F", getPosATL player, [], 0, "NONE"];
_box setVariable ["ammoBox", [["srifle_EBR_F", 3], ["20Rnd_762x51_Mag", 10], ["launch_NLAW_F", 1], ["NLAW_F", 2]]];
_box addAction ["Open box", tag_fnc_openAmmoBox, cursorTarget, "", 0, false, true, "", "_this distance _target < 3 && {player_is_allowed_condition}"];

tag_fnc_openAmmoBox would be a function to open a dialog to browse through the "ammoBox" array (the array added by setVariable). But that's another issue and I'm really not the guy for dialog creation and handling. I hope that helps though.

Best regards,

waltenberg aka Johnny

Edited by waltenberg

Share this post


Link to post
Share on other sites

Create and update the crate's contents locally for each client instead of creating some wonky locker system =)

Edited by Iceman77

Share this post


Link to post
Share on other sites

2 questions about this in 2 days, wow! I was trying to smash out some code yesterday to answer another thread about pretty much this exact topic, but apparently the event handler that I wanted to use is currently not working in stable releases and I should go to the dev branch (still haven't). But if you want to go to the dev branch here's the code I came up with (re-written to work with OBJECTS rather than sides).

/*
USAGE: _name = [P1, P2] execVM "script.sqf";
	P1: OBJECT - The container you want to lock.
	P2: OBJECT - The only player that can access the container.

*/

_obj = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_player = [_this, 1, objNull, [objNull]] call BIS_fnc_param;

_obj addEventHandler ["ContainerOpened",
{
_openedContainer = _this select 0;
_unit = _this select 1;

if (_player != _unit) then
{
	_unit action ["CancelAction", _unit];
	hint "You are not allowed to access this container";
};
}];

This code relies on the "_player" variable being passed to the event handler through the script, I'm not sure if it actually works that way. So this code might not work at all.

Share this post


Link to post
Share on other sites

Cool thanks guys I haven't had a chance to test anything yet but I'll see how I go and let you know.

Share this post


Link to post
Share on other sites
2 questions about this in 2 days, wow! I was trying to smash out some code yesterday to answer another thread about pretty much this exact topic, but apparently the event handler that I wanted to use is currently not working in stable releases and I should go to the dev branch (still haven't). But if you want to go to the dev branch here's the code I came up with (re-written to work with OBJECTS rather than sides).

/*
USAGE: _name = [P1, P2] execVM "script.sqf";
	P1: OBJECT - The container you want to lock.
	P2: OBJECT - The only player that can access the container.

*/

_obj = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_player = [_this, 1, objNull, [objNull]] call BIS_fnc_param;

_obj addEventHandler ["ContainerOpened",
{
_openedContainer = _this select 0;
_unit = _this select 1;

if (_player != _unit) then
{
	_unit action ["CancelAction", _unit];
	hint "You are not allowed to access this container";
};
}];

This code relies on the "_player" variable being passed to the event handler through the script, I'm not sure if it actually works that way. So this code might not work at all.

So I tired this yesterday and I may or may not be doing it right.

I have that code in a file lockers.sqf

Then I named the player "P1" and the corresponding ammo-box which has been cleared of all gear the name of "P2" and in the initialization field of the box

"this addAction ["Locker D-5", ""]; this allowDamage False; _name = [P1, P2] execVM "scripts\lockers.sqf";"

How ever as you said it may not work. I'm still very new to scripts as well so I maybe doing something wrong. Also the addaction is just to give It a name kind of thing.

Share this post


Link to post
Share on other sites

Yeah I saw that when dead said that. I just wanted to test it and make sure if I was doing it right.

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  

×