-Rex- Posted August 8, 2016 Posted August 8, 2016 Existe alguna forma de obtener las posiciones X, Y, Z de un objeto del GTA? Es decir por ejemplo, obtener las posiciones de todos los postes de luz del GTA ¿Se puede?
aka Blue Posted August 8, 2016 Posted August 8, 2016 function obtenerPosicion( modelID ) local modelID = tonumber( modelID ) if modelID then local tabla_objetos = getElementsByType( 'object' ) for i=1, #tabla_objetos do local objeto = tabla_objetos[ i ] if objeto == modelID then local x, y, z = getElementPosition( objeto ) local rx, ry, rz = getElementRotation( objeto ) outputChatBox( "Poste "..i..": Posicion: "..x..", "..y..", "..z.."." ) outputChatBox( "Poste "..i..": Rotacion: "..rx..", "..ry..", "..rz.."." ) end end end end
-Rex- Posted August 8, 2016 Author Posted August 8, 2016 function obtenerPosicion( modelID ) local modelID = tonumber( modelID ) if modelID then local tabla_objetos = getElementsByType( 'object' ) for i=1, #tabla_objetos do local objeto = tabla_objetos[ i ] if objeto == modelID then local x, y, z = getElementPosition( objeto ) local rx, ry, rz = getElementRotation( objeto ) outputChatBox( "Poste "..i..": Posicion: "..x..", "..y..", "..z.."." ) outputChatBox( "Poste "..i..": Rotacion: "..rx..", "..ry..", "..rz.."." ) end end end end Ese codigo ni siquiera imprimio algo en el chat. Ya lo había hecho de esta forma: for i, v in ipairs( getElementsByType("object") ) do if getElementModel( v ) == 1211 then local x, y, z = getElementPosition( v ) outputChatBox( "Grifo: "..x..", "..y..", "..z) end end Pero solo obtiene los que han sido creados por createObject
RekZ Posted August 9, 2016 Posted August 9, 2016 con eso engloba a todos los objetos tantos los creados por lua como los creados por un .map getElementsByType ( "object" ) el Ejemplo anterior no te dio mensaje porque no tiene evento ponle algun evento y ya function obtenerPosicion( command , modelID ) local modelID = tonumber( modelID ) if modelID then local tabla_objetos = getElementsByType( 'object' ) for i=1, #tabla_objetos do local objeto = tabla_objetos[ i ] if objeto == modelID then local x, y, z = getElementPosition( objeto ) local rx, ry, rz = getElementRotation( objeto ) outputChatBox( "Poste "..i..": Posicion: "..x..", "..y..", "..z.."." ) outputChatBox( "Poste "..i..": Rotacion: "..rx..", "..ry..", "..rz.."." ) end end end end addCommandHandler("quierolapos",obtenerPosicion)
Recommended Posts