NIKO_19997 Posted April 11, 2015 Share Posted April 11, 2015 hola, como puedo hacer que cuando vuelva a poner el comando /muro se desaparesca el objeto? lo unico que creo que me puede server es la funcion destroyElement, aqui el script: function tankHat ( source, commandName ) local x, y, z = getElementPosition ( source ) local tank = createObject ( 10828, x, y, z+5 ) attachElements ( tank, source, 0, 10, -2 ) setElementCollisionsEnabled (tank, true) else destroyElement (tank, true) end end addCommandHandler ( "muro", tankHat ) Saludos y espero me puedan ayudar! Link to comment
alex17 Posted April 11, 2015 Share Posted April 11, 2015 function tankHat ( source, commandName ) if tank then destroyElement (tank) else local x, y, z = getElementPosition ( source ) tank = createObject ( 10828, x, y, z+5 ) attachElements ( tank, source, 0, 10, -2 ) setElementCollisionsEnabled (tank, true) end end addCommandHandler ( "muro", tankHat ) Link to comment
NIKO_19997 Posted April 12, 2015 Author Share Posted April 12, 2015 function tankHat ( source, commandName ) if tank then destroyElement (tank) else local x, y, z = getElementPosition ( source ) tank = createObject ( 10828, x, y, z+5 ) attachElements ( tank, source, 0, 10, -2 ) setElementCollisionsEnabled (tank, true) end end addCommandHandler ( "muro", tankHat ) funciona, pero al sacarlo y intentar ponerlo denuevo no lo vuelve a poner Link to comment
Castillo Posted April 12, 2015 Share Posted April 12, 2015 Eso es porque la variable 'tank' sigue teniendo un valor, cambia el: if tank then a: if isElement ( tank ) then Y tambien deberias poner la variable 'tank' en el valor 'nil', asi: destroyElement ( tank ) tank = nil Link to comment
NIKO_19997 Posted April 12, 2015 Author Share Posted April 12, 2015 Funciona perfecto!! Muchas gracias a ambos Link to comment
Recommended Posts