Jump to content

Accountdata vehicle saver


Miika

Recommended Posts

Hi.

there is a lot of errors which need to be corrected.

the biggest error (red) is the color.

[server]

function saveCommand(thePlayer) 
local playeraccount = getPlayerAccount ( thePlayer ) 
if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
if (isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(thePlayer)),aclGetGroup("Admin"))) then 
for i, vehicle in pairs (getElementsByType("vehicle")) do 
    local px, py, pz = getElementPosition(vehicle) 
    local rx, ry, rz = getElementRotation(vehicle) 
    local color1, color2, color3 = getVehicleColor(vehicle) 
    local model = getElementModel(vehicle) 
    local health = getElementHealth (vehicle) 
    local upgrades = getVehicleUpgrades(vehicle) 
    local paintjob = getVehiclePaintjob(vehicle) 
     
    setAccountData ( playeraccount, "vipcar.position", tostring(px)..","..tostring(py)..","..tostring(pz) ) 
    setAccountData ( playeraccount, "vipcar.rotation", tostring(rx)..","..tostring(ry)..","..tostring(rz) ) 
    setAccountData ( playeraccount, "vipcar.color", tostring(color1)..","..tostring(color2)..","..tostring(color3) ) 
    setAccountData ( playeraccount, "vipcar.model", model) 
    setAccountData ( playeraccount, "vipcar.health", health) 
    setAccountData ( playeraccount, "vipcar.tableupgrades", tableUpgrades) 
    setAccountData ( playeraccount, "vipcar.upgrades", upgrades) 
    setAccountData ( playeraccount, "vipcar.paintjob", paintjob) 
     
    outputChatBox("* VIP-CAR: Car saved to your account!", thePlayer, 0, 255, 0, true) 
  end 
  else 
    outputChatBox("* VIP-CAR: You don't have permissions to save your vehicle!", thePlayer, 255, 0, 0, true) 
  return end 
end 
end 
addCommandHandler("save", saveCommand) 
  
function onPlayerLogin (_, playeraccount ) 
if (isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(_)),aclGetGroup("Admin"))) then 
if ( playeraccount ) then 
    local position = getAccountData ( playeraccount, "vipcar.position" ) 
    if ( position ) then 
        local p = split(position, ",") 
    end 
    local rotation = getAccountData ( playeraccount, "vipcar.rotation" ) 
    if ( rotation ) then 
        local r = split(rotation, ",") 
    end 
    local color = getAccountData ( playeraccount, "vipcar.color" ) 
    if ( color ) then 
        local c = split(color, ",") 
    end 
    local model = getAccountData ( playeraccount, "vipcar.model" ) 
    local health = getAccountData ( playeraccount, "vipcar.health" ) 
    local tableUpgrades = getAccountData ( playeraccount, "vipcar.tableUpgrades" ) 
    local upgrades = getAccountData ( playeraccount, "vipcar.upgrades" ) 
    local paintjob = getAccountData ( playeraccount, "vipcar.paintjob" ) 
    if ( model ) then 
        local vehicle = createVehicle( model, p[1], p[2], p[3], r[1], r[2], r[3] ) 
    end 
    setElementHealth ( vehicle, health ) 
    setVehicleColor ( vehicle, c[1], c[2], c[3] ) 
    if ( paintjob ) then 
        setVehiclePaintjob( vehicle, paintjob ) 
    end 
    local upgrades = split( upgrades, 44 ) 
    for index, upgrade in pairs (upgrades) do 
        addVehicleUpgrade( vehicle, upgrade ) 
    end 
    outputChatBox("* VIP-CAR: Car loaded from your account!", source, 0, 255, 0, true) 
end 
end 
end 
addCommandHandler("load", onPlayerLogin) 
  

Link to comment

Since we're here to help you with any doubt or current problem you're having and not to 'fix' a piece of code directly, it would be cool if you specify what's exactly wrong or not properly working on the code you've introduced above; and only then we'll be able to possibly assist you.

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