Jump to content
Cigs4

Addaction in building doors

Recommended Posts

Hello,

 

It's possible to put an "addaction" command to a certain building door ?

 

I did locked all this building doors via gamelogic (9 doors in total). Now I want to put an addaction to some of this doors. Is there any easy way to do it?

 

I know there are some scripts to breach doors and all, but I was thinking to do it as simple as possible, just an addaction to unlock/picklock. That's it. 

 

For info, the map is Zargabad.

 

Thank you in advance

Share this post


Link to post
Share on other sites

 

19 minutes ago, Cigs4 said:

Hello,

 

It's possible to put an "addaction" command to a certain building door ?

 

I did locked all this building doors via gamelogic (9 doors in total). Now I want to put an addaction to some of this doors. Is there any easy way to do it?

 

I know there are some scripts to breach doors and all, but I was thinking to do it as simple as possible, just an addaction to unlock/picklock. That's it. 

 

For info, the map is Zargabad.

 

Thank you in advance

 

You can add actions to specific selections of an object, doing something like a lock/unlock system isn't simple by any means though.

Feel free to use and adapt the snippet I quickly sketched together.

 

To lock all doors you need to go through all door selections and set a special variable on them.

Why BIS implemented a module instead of a dedicated script command to do this is beyond me.

So using this snippet you no longer need the editor modules.

 

Something like this will lock all building doors, add a lock/unlock option to every door and also has a check for the owner of the building, so players can only open doors on buildings they own:

 

//put these three functions in init.sqf
GOM_fnc_lockBuildingDoor = {
	params ["_building","_door"];
	_building addAction ["Unlock door",{
		params ["_object","_caller","_ID","_door"];
		if (_object in (_caller getVariable ["GOM_fnc_keyRing",[]])) exitWith {
			_object removeAction _ID;
			_object setVariable [format ["bis_disabled_%1",_door],0,true];
			systemchat "Door unlocked.";
			playSound "Click";
			_unlockAction = [_object,_door,_caller] call GOM_fnc_unlockBuildingDoor;
		};
		systemchat "This door is locked!";//your code here
		playSound "Click";
		},_door,6,true,true,"","_this isEqualTo vehicle _this",15,false,_door];
};

GOM_fnc_unlockBuildingDoor = {
	params ["_building","_door"];
	_building addAction ["Lock door",{
		params ["_object","_caller","_ID","_door"];
		if (_object in (_caller getVariable ["GOM_fnc_keyRing",[]])) exitWith {
			_object removeAction _ID;
			_object setVariable [format ["bis_disabled_%1",_door],1,true];
			systemchat "Door locked.";
			playSound "Click";
			_lockAction = [_object,_door,_caller] call GOM_fnc_lockBuildingDoor;
		};
	},_door,6,true,true,"","_this isEqualTo vehicle _this",15,false,_door];
};

GOM_fnc_initBuildingDoors = {
		params ["_building","_owner"];
		//this adds the building to the specified player so he can unlock the doors
		_alreadyOwned = _owner getVariable ["GOM_fnc_keyRing",[]];
		_alreadyOwned pushBackUnique _building;
		_owner setVariable ["GOM_fnc_keyRing",_alreadyOwned,true];
		//grabbing all valid doors
		_selectionNames = selectionNames _building;
		_doors = _selectionNames select {toUpper _x find "DOOR" >= 0 AND toUpper _x find "HANDLE" == -1};
	{
		//lock all doors and add the actions
		_building setVariable [format ["bis_disabled_%1",_x],1,true];
		_lock = [_building,_x] call GOM_fnc_lockBuildingDoor;
	} forEach _doors;
};

 

Now to initialize a building and owner to this system simply do this during mission runtime or wherever you seem fit:

_building = cursorObject;
_owner = player;

//this sets the player as owner and locks all doors and adds all respective actions
_init = [_building,_owner] call GOM_fnc_initBuildingDoors;

 

 

 

Cheers

  • Like 9

Share this post


Link to post
Share on other sites

This may interest you as well:

See Larrow's post.

  • Like 2

Share this post


Link to post
Share on other sites

Thank you very much, Grumpy!

 

I can see what you did it. That's exactly what I was looking for.  Really cleaver, by the way.

Own you a beer.

Thanks again!

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, HazJ said:

This may interest you as well:

See Larrow's post.

 

Thanks, HazJ! 

You helped me with another issue that I had.

Own you a beer aswell.

Cheers!

  • Like 3

Share this post


Link to post
Share on other sites

@Grumpy Old Man I'm assuming that I assign each player a house (_building) by giving the asset a unique variable name, correct, then assigning the player (_owner)?

I know you said:

On 3/15/2018 at 11:31 PM, Grumpy Old Man said:

Something like this will lock all building doors, add a lock/unlock option to every door and also has a check for the owner of the building, so players can only open doors on buildings they own:


but I'm not quite grasping how to properly implement this. Please excuse my ignorance.

Also, I was wondering if there was a way to use an item to break open the door regardless if a player has locked it. The mission I'm building is a Law Enforcement RP, so even if a civilian player were to lock their doors, the police would need to be able to gain access... with a warrant of course 😉

Share this post


Link to post
Share on other sites
16 minutes ago, AAO-Optik said:

@Grumpy Old Man I'm assuming that I assign each player a house (_building) by giving the asset a unique variable name, correct, then assigning the player (_owner)?

I know you said:


but I'm not quite grasping how to properly implement this. Please excuse my ignorance.

Also, I was wondering if there was a way to use an item to break open the door regardless if a player has locked it. The mission I'm building is a Law Enforcement RP, so even if a civilian player were to lock their doors, the police would need to be able to gain access... with a warrant of course 😉

Well there's plenty of ways to implement it.

 

You can have a GUI that displays all buildings within your radius, work with a predefined array of buildings to purchase, or have another addAction to purchase the building you're looking at.

As long as you pass a building object and owner the script will do its job.

You can put the functions into initPlayerLocal.sqf or however you seem fit.

 

Cheers

Share this post


Link to post
Share on other sites
4 minutes ago, Grumpy Old Man said:

Well there's plenty of ways to implement it.

 

You can have a GUI that displays all buildings within your radius, work with a predefined array of buildings to purchase, or have another addAction to purchase the building you're looking at.

As long as you pass a building object and owner the script will do its job.

You can put the functions into initPlayerLocal.sqf or however you seem fit.

 

Cheers


Oh geez.. you just broke my brain. I'm going to be honest. I'm lost.

Share this post


Link to post
Share on other sites

I'm looking to just lock the building's doors and only allow the owner to enter the building with the only exception being police players with a certain item in their inventory. 

Share this post


Link to post
Share on other sites

@AAO-Optik Question: do the Police have to have a special item in their inventory? Or is it fine if all Police players are able to open buildings?

In that case, you can just include Police players as part of a special array in the _caller part of GOM_fnc_lockBuildingDoor (why is it called the "lockBuildingDoor" function?). 

Otherwise, if you want to require a player (any player, not just Police) to have an item, you can use these functions:

https://community.bistudio.com/wiki/items

https://community.bistudio.com/wiki/in

As a beginner programming exercise, you can try to type out a line of code that gives TRUE for a player carrying their compass (classname: ItemCompass ). Just use the Debug console in the Eden Editor and press the "local execute" button.

From there you can probably paste it into GrumpyOldMan's code to get it to work with any item you like. 

Good luck!

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

×