lJames Posted March 25, 2013 Posted March 25, 2013 (edited) Hi, i'm new and very noob in all this scripting thing, but I want to learn, at least, basic things. I tried to create myself a script to open/close a gate, which is the following. puerta = createObject (971, -2136.599609375, 208.599609375, 38, 0, 0, 270) function abrirPuerta(player) moveObject (puerta, 5000, -2136.6000976563, 208.60000610352, 29) end addCommandHandler ("james", abrirPuerta) function cerrarPuerta(player) moveObject (puerta, 5000, -2136.599609375, 208.599609375, 38) end addCommandHandler ("james2", cerrarPuerta) I know it's very very simple, but it's the best I can do. The thing is, I want to make that door open and close with the same command. I think I have to use an if, but I'm not sure how to do it. If someone could help me, I'd appreciate it.[/i] Edited March 25, 2013 by Guest
golanu21 Posted March 25, 2013 Posted March 25, 2013 and ? , what is your problem ? [Dev]BloWnRPG - We BloW the World [1%]
EstrategiaGTA Posted March 25, 2013 Posted March 25, 2013 For put it with "colors and all stuff", as you said, put it with the LUA Tag, not Code =)
lJames Posted March 25, 2013 Author Posted March 25, 2013 The thing is, I want to make that door open and close with the same command. I think I have to use an if, but I'm not sure how to do it. I've said it.
xXMADEXx Posted March 25, 2013 Posted March 25, 2013 (edited) Try this: puerta = createObject (971, -2136.599609375, 208.599609375, 38, 0, 0, 270) function abrirPuerta(player) moveObject (puerta, 5000, -2136.6000976563, 208.60000610352, 29) setTimer( function () moveObject(puerta, 5000, -2136.599609375, 208.599609375, 38) end, 3500, 1 ) end addCommandHandler ("james", abrirPuerta) Edited March 25, 2013 by Guest The Ultimate Lua Tutorial! | MTA PHP SDK
golanu21 Posted March 25, 2013 Posted March 25, 2013 The thing is, I want to make that door open and close with the same command. I think I have to use an if, but I'm not sure how to do it. I've said it. sorry, you need to use a setTimer [Dev]BloWnRPG - We BloW the World [1%]
lJames Posted March 25, 2013 Author Posted March 25, 2013 For put it with "colors and all stuff", as you said, put it with the LUA Tag, not Code =) I've edited it. ¡Thanks!
EstrategiaGTA Posted March 25, 2013 Posted March 25, 2013 Try this: puerta = createObject (971, -2136.599609375, 208.599609375, 38, 0, 0, 270) function abrirPuerta(player) moveObject (puerta, 5000, -2136.6000976563, 208.60000610352, 29) setTimer( function () moveObjct(puerta, 5000, -2136.599609375, 208.599609375, 38) end, 3500, 1 ) end addCommandHandler ("james", abrirPuerta) Your code is wrong. Line 6, "moveObjct"?
golanu21 Posted March 25, 2013 Posted March 25, 2013 Try this: puerta = createObject (971, -2136.599609375, 208.599609375, 38, 0, 0, 270) function abrirPuerta(player) moveObject (puerta, 5000, -2136.6000976563, 208.60000610352, 29) setTimer( function () moveObjct(puerta, 5000, -2136.599609375, 208.599609375, 38) end, 3500, 1 ) end addCommandHandler ("james", abrirPuerta) Your code is wrong. Line 6, "moveObjct"? yea .. LOL [Dev]BloWnRPG - We BloW the World [1%]
lJames Posted March 25, 2013 Author Posted March 25, 2013 It worked, thanks. There's a way I can write /james, the door moves, and then, whenever I want, /james again so the gate closes?
DNL291 Posted March 25, 2013 Posted March 25, 2013 Try this: local open = false addCommandHandler("james", function() if not open then moveObject(puerta, 5000, -2136.6000976563, 208.60000610352, 29) open = true elseif open then moveObject(puerta, 5000, -2136.599609375, 208.599609375, 38) end end ) Please do not PM me with scripting related question nor support, use the forums instead.
xXMADEXx Posted March 25, 2013 Posted March 25, 2013 Try this: puerta = createObject (971, -2136.599609375, 208.599609375, 38, 0, 0, 270) function abrirPuerta(player) moveObject (puerta, 5000, -2136.6000976563, 208.60000610352, 29) setTimer( function () moveObjct(puerta, 5000, -2136.599609375, 208.599609375, 38) end, 3500, 1 ) end addCommandHandler ("james", abrirPuerta) Your code is wrong. Line 6, "moveObjct"? lmao, fail The Ultimate Lua Tutorial! | MTA PHP SDK
lJames Posted March 26, 2013 Author Posted March 26, 2013 Try this: local open = false addCommandHandler("james", function() if not open then moveObject(puerta, 5000, -2136.6000976563, 208.60000610352, 29) open = true elseif open then moveObject(puerta, 5000, -2136.599609375, 208.599609375, 38) end end ) I edited some things, and it worked. ¡Thanks! I leave here the definitive script, so someone who wants the same thing can obtain it. puerta = createObject (971, -2136.599609375, 208.599609375, 37.898998260498, 0, 0, 270) local open = false function movePuerta (player) if not open then moveObject(puerta, 5000, -2136.6000976563, 208.60000610352, 29) open = true else if open then moveObject(puerta, 5000, -2136.599609375, 208.599609375, 37.898998260498) end end end addCommandHandler("james", movePuerta)
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