Jump to content

setElementData


Newbie

Recommended Posts

function Car1() 
        if ( playeraccount ) then 
        local playercar = getAccountData ( playeraccount, "car" ) 
        setElementData(source,"car",405) 
end 
end 
addCommandHandler("car1", Car1) 

-- TO SPAWN CAR

function callCar(player) 
        if ( playeraccount ) then 
        local playercar = getAccountData ( playeraccount, "car" ) 
        local x,y,z = getElementPosition(player) 
        createVehicle (playercar, x, y, z+3)         
end 
end 
addCommandHandler("callmycar", callCar) 

Im trying to set data as a car id, and then spawn car with that id in player location, but that dont work, nil at createvehicle

Link to comment

it is

function onPlayerQuit ( ) 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then  
            local playercar = getElementData(source,"car") 
            setAccountData ( playeraccount, "car", playercar ) 
      end 
end 
  
function onPlayerLogin (_, playeraccount ) 
    if ( playeraccount ) then 
        local playercar = getAccountData ( playeraccount, "car" ) 
        setElementData(source,"car",playercar or 0) 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) 

Link to comment

Account data and element data are different.

Element data: It is temporary and uses a lot of cpu so use it in extreme necessary.

Account data: This is stored in database and it's better than element data.

  
  
function callCar(player,_,car) 
local car = tonumber (car) 
local playeraccount = getPlayerAccount(player) 
        if ( playeraccount ) then 
if  car then 
   setAccountData(playeraccount,"car",car) 
else 
        local playercar = getAccountData ( playeraccount, "car" )  
  
        local x,y,z = getElementPosition(player) 
  
        local car = createVehicle (playercar, x, y, z+3)    
       spawnVehicle (car,x,y,z+3) 
  
          end 
     end 
end 
  
addCommandHandler("car", callCar) 

Usage:

To set a new car id then: /car id

Example: /car 411

To spawn your car:

/car

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...