Newbie Posted October 15, 2014 Share Posted October 15, 2014 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
xScatta Posted October 15, 2014 Share Posted October 15, 2014 'playeraccount' isn't defined. Link to comment
Newbie Posted October 15, 2014 Author Share Posted October 15, 2014 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
Saml1er Posted October 15, 2014 Share Posted October 15, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now