Jump to content

help system vehicle ;(


Recommended Posts

I have this system and I need a function to change the owner of the vehicle

function getVehicleFromID ( ID ) 
 for id, i in ipairs (getElementsByType( "vehicle" )) do 
    if getElementID (i) == ID then 
      return i 
       end 
         end 
           end 
  
vehicles = {} 
function vehiclesCache () 
 vehicles = {} 
  for k, i in pairs (xmlNodeGetChildren( xmlLoadFile( "scripts/vehicles.xml" ) )) do 
    vehicles[xmlNodeGetAttribute ( i, "id" )] = { id = xmlNodeGetAttribute ( i, "id" ), model = xmlNodeGetAttribute ( i, "model" ), x = xmlNodeGetAttribute ( i, "x" ), y = xmlNodeGetAttribute ( i, "y" ),z = xmlNodeGetAttribute ( i, "z" ),rotX = xmlNodeGetAttribute ( i, "rotX" ),rotY = xmlNodeGetAttribute ( i, "rotY" ),rotZ = xmlNodeGetAttribute ( i, "rotZ" ),ptype = xmlNodeGetAttribute ( i, "ptype" ), owner = xmlNodeGetAttribute ( i, "owner" ), damage = xmlNodeGetAttribute ( i, "damage" ), r = xmlNodeGetAttribute ( i, "r" ), g = xmlNodeGetAttribute ( i, "g" ), b = xmlNodeGetAttribute ( i, "b" ), sr = xmlNodeGetAttribute ( i, "sr" ) or xmlNodeGetAttribute ( i, "r" ), sg = xmlNodeGetAttribute ( i, "sg" ) or xmlNodeGetAttribute ( i, "g" ), sb = xmlNodeGetAttribute ( i, "sb" ) or xmlNodeGetAttribute ( i, "b" ) } 
  end 
  return vehicles 
end 
  
  
addEventHandler( "onResourceStart", resourceRoot, 
 function () 
  for id, v in pairs ( vehiclesCache() ) do 
      setElementID(createVehicle( tonumber (vehicles[id]["model"]), tonumber(vehicles[id]["x"]), tonumber(vehicles[id]["y"]), tonumber(vehicles[id]["z"]), tonumber(vehicles[id]["rotX"]), tonumber(vehicles[id]["rotY"]), tonumber(vehicles[id]["rotZ"])), id) 
      local vehicle = getVehicleFromID( id ) 
      setVehicleColor( vehicle, tonumber( vehicles[id]["r"]), tonumber( vehicles[id]["g"]), tonumber( vehicles[id]["b"]), tonumber( vehicles[id]["sr"]), tonumber( vehicles[id]["sg"]), tonumber( vehicles[id]["sb"])) 
  
        if vehicles[id]["damage"] == "false" then 
         setVehicleDamageProof( vehicle, true ) 
        end 
  
          if vehicles[id]["ptype"] == "team" then 
           local lr, lg, lb = getTeamColor( getTeamFromName( vehicles[id]["owner"] ) ) 
           setVehicleHeadLightColor( vehicle, lr, lg, lb ) 
          end 
     end 
    end 
) 
  
function getVehicleOwner( vehicle ) 
 if vehicles[getElementID(vehicle)] then 
  local owner = vehicles[getElementID(vehicle)]["owner"] 
   if owner then 
       return owner 
     end 
   end 
end 
  
  
addCommandHandler( "crear", 
   function ( source, _, idd, modelo, stype, dueno, dano, cr, cg, cb, ssr, ssg, ssb) 
   if isObjectInACLGroup ("user."..getAccountName( getPlayerAccount (source) ), aclGetGroup ( "RGB" ) ) then 
   if not vehicles[idd] then 
    if not isPedInVehicle( source ) then 
     local sx, sy, sz = getElementPosition( source ) 
     local rx, ry, rz = getElementRotation ( source ) 
     if idd and modelo and stype and dueno and dano and cr and cg and cb then 
               setElementID(createVehicle( tonumber (modelo), sx, sy, sz, rx, ry, rz), idd) 
               vehicles[idd] = { id = idd, model = modelo, x = sx, y = sy, z = sz, rotX = rx, rotY = ry, rotZ = rz, ptype = stype, owner = dueno, damage = dano, r = cr, g = cg, b = cb, sr =  ssr or cr, sg = ssg or cg, sb = ssb or cb} 
               local vehicle = getVehicleFromID( idd ) 
               warpPedIntoVehicle( source, vehicle ) 
                 if dano == "false" then 
                    setVehicleDamageProof( vehicle, true) 
                 end 
                        if not ssr and not ssg and not ssb then 
                               setVehicleColor( vehicle, tonumber( cr ), tonumber( cg), tonumber( cb), tonumber( cr ), tonumber( cg), tonumber( cb) ) 
                        elseif ssr and ssg and ssb then 
                               setVehicleColor( vehicle, tonumber( cr ), tonumber( cg), tonumber( cb), tonumber( ssr ), tonumber( ssg), tonumber( ssb) ) 
                        end 
                             if stype == "team" then 
                                local lr, lg, lb = getTeamColor( getTeamFromName( dueno ) ) 
                                setVehicleHeadLightColor( vehicle, lr, lg, lb ) 
                             end 
            else outputChatBox( "Syntax: /create ID modelo Privatizacion Dueño Daño ColorR ColorG ColorB (ColorSecR ColorSecG ColorSecB.)", source, 255, 0, 0) 
                 end 
            else outputChatBox( "Para evitar errores, por favor baja del vehiculo.", source, 255, 0, 0) 
              end 
            else outputChatBox( "ID Incorrecta, Quiza ya este en uso. Utilize otra.", source, 255, 0, 0) 
        end 
        else outputChatBox( "Comando solo para administradores.", source, 255, 0, 0) 
    end 
end 
) 
  
addCommandHandler( "borrar", 
    function ( source ) 
           if isObjectInACLGroup ("user."..getAccountName( getPlayerAccount (source) ), aclGetGroup ( "RGB" ) ) then 
              if isPedInVehicle( source ) then 
                local vehicle = getPedOccupiedVehicle( source ) 
                local id = getElementID( vehicle ) 
                  if vehicles[id] then 
                    destroyElement( vehicle ) 
                    vehicles[id] = nil 
                  else outputChatBox( "Este vehiculo no esta privatizado.", source, 255, 0, 0) 
                end 
             else outputChatBox( "Debes estar en el vehiculo que deseas eliminar.", source, 255, 0, 0) 
           end 
        else outputChatBox( "Comando solo para administradores.", source, 255, 0, 0) 
      end 
    end 
) 

try this but does not work with me

function cars( source ) 
       if isPedInVehicle(source) then 
       local username = getAccountName( getPlayerAccount (source) ) 
            local vehicle = getPedOccupiedVehicle( source ) 
            local id = getElementID( vehicle ) 
               if vehicles[id] then 
                    local x, y, z = getElementPosition ( source ) 
                    local rx, ry, rz = getElementRotation ( source ) 
                    vehicles[id]["x"] = x 
                    vehicles[id]["y"] = y 
                    vehicles[id]["z"] = z 
                    vehicles[id]["rotX"] = rx 
                    vehicles[id]["rotY"] = ry 
                    vehicles[id]["rotZ"] = rz 
                    setVehicleRespawnPosition( vehicle, x, y, z, rx, ry, rz) 
                   local r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 = getVehicleColor ( vehicle, true ) 
                    vehicles[id]["r"] = r1 
                    vehicles[id]["g"] = g2 
                    vehicles[id]["b"] = b1 
                    vehicles[id]["sr"] = r2 
                    vehicles[id]["sg"] = g2 
                    vehicles[id]["sb"] =  b2 
                    vehicles[id]["ptype"] = user 
                    vehicles[id]["owner"] = username 
                   vehicles[id]["model"] = getElementModel(vehicle) 
                   vehicles[id]["upgrades"] = getVehicleUpgrades(vehicle) 
                      setVehicleDamageProof(vehicle, true) 
                end 
              end 
            end 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...