toxicsmoke11 Posted July 21, 2014 Share Posted July 21, 2014 hi im trying to open/close gate with just one command,i dont want 2 different commands but this doesnt work function createTheGate1 () myGate1 = createObject ( 7657, 2522.2001953125, -1278, 35.5 ) end addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), createTheGate1 ) function openMyGate1 (thePlayer) local playerTeam = getPlayerTeam(thePlayer) local teamName = getTeamName(playerTeam) if (teamName) then if (teamName) == "Test" then moveObject ( myGate1, 3000, 2522.1999511719, -1278, 38.900001525879 ) setElementData(myGate1,"gate.state",1) outputChatBox("Gate has been opened!",thePlayer,0,255,0,true) elseif getElementData(myGate1,"gate.state" == 1) then moveObject ( myGate1, 3000,2522.2001953125, -1278, 35.5 ) setElementData(myGate1,"gate.state",0) outputChatBox("Gate has been closed!",thePlayer,255,0,0,true) else outputChatBox("You don't have access to open the gate!",thePlayer,255,0,0,true) end end end addCommandHandler("base",openMyGate1) nodebugscript3 errors please help Link to comment
Et-win Posted July 21, 2014 Share Posted July 21, 2014 Are you in a team and has this team the name "Test"? Otherwise does it output anything in the chatbox? Link to comment
toxicsmoke11 Posted July 21, 2014 Author Share Posted July 21, 2014 yeah im in that team and it always outputs gate has been opened but doesnt output anything else Link to comment
Bonsai Posted July 21, 2014 Share Posted July 21, 2014 As far as I can see the elseif in line 14 belongs to if (teamName) == "Test" then . So how could it work like this. Link to comment
toxicsmoke11 Posted July 21, 2014 Author Share Posted July 21, 2014 As far as I can see the elseif in line 14 belongs to if (teamName) == "Test" then .So how could it work like this. so i need to replace 'elseif' with 'else' and have 2 elses in my script? i really dont know what i need to do now to make this working,i understand what u said but i still dont know how to make this work Link to comment
Bonsai Posted July 21, 2014 Share Posted July 21, 2014 Your script checks if the players is in the right team and then just opens the gate without checking the gates state. So after you check for the team you need to put another if and check for the state. If the players is not in the right team, thats your elseif, it checks if the state is == 1 and moves it again. Link to comment
Et-win Posted July 21, 2014 Share Posted July 21, 2014 Also: elseif getElementData(myGate1,"gate.state" == 1) then Change to: elseif getElementData(myGate1,"gate.state") == 1 then Link to comment
toxicsmoke11 Posted July 21, 2014 Author Share Posted July 21, 2014 okay umm so i changed some things but im stuck at one part i changed when i create the gate in first function it sets element data to 0 since its closed on start but then i do that check if element data is 0 then open it and set element data to 1 ==stuck here== i cant use 'elseif' because its checking the team,not gate state so what do i use if element data is actually 1 when someone uses the command? Link to comment
Bonsai Posted July 21, 2014 Share Posted July 21, 2014 Try something like this: Just the structure, might have errors. if (teamName) == "Test" then if getElementData(myGate1,"gate.state") == 0 then moveObject ( myGate1, 3000, 2522.1999511719, -1278, 38.900001525879 ) setElementData(myGate1,"gate.state",1) outputChatBox("Gate has been opened!",thePlayer,0,255,0,true) elseif getElementData(myGate1,"gate.state") == 1 then moveObject ( myGate1, 3000,2522.2001953125, -1278, 35.5 ) setElementData(myGate1,"gate.state",0) outputChatBox("Gate has been closed!",thePlayer,255,0,0,true) end else outputChatBox("You don't have access to open the gate!",thePlayer,255,0,0,true) end Link to comment
toxicsmoke11 Posted July 21, 2014 Author Share Posted July 21, 2014 edit: it works thanks Link to comment
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