Larpushka 17 Posted August 19, 2018 Hey guys, Basically I placed a building, now I want to define the door (or doors) of this building as "locked." In addition, I want to place a key and say that only if the player has this key, he can unlock it. I assume it should be easily possible, but whenever I place a building I can't seem to specifically choose the door and the "attribute" of the building don't make it straightforward also. Could you help me? Though I'm a modding newbie I really did do the best research I could before resorting to posting here. Share this post Link to post Share on other sites
gc8 977 Posted August 19, 2018 The door "lock" can be changed via this variable: building setVariable["bis_disabled_Door_1",1,true]; Then you need to use addAction with selection to put the action on the door you want. That should get you started... Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted August 19, 2018 44 minutes ago, Larpushka said: Hey guys, Basically I placed a building, now I want to define the door (or doors) of this building as "locked." In addition, I want to place a key and say that only if the player has this key, he can unlock it. I assume it should be easily possible, but whenever I place a building I can't seem to specifically choose the door and the "attribute" of the building don't make it straightforward also. Could you help me? Though I'm a modding newbie I really did do the best research I could before resorting to posting here. Made something that could get you started, check this out: Cheers 4 1 Share this post Link to post Share on other sites
Larpushka 17 Posted August 19, 2018 @Grumpy: Your example is nice but it's not "object-based" it's "owner based". I ran into a few other problems -- there's no "key" object. I tried to use a "crowbar" object instead but I'm not sure if it can be made "pickable". Can it? Thanks gc8, I tried playing around with it and I get the idea behind the script I write. A certain item which you can pick up will have the code: [If this item exists in the player's inventory - unlock door with the name/tag XXXXX] Very simple, right? It would seem it needs to be just one line attached an object. Am I wrong? Share this post Link to post Share on other sites
gc8 977 Posted August 19, 2018 Use addaction to add the scroll menu action on doors. You don't really need a key just some variable that tells player has the key and can use the action. Check out this thread how to do it: Share this post Link to post Share on other sites
Larpushka 17 Posted August 20, 2018 Quote You don't really need a key just some variable that tells player has the key and can use the action. But without the key they shouldn't be able to open the door (that's how I'd like it to work), so I do need the key. The thread/script you linked to just indicate if a player is the owner of the building, which is not what I'm going for. If there was some manual I could read to understand how I do it, I'd read it and wouldn't bother you guys, but right now the information seems quite fragmented. Share this post Link to post Share on other sites
gc8 977 Posted August 20, 2018 @Larpushka Sorry I don't understand how you want the key to be? An item in your inventory, or something else? If you give more details we can help you better. Share this post Link to post Share on other sites
pierremgi 4897 Posted August 20, 2018 There is no key as object in Vanilla (non modded) Arma. So, what people said, is that you can: - lock a specific door if you need, for any player; - add an action on this specific door to open it under conditions: * presence of an item in you inventory, * specific guy (player's name, friendly unit, medic trait....) * any player with a specific variable. Because you don't need to own an object, just a variable pass (condition true) allowing the action on the door. The way you obtain "the pass" is your choice. We can't guess that. You didn't explain if you're in MP or SP and what mod / object you intend to use (if any). Share this post Link to post Share on other sites
Larpushka 17 Posted August 20, 2018 Sorry, I'll explain better then. It's SP. And yes, it should be the presence of an item in your inventory that causes the door to open. It doesn't have to be a key if it doesn't exist in vanilla arma. How do I condition "If object X exists in player's inventory" ? I get that Quote building setVariable["bis_disabled_Door_1",1,true]; Is how I lock/open doors. The issue for me is technically setting the condition. It should be a few lines, right? Quote If player has item X building setVariable["bis_disabled_Door_1",1,true]; else building setVariable["bis_disabled_Door_1",1,false]; I appreciate you guys being nice about it, posting really was my last resort. Share this post Link to post Share on other sites
gc8 977 Posted August 20, 2018 (edited) @Larpushka Here's you the basic function that locks the doors in building and allows you to unlock the doors with action menu: lockDoors = { params ["_posObj"]; if(typename _posObj == "OBJECT") then // Is passed parameter an object? { _posObj = getpos _posObj; }; _bldg = nearestBuilding _posObj; // Get the building closest to the parameter object/location _num = getNumber (configfile >> "CfgVehicles" >> typeOf _bldg >> "numberOfDoors"); // Need to get number of doors in the building diag_log format["Locking doors %1", _num]; for "_i" from 1 to _num do // loop through all the doors in the building { _bldg setVariable [format["bis_disabled_Door_%1",_i], 1, false]; // lock the door _sel = format["Door_%1", _i]; // The door selection for addaction command // Add action user can select from the scroll menu _aid = _bldg addAction ["<t color='#ffbf00'>Unlock door</t>", { params["_bldg","_caller","_actId","_doorIndex"]; hint "Opening door"; _bldg setVariable [format["bis_disabled_Door_%1",_doorIndex], 0, false]; // Unlock the door }, _i,1.5,true,true,"","true",3,false,_sel]; }; }; In there, inside the addaction's condition field you can put your key check. So that the action only appears if you have the key... This function is SP btw you need to call the function by giving it either object or position as parameter Example usage: myBuilding call lockDoors; Put game logic called "myBuilding" near the building in editor that you want locked, then call that function from init.sqf Edited August 21, 2018 by gc8 more comments Share this post Link to post Share on other sites
HazJ 1289 Posted August 21, 2018 There is no physical item so if you want an actual key, you'd have to make your own virtual inventory UI. However... There are ways to manipulate the in-game inventory UI. You could add a key icon somewhere. You cannot directly modify the listbox though, although people have worked around it, it isn't an ideal solution and far from perfect. Vanilla wise that is. WIthout items mod. Share this post Link to post Share on other sites
pierremgi 4897 Posted August 21, 2018 Just test it with a toolKit. Let's say, if the player has one in his inventory, he can open the doors: Just modify the @gc8 script like this (as far as you don't need to re-lock the door): lockDoors = { params ["_posObj"]; if(typename _posObj == "OBJECT") then { _posObj = getpos _posObj; }; _bldg = nearestBuilding _posObj; _num = getNumber (configfile >> "CfgVehicles" >> typeOf _bldg >> "numberOfDoors"); diag_log format["Locking doors %1", _num]; for "_i" from 1 to _num do { _bldg setVariable [format["bis_disabled_Door_%1",_i], 1, false]; _sel = format["Door_%1", _i]; _aid = _bldg addAction ["<t color='#ffbf00'>Unlock door</t>", { params["_bldg","_caller","_actId","_doorIndex"]; hint "Opening door"; _bldg setVariable [format["bis_disabled_Door_%1",_doorIndex], 0, false]; }, _i,1.5,true,true,""," 'ToolKit' in items _this ",3,false,_sel]; }; }; mybuilding call lockdoors Share this post Link to post Share on other sites
Larpushka 17 Posted August 21, 2018 Yes pierre, I don't need to relock the door. And as far as a physical key item, it's fine. Any chance you can add commentary to your script? I can't follow the logic. Is "typename" the name I give the building? Why do I have to use configfile? seems a bit too fancy of a script for something so simple. Share this post Link to post Share on other sites
gc8 977 Posted August 21, 2018 @Larpushka I added some comments to my code. Hope that clears it a bit 1 Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted August 21, 2018 On 8/19/2018 at 8:50 PM, Larpushka said: @Grumpy: Your example is nice but it's not "object-based" it's "owner based". That depends on how you implement to give individual players access to the locks of buildings. The snippet I linked to already has a variable for each player that's holding buildings they can lock/unlock. You can easily add your own way to handle addition/removal of keys, be it through addAction on a notebook, upon killing a certain unit, etc. Seeing how you want to do this via an item in players inventory this might not be possible in a reliable way, since there are no item IDs, you'd need to track which items are being picked up/dropped by a player, if a player has multiple items there's currently no way to track which one has been in the inventory, and which has recently been picked up. Would be easier to do with simulated items and setVariable/getVariable. Cheers Share this post Link to post Share on other sites
pierremgi 4897 Posted August 21, 2018 3 hours ago, Larpushka said: Yes pierre, I don't need to relock the door. And as far as a physical key item, it's fine. Any chance you can add commentary to your script? I can't follow the logic. Is "typename" the name I give the building? Why do I have to use configfile? seems a bit too fancy of a script for something so simple. Not my script, but @gc8 one. It works to unlock doors of a building. I just added a condition to make the addAction appears on the right building. Don't forget to place your game logic named mybuiding close to the building you want to close/open. You can improve the code by deleting the addAction when used or toggling some lock/unlock menu (useful in MP but not your case). You can find the commands usage on BIKI here. Be aware that most of the maps have specific houses/building, sometimes just landscape objects without any door (see Tanoa). Share this post Link to post Share on other sites