Actimel Posted April 1, 2017 Posted April 1, 2017 Can someone help me to bind key on this script for opening gates? code for command local opencommand = "open" --open command local closecommand = "close" --close command local GateObject = 980 --object local OpenTime = 3000 --opening second local rotX, rotY, rotZ = 0, 0, 270 --rotations local Defx, Defy, defz = -489.20001220703,-562.40002441406,27.299999237061 --closed position local opx, opy, opz = -489.20001220703,-562.40002441406,21.7 --opened position --create the gate (DO NOT EDIT) local ggate = createObject ( GateObject, Defx, Defy, defz, rotX, rotY, rotZ) --DO NOT EDIT function gateopen ( p ) if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(p)), aclGetGroup(ACL)) then moveObject (ggate, OpenTime, opx, opy, opz) outputChatBox("Admin base gate opened", p,0,255,0,true) else outputChatBox("Sorry you dont have permission to do that!", p,0,255,0,true) end end addCommandHandler( opencommand, gateopen) function gateclose ( p ) if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(p)), aclGetGroup(ACL)) then moveObject (ggate, OpenTime, Defx, Defy, defz) outputChatBox("Admin base gate closed", p,0,255,0,true) else outputChatBox("Sorry you dont have permission to do that!", p,0,255,0,true) end end addCommandHandler( closecommand, gateclose)
NeXuS™ Posted April 1, 2017 Posted April 1, 2017 function handlerFunction(thePlayer) local oX, oY, oZ = getElementPosition(ggate) if oZ ~= defz then gateclose(thePlayer) else gateopen(thePlayer) end end addEventHandler("onResourceStart," getResourceRootElement(), function() for i, k ipairs(getElementsByType("player")) do bindKey(k, "down", handlerFunction) end end) addEventHandler("onPlayerJoin", getRootElement(), function() bindKey(source, "down", handlerFunction) end) I think this one should work. 1
Actimel Posted April 1, 2017 Author Posted April 1, 2017 10 minutes ago, NeXuS™ said: function handlerFunction(thePlayer) local oX, oY, oZ = getElementPosition(ggate) if oZ ~= defz then gateclose(thePlayer) else gateopen(thePlayer) end end addEventHandler("onResourceStart," getResourceRootElement(), function() for i, k ipairs(getElementsByType("player")) do bindKey(k, "down", handlerFunction) end end) addEventHandler("onPlayerJoin", getRootElement(), function() bindKey(source, "down", handlerFunction) end) I think this one should work. doesnt work
NeXuS™ Posted April 1, 2017 Posted April 1, 2017 function handlerFunction(thePlayer) local oX, oY, oZ = getElementPosition(ggate) if oZ ~= defz then gateclose(thePlayer) else gateopen(thePlayer) end end addEventHandler("onResourceStart," getResourceRootElement(), function() for i, k ipairs(getElementsByType("player")) do bindKey(k, "K", "down", handlerFunction) end end) addEventHandler("onPlayerJoin", getRootElement(), function() bindKey(source, "K", "down", handlerFunction) end) bindKey arguments were :Oed.
Mr.Loki Posted April 1, 2017 Posted April 1, 2017 You can use /bind key command to bind a command to a key. /bind j open When I press j it will execute the open command it's better to use commandHandlers instead of bindKey because not all players would want to use the same key. Also instead of using 2 separate functions to open/close the gate just use 1 function so all you need is 1 command for example local opencommand = "gate" --toggle command local GateObject = 980 --object local OpenTime = 3000 --opening second local rotX, rotY, rotZ = 0, 0, 270 --rotations local x, y, z = -489.2,-562.4,27.299 --closed position local open --Var representing the state of the gate opened = true closed = false local ggate = createObject ( GateObject, x, y, z, rotX, rotY, rotZ) function toggleGate ( p ) if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(p)), aclGetGroup(ACL)) then if open then moveObject (ggate, OpenTime, x, y, z) else moveObject (ggate, OpenTime, x, y, z-5.5) end local state = not open and "opened." or "closed." -- check if gate opened and set the text to opened/closed outputChatBox("Admin base gate "..state, p,0,255,0,true) open = not open --toggle the open var between true/false else outputChatBox("Sorry, you dont have permission to do that!", p,0,255,0,true) end end addCommandHandler( opencommand, toggleGate)
Actimel Posted April 1, 2017 Author Posted April 1, 2017 4 minutes ago, Mr.Loki said: You can use /bind key command to bind a command to a key. /bind j open When I press j it will execute the open command it's better to use commandHandlers instead of bindKey because not all players would want to use the same key. Also instead of using 2 separate functions to open/close the gate just use 1 function so all you need is 1 command for example local opencommand = "gate" --toggle command local GateObject = 980 --object local OpenTime = 3000 --opening second local rotX, rotY, rotZ = 0, 0, 270 --rotations local x, y, z = -489.2,-562.4,27.299 --closed position local open --Var representing the state of the gate opened = true closed = false local ggate = createObject ( GateObject, x, y, z, rotX, rotY, rotZ) function toggleGate ( p ) if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(p)), aclGetGroup(ACL)) then if open then moveObject (ggate, OpenTime, x, y, z) else moveObject (ggate, OpenTime, x, y, z-5.5) end local state = not open and "opened." or "closed." -- check if gate opened and set the text to opened/closed outputChatBox("Admin base gate "..state, p,0,255,0,true) open = not open --toggle the open var between true/false else outputChatBox("Sorry, you dont have permission to do that!", p,0,255,0,true) end end addCommandHandler( opencommand, toggleGate) its not for other players i need. i need just for private base for example
Actimel Posted April 1, 2017 Author Posted April 1, 2017 1 minute ago, Mr.Loki said: You can still use it for a private base. yes i know but i want try to do on scipt not just bind in console ant thats it...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now