adanteh 58 Posted August 28, 2013 tl;dr - is there a dynamic way to retrieve all doors of building X and lock the doors + add something next to it. I want to add keypads to all doors of random buildings (Not predefined. I want to be able to add a marker in the mission and the script takes care of the rest), lock all the doors and every keypad next to the door unlocks the corresponding door. I guess if you could do something like this _building = NearestObject [lockMarker, "House_F"]; _count = [b][color="#FF0000"]countDoors[/color][/b] _building for "_i" from 0 to _count do { _building setVariable ['[color="#FF0000"][b]bis_disabled_Door_i[/b][/color], 1, true]; [color="#FF0000"][b]keypad_i [/b][/color] = "SurvivalRadio_F" createVehicle (getPos _building); [color="#FF0000"][b]keypad_i[/b][/color] attachTo [_building, [-1, 0, 0], [color="#FF0000"][b]"door_i_trigger"[/b][/color]]; [b][color="#FF0000"]keypad_i [/color][/b]addAction ["Enter code", "keypadscript.sqf", _i]; }; where the bis_disabled_Door_i is basically a variable that gets adjusted in every for loop and countDoors counts all the doors on a building. Is adding a number to a variable even possible? Like defining a new variable out of formatting a base name (varName) and adding _x at the end, so I get varName_1, varName_2, etc. I'd love to know this. Share this post Link to post Share on other sites
das attorney 858 Posted August 28, 2013 Yes you can do that. Check this informative post by Kylania: http://forums.bistudio.com/showthread.php?153100-Enemy-occupation-system-(eos)&p=2480054&viewfull=1#post2480054 Share this post Link to post Share on other sites
adanteh 58 Posted August 28, 2013 (edited) Looks like I fail. It's working now. I'm not even sure what I changed, but I managed to attach the radios to every single door now. Ignore everything below the line! I'd still very much like to know how to get the amount of doors a building has from the config though Thanks a lot man. I never realized I could just use strings for that. I used format a ton, but didn't realize I could actually use it to format a variable name as well. Now I just need to figure out how to get the placing of the attachTo correctly. I'd like the items to be left of the door handle, but when there's a door at the other side the item gets offsetted in the wrong direction. Suggestions how I would go about this? I can't for the life of me figure out how to use modelToWorld and so. It seems to work fine for locking all the doors, because a string is used in the actual command there, but I can't create the items from what I'm guessing is because I'm basically saying "randomstringtext" = "Item_F" createVehicle blablabla; "randomstringtext" attachTo blablabla; In Kylania's example it's also solely used as a string. I don't understand it all perfectly, but I'm guessing you can't use a string as the name for an object? That was my initial problem. It works perfectly when the dynamic name has to be used as a string, but I can't figure out how to use it when it needs to be an actual variable as opposed to a string. private ["_building", "_count"]; _building = nearestObject [lockMarker, "House_F"]; _count = 8; for "_i" from 0 to _count do { _lockVar = format ["bis_disabled_Door_%1", _i]; _keyVar = format ["keypad_%1", _i]; _doorVar = format ["door_%1_trigger", _i]; _building setVariable [_lockVar, 1, true]; _keyVar = "Land_SurvivalRadio_F" createVehicle (getPos _building); _keyVar attachTo [_building, [-1, -1, 0], _doorVar]; _keyVar addAction ["Enter code", "kpw_use.sqf", _i]; _keyVar setVariable ["lock_pw", "12345", true]; }; That's the code I have right now. I testing it on a military office, that's why _count = 8;, seeing I don't yet know how to get the number of doors from the config. Edited August 28, 2013 by Adanteh Share this post Link to post Share on other sites
kylania 568 Posted August 28, 2013 (edited) In your example you don't need actual object names, the keypad_i stuff, local variables would be fine _keypad for all of them. Just make sure you put _keyVar instead of just _i in the addAction. _keyVar addAction ["Enter code", "kpw_use.sqf", [color="#FF0000"]_keyVar[/color]]; You could count the useractions or animation sources for a building, but I'm not seeing any number that lists how many they have. There's is some more advanced options like scanning the models for memory points, but that's a bit excessive :) private ["_building", "_count"]; _building = nearestObject [lockMarker, "House_F"]; _count = 8; for "_i" from 0 to _count do { _building setVariable [format["bis_disabled_Door_%1", _i], 1, true]; _keyVar = "Land_SurvivalRadio_F" createVehicle (getPos _building); _keyVar attachTo [_building, [-1, -1, 0], format ["door_%1_trigger", _i]]; // This assumes you don't need to refer to keypad_1 since the addAction would already know // what object it's attached to. _keyVar addAction ["Enter code", "kpw_use.sqf", _i]; // _i is passed as (_this select 3) to the kpw_use.sqf _keyVar setVariable ["lock_pw", "12345", true]; }; Edited August 28, 2013 by kylania Share this post Link to post Share on other sites
adanteh 58 Posted August 28, 2013 Why are you sending _keyVar as an argument for the addAction? Also, this is my kpw_use.sqf script private ["_i", "_building"]; _i = ((_this select 3) select 1); hint format ["Trying to open door #%1", _i]; _building = nearestObject [(_this select 0), "House_F"]; if (((_this select 1) getVariable "lock_pw") == ((_this select 0) getVariable "lock_pw")) then { _building setVariable [format["bis_disabled_Door_%1", _i], 0, true]; _building animate [format["door_%1_rot", _i], 1]; hint format ["Door #%1 Opening", _i]; sleep 4.0; _building animate [format["door_%1_rot", _i], 0]; _building setVariable [format["bis_disabled_Door_%1", _i], 1, true]; }; Now for some weird reason door number 1, 3, 5 and 6 don't open. When I type in testBuilding animate ["door_3_rot", 1]; they animate normally though. In the hint I get it also says door #3 just fine, so the script know's it's the correct door.. Yet for some reason it doesn't open? Share this post Link to post Share on other sites
kylania 568 Posted August 28, 2013 Oh, I see, yeah, ignore that. Thought you were trying to send the object of the keypad. _i would be fine. I have no idea how your hint is working. You're sending it _i as (_this select 3) to your addAction script. So trying to select 1 from that (a number, not an array) shouldn't work, even if it was an array. Can you repost all your code as you have it please? Share this post Link to post Share on other sites
adanteh 58 Posted August 28, 2013 (edited) I just did ((_this select 3) select 1), because I made an array of the arguments. Select 0 being the _keyVar which might've been there for a magical reason I didn't understand at all and Select 1 being _i. I changed it back now to how I had it before, removing _keyVar. _i is send so I know which door I'm trying to open. This is kpw_all.sqf, which is called by a game logic called lockMarker on init. lockMarker is placed near the building I'm testing on. (In actual use I guess I can create game logics near buildings that I want to be able to lock). private ["_building", "_count"]; _building = nearestObject [lockMarker, "House_F"]; _count = 8; for "_i" from 1 to _count do { _building setVariable [format["bis_disabled_Door_%1", _i], 1, true]; _keyVar = "Land_Laptop_Unfolded_F" createVehicle (getPos _building); _keyVar attachTo [_building, [0, 0, 0], format ["door_%1_trigger", _i]]; _keyVar addAction ["Enter code", "kpw_use.sqf", _i]; _keyVar setVariable ["lock_pw", "12345", true]; }; This is kpw_use.sqf, which is called by all the addactions on in this case the Laptops in the door (Took that as temporary thing so I can actually open the doors from the inside again... :D) private ["_i", "_building"]; _i = (_this select 3); hint format ["Trying to open door #%1", _i]; _building = nearestObject [(_this select 0), "House_F"]; if (((_this select 1) getVariable "lock_pw") == ((_this select 0) getVariable "lock_pw")) then { _building setVariable [format["bis_disabled_Door_%1", _i], 0, true]; sleep 0.01; _building animate [format["door_%1_rot", _i], 1]; hint format ["Door #%1 Opening", _i]; sleep 4.0; _building animate [format["door_%1_rot", _i], 0]; sleep 0.01; _building setVariable [format["bis_disabled_Door_%1", _i], 1, true]; }; The variable lock_pw is just used a temporary thing. There's a notepad next to one of the doors, with an action on it that gives you the password (And adds that variable to the player). That's really all there is right now. I would prefer being able to open the doors from the inside without the use of a password, but I doubt this is possible. Edit: Here's a link, to the mission right now: http://cl.ly/1u203a2m2K3T (You have to read the note at the door to be able to open them) Also how the hell can I place the future keypad to the left of the door? I checked out worldToModel and so, but can't use that properly either. What I need is that the offset towards Door_x_trigger is always towards the same direction, based on the orientation of the door. Outside of the door is pointing north? Place the keypad 1 meter east. Door is pointing south? Place the keypad 1 meter west. Edited August 28, 2013 by Adanteh Share this post Link to post Share on other sites
adanteh 58 Posted August 28, 2013 More info time: I figured out why the other doors wouldn't work! _building = nearestObject [(_this select 0), "House_F"]; That part? Well, the nearestObject falling under House_F, looking from those leftover doors wasn't the building that I was trying to interact with.. It was a barrier right next to it. Fixed it by using this instead _building = nearestObject [lockMarker, "House_F"]; Share this post Link to post Share on other sites
vake 10 Posted September 26, 2013 Hey Adanteh, this looks very promising. I have looked for your demo mission, but every link posted either in this thread or others you have posted it on are all unavailable. Can you post the mission again? Or if it's easier, I have the sqf files ready to go but am not sure how to attach the laptop/other object to the doors, and also what needs to go into the gamelogic in the editor to make this work. If you could share that info instead I'd appreciate it. I'm interested in making a mission where players are able to lock doors to their own homes/apartment rooms and think this would work great. Just testing the waters to see what is and isn't possible. Thank you for sharing your work! Share this post Link to post Share on other sites
adanteh 58 Posted September 27, 2013 Hey man, here it is: http://cl.ly/130K2g0U231h That case next to the door of the office building is what I had as plan to use for the computer. You can use that to create locks and reset the password as well. There's also an option to use a keypad. All it does now is add a variable to the player (with the current password) and if the player has that variable instead of asking for a password it opens the door with a slight delay. Seeing I don't really have a purpose for it right now I stopped working on it. The way I'm adding things right now isn't really suited for saving (with iniDB or so) and multiplayer though I'm guessing. Share this post Link to post Share on other sites
vake 10 Posted September 27, 2013 Thank you for sharing, Adanteh. This works great! I wonder if there is a dynamic way to add this function to every building (or maybe the same building type), yet have it so a keycard for one building wouldn't work on another building's doors? Share this post Link to post Share on other sites
adanteh 58 Posted September 27, 2013 Well when you grab a keycard it should create a keycard with the password for the security computer. So if you grab the keycard from Building A's computer it will only work on Building A (Or well on all buildings that use the same password). Adding it easily to different buildings is still something I needed to work on though. I wanted to set it up in such a way you can easily save it with iniDB so it's actually useful for Altis Life/Wasteland scenarios (Which always should save gear in my eyes). I guess you can write a script which adds a marker to every building you want and then create another script that adds the keypad to every building near those markers. I figured using the markers would make sense because it's something you can easily save to the database. Then you only have to make sure that once the server boots again you readd the markers and after that and then execute the script that adds keypads to every building near a marker. You shouldn't forget to save the passwords (Which is a variable added to the building, but maybe could be switched over to the marker as well). That will only work for building-wide passwords though Edit: Also if you figure out some of this I'd love if it you posted it back in this thread. I really wouldn't mind seeing more people further expanding on scripts and then adding it all together. It's such a shame to see a lot of people take a basic thing and then adding one or two things themselves..Letting you end up with everyone having their own script doing one thing pretty decent, but none of them actually having all the 'features'. Share this post Link to post Share on other sites
vake 10 Posted September 27, 2013 An RP style mission is exactly what I would like to use this in! I've spent a lot of time on life/RP servers since discovering Sahrani Life some 6 years ago and would love to work on my own iteration of these types of missions. I just recently decided to dive in and rent a dedicated server, and would love to figure out how to implement something like this into a mission and have it be included in a persistent db stat-save system. I think that the ability to purchase homes/apartments/commercial buildings and be able to limit who has access to those buildings by way of keys/keycards would really add to the RP experience. Having said that, I am still a noob at scripting and haven't wrapped my head around creating, managing and storing variables like keys, money, and other items like wood, wheat and meat that are needed for RP missions. As much as I'd love to fire up a mission for players tomorrow that has everything in place, the reality is I will need to do a lot of tinkering on the server by myself (or maybe with a small group of interested developers/testers), likely for a long time before my ideas would come to fruition. Right now I'd say chances are slim to nil, but if somehow I do happen to stumble upon something useful during my testing I will be sure to share it with the community! Share this post Link to post Share on other sites