MRThinker

[HELP] Save Account Data

Recommended Posts

Hi Guys

Give me a resource for saving money, skin when player death and when player leave the server

Give me a account data saver 

Thanks ❤

Share this post


Link to post
function saveData(p) 
    if not source and p then source = p; end 
    local a = getPlayerAccount(source); 
    if a then 
        if not isGuestAccount(a) then 
            setAccountData(a, "user.money", getPlayerMoney(source)); 
            setAccountData(a, "user.skin", getPedSkin(source)); 
            setAccountData(a, "user.health", getElementHealth(source)); 
            setAccountData(a, "user.armor", getPedArmor(source)); 
            local x,y,z = getElementPosition(source); 
            setAccountData(a, "user.pos", toJSON({x,y,z,getElementInterior(source),getElementDimension(source)})); 
            local rx, ry, rz = getElementRotation(source); 
            setAccountData(a, "user.rot", toJSON({rx,ry,rz})); 
            local stats = {}; 
            for i=69,79 do 
                stats[i] = getPedStat(source,i); 
            end 
            setAccountData(a, 'user.stats', toJSON(stats)); 
        end 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),saveData) 
addEventHandler("onPlayerLogout",getRootElement(),saveData) 
addEventHandler("onPlayerWasted",getRootElement(),saveData) 
  
function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) 
    local a = getPlayerAccount(source); 
    if not isGuestAccount(a) then 
        local pos = fromJSON(getAccountData(theCurrentAccount,"user.pos")) or {}; 
        if pos[1] and pos[2] and pos[3] then 
            local money =   getAccountData(theCurrentAccount,"user.money"); 
            local health =  getAccountData(theCurrentAccount,"user.health"); 
            local armor =   getAccountData(theCurrentAccount,"user.armor"); 
            local skin =    getAccountData(theCurrentAccount,"user.skin"); 
            local rx,ry,rz = fromJSON(getAccountData(theCurrentAccount,"user.rot")); 
            if not rx then rx = 0; end; 
            if not ry then ry = 0; end; 
            if not rz then rz = 0; end; 
             
            local stats =   fromJSON(getAccountData(theCurrentAccount,"user.stats")); 
            spawnPlayer(source,pos[1],pos[2],pos[3],0,skin,pos[4],pos[5]); 
            --setElementRotation(source,tonumber(rx),tonumber(ry),tonumber(rz)); 
            setElementRotation(source,0,0,0); 
            setElementHealth(source,health); 
            setPedArmor(source,armor); 
            setPlayerMoney(source,money); 
            setElementFrozen(source,false); 
            setElementAlpha(source,255) 
            for i=69,79 do 
                setPedStat(source,i,tonumber(stats[tostring(i)])); 
            end 
        else 
            FirstTimePlaying(); 
        end    
  
        setCameraTarget(source,source); 
        fadeCamera(source,true,2); 
    end 
end 
addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) 
  
function FirstTimePlaying() 
    local PedSkins = {26,29,27,33,34,32,45,46,61,59,60,68,73,78,79,93,100,105,106,107,101,102,103,104,108,109,110,114,115,116,117,118,120,121,122,127,133,152,157,154,161,163,165,170,176,177,179,181,191,192,204,206,217,227,246,247,248,250,254,264}; 
    spawnPlayer(source, 1608, 1830, 10.8, 0, math.random(1,#PedSkins), 0, 0); 
    setPlayerMoney(source,2500); 
    giveWeapon(source,math.random(22,23),250); 
    giveWeapon(source,25,25); 
end 
  
function saveWeaponData(p) 
    if not source and p then source = p; end 
    local a = getPlayerAccount(source); 
    if not isGuestAccount(a) then 
        for i=0,11 do 
            setAccountData(a, "weapon."..i,toJSON({getPedWeapon(source,i),getPedTotalAmmo(source,i)})); 
        end 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),saveWeaponData) 
addEventHandler("onPlayerWasted",getRootElement(),saveWeaponData) 
addEventHandler("onPlayerLogout",getRootElement(),saveWeaponData) 
  
  
function loadWeaponData(p) 
    if not source and p then source = p; end 
    local a = getPlayerAccount(source); 
    if not isGuestAccount(a) then 
        for i=0,11 do 
            local w = fromJSON(getAccountData(a, "weapon."..i, getPedWeapon(source,i))); 
            giveWeapon(source,w[1],w[2]); 
        end 
    end 
end 
addEventHandler("onPlayerSpawn",getRootElement(),loadWeaponData) 
  

 

Share this post


Link to post

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.