Arsilex Posted August 29, 2012 Posted August 29, 2012 addCommandHandler( "nearbycars", function( player, commandName ) if hasObjectPermissionTo( player, "command.kick", false ) or hasObjectPermissionTo( player, "command.deletecar", false ) then local x, y, z = getElementPosition( player ) local dimension = getElementDimension( player ) local interior = getElementInterior( player ) local vehicles = getElementInterior( player ) outputChatBox( "Nearby Coches:", player, 255, 255, 0 ) for key, value in pairs( vehicles ) do if isElement( key ) and getElementDimension( key ) == dimension and getElementVehicle( key ) == interior then local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( key ) ) if distance < 20 then outputChatBox( " Coche " .. value .. " - Type: " .. tostring( vehicles ) .. ".", player, 255, 255, 0 ) end end end end end ) Tengo este script pero no me dice el ID de los coches cercano como lo ago funcionar
Renkon Posted August 29, 2012 Posted August 29, 2012 local vehicles = getElementInterior( player ) local vehicles = getElementsByType("vehicle")
Alexs Posted August 29, 2012 Posted August 29, 2012 addCommandHandler( "nearbycars", function( player, commandName ) if hasObjectPermissionTo( player, "command.kick", false ) or hasObjectPermissionTo( player, "command.deletecar", false ) then local x, y, z = getElementPosition( player ) local dimension = getElementDimension( player ) local interior = getElementInterior( player ) local vehicles = getElementsByType("vehicle") outputChatBox( "Nearby Coches:", player, 255, 255, 0 ) for key, value in pairs( vehicles ) do if isElement( key ) and getElementDimension( key ) == dimension and getElementVehicle( key ) == interior then local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( key ) ) if distance < 20 then outputChatBox( " Coche " .. value .. " - Type: " .. tostring( vehicles ) .. ".", player, 255, 255, 0 ) end end end end end )
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 No me sale solo sale Nearby Coches: nada mas
Renkon Posted August 29, 2012 Posted August 29, 2012 Revisa esto if isElement( key ) and getElementDimension( key ) == dimension and getElementVehicle( key ) == interior then local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( key ) ) y pon if isElement( value ) and getElementDimension( value ) == dimension and getElementVehicle( value ) == interior then local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( value ) )
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 me sale ERROR: vehicles/vehicles.lua:756: attempt to call global 'getElementVehicle' (a nil value)
Alexs Posted August 29, 2012 Posted August 29, 2012 me sale ERROR: vehicles/vehicles.lua:756: attempt to call global 'getElementVehicle' (a nil value) No existe la función "getElementVehicle".
Renkon Posted August 29, 2012 Posted August 29, 2012 outputChatBox( " Coche " .. value .. " - Type: " .. tostring( vehicles ) .. ".", player, 255, 255, 0 ) cambia por outputChatBox( " Coche " .. value .. " - Type: " .. tostring( getElementModel (value) ) .. ".", player, 255, 255, 0 ) y tambien, getElementVehicle no existe... es getElementsByType("vehicle")
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 me sale ahora esto attempt to concatenate local 'value' (a userdata value)
Alexs Posted August 29, 2012 Posted August 29, 2012 pues, value son los vehiculos, no un string, que quieres que aparezca ahi?
Renkon Posted August 29, 2012 Posted August 29, 2012 outputChatBox( " Coche " .. value .. " - Type: " .. tostring( vehicles ) .. ".", player, 255, 255, 0 ) por outputChatBox( " Coche " .. getElementModel(value) .. ".", player, 255, 255, 0 )
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 grax por la ayuda pero tengo otra duda añadi esto y no funciona ahora addCommandHandler( "nearbycars", function( player, commandName ) if hasObjectPermissionTo( player, "command.kick", false ) or hasObjectPermissionTo( player, "command.deletecar", false ) then local x, y, z = getElementPosition( player ) local dimension = getElementDimension( player ) local interior = getElementInterior( player ) local vehicles = getElementsByType( "vehicle" ) outputChatBox( "Nearby Coches:", player, 255, 255, 0 ) for key, value in pairs( vehicles ) do local vehicleID = vehicles[ vehicle ] and vehicles[ vehicle ].vehicleID if vehicleID then local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( value ) ) if distance < 20 then outputChatBox( " Coche " .. getElementModel(value) .. "ID".. vehicleID.. ".", player, 255, 255, 0 ) end end end end end ) Ningun error pero no sale el chat
Renkon Posted August 29, 2012 Posted August 29, 2012 outputChatBox( " Coche " .. getElementModel(value) .. "ID".. vehicleID.. ".", player, 255, 255, 0 ) por outputChatBox( " Coche " .. getElementModel(value) .. "ID".. vehicleID.. ".", getRootElement(), 255, 255, 0 )
Renkon Posted August 29, 2012 Posted August 29, 2012 Puedes optar por local vehicleID = vehicles[ vehicle ] and vehicles[ vehicle ].vehicleID a local vehicleID = vehicles[ value ] and vehicles[ value ].vehicleID o simplemente... outputChatBox( " Coche " .. getElementModel(value) .. "ID".. vehicleID.. ".", player, 255, 255, 0 ) por... outputChatBox( " Coche " .. getElementModel(value) .. ".", getRootElement(), 255, 255, 0 ) ¿Para qué quieres el vehicle ID?
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 Nada sigue igual para que me diga el ID de mi coche es que en mi server es mysql y para borrar o abrir coches con admin tienes que saber el ID del coche
Renkon Posted August 29, 2012 Posted August 29, 2012 Nada sigue igual para que me diga el ID de mi coche es que en mi server es mysql y para borrar o abrir coches con admin tienes que saber el ID del coche Revisa que edité para que modifiques algo local vehicleID = vehicles[ vehicle ] and vehicles[ vehicle ].vehicleID a local vehicleID = vehicles[ value ] and vehicles[ value ].vehicleID
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 no no funciona puse addCommandHandler( "nearbycars", function( player, commandName ) if hasObjectPermissionTo( player, "command.kick", false ) or hasObjectPermissionTo( player, "command.deletecar", false ) then local x, y, z = getElementPosition( player ) local dimension = getElementDimension( player ) local interior = getElementInterior( player ) local vehicles = getElementsByType( "vehicle" ) outputChatBox( "Nearby Coches:", player, 255, 255, 0 ) for key, value in pairs( vehicles ) do local vehicleID = vehicles[ value ] and vehicles[ value ].vehicleID if vehicleID then local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( value ) ) if distance < 20 then outputChatBox( " Coche " .. getElementModel(value) .. "ID".. vehicleID.. ".", player, 255, 255, 0 ) end end end end end )
Renkon Posted August 29, 2012 Posted August 29, 2012 Revisa el DebugScript. Si nada sale quiere decir que el error se halla aquí: local vehicleID = vehicles[ value ] and vehicles[ value ].vehicleID Además, claro que no funcionará. Te retorna únicamente los vehicles. No creas que los vehicles a su vez son tablas con distintos atributos!. Hazme caso y bórralo al menos por ahora o dejalo en comentarios
Renkon Posted August 29, 2012 Posted August 29, 2012 Prueba suprimiendo eso momentáneamente y sacando la muestra de la variable en el outputChatBox. Y dime si funciona así. me quedaría tranquilo
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 si sin eso si funciona sale el nombre y el modelo
Renkon Posted August 29, 2012 Posted August 29, 2012 En fin, como te digo. No funcionará de esa forma. La única será usando un setElementData para el ID,o algo así. Porque desde ya es erróneo. Si bien el vector vehicles posee todos los vehículos. Este, asi mismo, no es otro vector (sería bidimensional). Si no que simplemente, el vehicle puedes conseguir los datos con determinadas funciones. Lo mejor será, o usar setElementData, o ayudarte con la BD
Arsilex Posted August 29, 2012 Author Posted August 29, 2012 mira tengo estoo addCommandHandler( { "vehicleid", "thisvehicle" }, function( player, commandName ) local vehicle = getPedOccupiedVehicle( player ) if vehicle then local vehicleID = vehicles[ vehicle ] and vehicles[ vehicle ].vehicleID if vehicleID then outputChatBox( "El ID de este " .. getVehicleName( vehicle ) .. " is " .. vehicleID .. ".", player, 0, 255, 0 ) else outputChatBox( "Este " .. getVehicleName( vehicle ) .. " no tiene ID.", player, 255, 0, 0 ) end else outputChatBox( "No estas en ninguno coche.", player, 255, 0, 0 ) end end ) addCommandHandler( { "oldvehicleid", "oldvehicle" }, function( player, commandName ) local vehicle = p[ player ] and p[ player ].oldVehicle if vehicle and isElement( vehicle ) then local vehicleID = vehicles[ vehicle ] and vehicles[ vehicle ].vehicleID if vehicleID then outputChatBox( "El ID de tu viejo vehiculo es " .. getVehicleName( vehicle ) .. " is " .. vehicleID .. ".", player, 0, 255, 0 ) else outputChatBox( "This " .. getVehicleName( vehicle ) .. " has no ID.", player, 255, 0, 0 ) end else outputChatBox( "You haven't been in any vehicle.", player, 255, 0, 0 ) end end ) Es lo que saca el ID de el coche como pasarlo a mi script?
Alexs Posted August 29, 2012 Posted August 29, 2012 Server: addCommandHandler("mirarid", function ( playerSource ) setElementData(playerSource, "mirarid.on", true) end ) addEventHandler("onPlayerContact", getRootElement(), function (prev, act) if ( getElementType(act) == "vehicle" ) and ( getElementData( source, "mirarid.on") == true ) then local vehicleID = vehicles[ act ] and vehicles[ act ].vehicleID if vehicleID then outputChatBox( "ID de Este Vehiculo: "..vehicleID, source, 255,255,0, true) end end end )
Recommended Posts