LANS Posted September 21, 2014 Share Posted September 21, 2014 hola hice este script para abrir y cerrar una puerta con un solo comando, pero solo abre y no vuelve a cerrar al poner el comando nuevamente puerta = createObject (3115, -2183.6943359375, 608.4990234375, 58.674999237061) function puerta1 () local x, y, z = getElementPosition (puerta) if y == 608.4990234375 then moveObject (puerta, 1000, -2183.6943359375, 626.99597167969, 58.674999237061) ---abrir elseif y == 626.99597167969 then moveObject (puerta, 1000, -2183.6943359375, 608.4990234375, 58.674999237061) --cerrar end end addCommandHandler("abrir", puerta1) cualquier ayuda se agradece Saludos Link to comment
Alexs Posted September 21, 2014 Share Posted September 21, 2014 (edited) Prueba con esto: puerta = createObject (3115, -2183.6943359375, 608.4990234375, 58.674999237061) open = false function puerta1 () if not open then moveObject (puerta, 1000, -2183.6943359375, 626.99597167969, 58.674999237061) open = true elseif open then moveObject (puerta, 1000, -2183.6943359375, 608.4990234375, 58.674999237061) open = false end end addCommandHandler("abrir", puerta1) * No aseguro que funcione, pues hace tiempo que no escribo algún código. Edited September 21, 2014 by Guest Link to comment
Tomas Posted September 21, 2014 Share Posted September 21, 2014 Prueba con esto: puerta = createObject (3115, -2183.6943359375, 608.4990234375, 58.674999237061) open = false function puerta1 () local x, y, z = getElementPosition (puerta) if not open then moveObject (puerta, 1000, -2183.6943359375, 626.99597167969, 58.674999237061) open = true elseif open then moveObject (puerta, 1000, -2183.6943359375, 608.4990234375, 58.674999237061) open = false end end addCommandHandler("abrir", puerta1) * No aseguro que funcione, pues hace tiempo que no escribo algún código. ¿Para qué: local x, y, z = getElementPosition (puerta) ? Si no lo usas en ningún momento? Link to comment
Alexs Posted September 21, 2014 Share Posted September 21, 2014 ¿Para qué: local x, y, z = getElementPosition (puerta) ? Si no lo usas en ningún momento? No veo el problema, quizá no utilice las variables, pero su definición no afecta el rendimiento del recurso ni da problemas en su funcionamiento. Link to comment
Tomas Posted September 21, 2014 Share Posted September 21, 2014 Pero para qué detectar la posición si no se va a usar en ningún momento? Y al rendimiento obviamente lo afectará, quizás ni se note pero como a usted le encanta ver el 'rendimiento' de todas las cosas, pues eso afectaría. Link to comment
alex17 Posted September 21, 2014 Share Posted September 21, 2014 Mejore un poco lo que hiso @Alexs_Steel ademas le agrege un mensaje cuando abras o cierres la puerta ya lo prove y funciona puerta = createObject (3115, -2183.6943359375, 608.4990234375, 58.674999237061) open = false function puerta1 (thePlayer) if open == false then moveObject (puerta, 1000, -2183.6943359375, 626.99597167969, 58.674999237061) open = true outputChatBox ("#00ff00 Abriendo Puerta", thePlayer, 255, 255, 255, true ) elseif open == true then moveObject (puerta, 1000, -2183.6943359375, 608.4990234375, 58.674999237061) open = false outputChatBox ("#ff0000 Cerrando Puerta", thePlayer, 255, 255, 255, true ) end end addCommandHandler("abrir", puerta1) Link to comment
Alexs Posted September 21, 2014 Share Posted September 21, 2014 Mejore un poco lo que hiso @Alexs_Steel ademas le agrege un mensaje cuando abras o cierres la puerta ya lo prove y funciona Solo como comentario, espero no lo tomes como ofensa, te recomiendo mantener la forma de mis condicionales, es tautológico realizar en ellas una comprobación entre dos variables de tipo boolean. puerta = createObject (3115, -2183.6943359375, 608.4990234375, 58.674999237061) open = false function puerta1 (thePlayer) if not open then moveObject (puerta, 1000, -2183.6943359375, 626.99597167969, 58.674999237061) open = true outputChatBox ("#00ff00 Abriendo Puerta", thePlayer, 255, 255, 255, true ) elseif open then moveObject (puerta, 1000, -2183.6943359375, 608.4990234375, 58.674999237061) open = false outputChatBox ("#ff0000 Cerrando Puerta", thePlayer, 255, 255, 255, true ) end end addCommandHandler("abrir", puerta1) Link to comment
alex17 Posted September 21, 2014 Share Posted September 21, 2014 no hay problema lo tendre en cuenta para la proxima Link to comment
LANS Posted September 22, 2014 Author Share Posted September 22, 2014 muchas gracias por la solucion Link to comment
Recommended Posts