Jump to content

Ajuda com save system


Recommended Posts

Boas a todos, eu precisava de um save system que funcione ja usei muitos saver's daqui da comunidade e nenhum funciono corretamente nao sei se e devido a versão nova do mta, mesmo assim preciso de um urgente porque no meu sv não salva armas, nem skin, nem dinheiro, nem mesmo ao fazer quit e ao entrar. :/

Link to comment

Fiz um pequeno save so para armas mas nao sei porque que nao funciona peco ajuda a pessoas experientes para me ajudarem ou ao menos diserem onde esta o erro:

localPlayerWeapons = { } 
  
addEventHandler ( "onPlayerWasted", Root , 
 function () 
Local = getPedWeapon [source] ) then 
PlayerWeapon [source] = { } 
end 
local weapon = getPedWeapon (source, slot ) 
PlayerWeapons [source] [weapon] = ammo 
end  
end 
end 
) 
addEventHandler ( "onPlayerSpawn", root, 
function () 
if playerWeapons [source] then 
(playerWeapons [source] ) do 
giveweapon (source, tonumber ( weapon ), tonumber (ammo ) ) 
end 
end 
playerWeapons [source] = nil 
end 
) 

obrigado

Link to comment

Se você usasse a barra de pesquisa ia encontrar isto:

local playerWeapons = { } 
  
addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        if ( not playerWeapons [ source ] ) then 
            playerWeapons [ source ] = { } 
        end 
        for slot = 0, 12 do 
            local weapon = getPedWeapon ( source, slot ) 
            if ( weapon > 0 ) then 
                local ammo = getPedTotalAmmo ( source, slot ) 
                if ( ammo > 0 ) then 
                    playerWeapons [ source ] [ weapon ] = ammo 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerSpawn", root, 
    function ( ) 
        if ( playerWeapons [ source ] ) then 
            for weapon, ammo in pairs ( playerWeapons [ source ] ) do 
                giveWeapon ( source, tonumber ( weapon ), tonumber ( ammo ) ) 
            end 
        end 
  
        playerWeapons [ source ] = nil 
    end 
) 

Se você quer que a arma seja salva quando sair do servidor, precisará editar, usando as funções citadas acima.

Link to comment

Tente isto. Eu não testei.

local playerWeapons = { } 
  
local onDeath = false 
addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        if ( not playerWeapons [ source ] ) then 
            playerWeapons [ source ] = { } 
        end 
        for slot = 0, 12 do 
            local weapon = getPedWeapon ( source, slot ) 
            if ( weapon > 0 ) then 
                local ammo = getPedTotalAmmo ( source, slot ) 
                if ( ammo > 0 ) then 
                    playerWeapons [ source ] [ weapon ] = ammo 
                    onDeath = true 
                end 
            end 
        end 
    end 
) 
  
addEventHandler( "onPlayerQuit", root, 
    function () 
        local account = getPlayerAccount(source) 
        if (account) and not isGuestAccount(account) then 
            savePlayerWeapons(source, account) 
        end 
        if playerWeapons[source] then 
            playerWeapons[source] = nil 
        end 
    end 
) 
  
function savePlayerWeapons(player, account) 
    if not player then return false end 
    local tWeapons = {} 
    for slot=0, 12 do 
        local weapon = getPedWeapon(player, slot) 
        local ammo = getPedTotalAmmo(player, slot) 
        if (ammo > 0) then 
            tWeapons[weapon] = ammo 
        end 
    end 
    if account then 
        setAccountData(account, "playerWeapons", toJSON(tWeapons)) 
    end 
    return toJSON(tWeapons) 
end 
  
function loadPlayerWeapons(player, onDeath, account) 
    if not player then return false end 
    if (onDeath == true) then 
        if playerWeapons[player] then 
            for weapon, ammo in pairs(playerWeapons[player]) do 
                giveWeapon(player, weapon, ammo) 
            end 
        end 
        return 
    end 
    if not account then return false end 
    local weapons = getAccountData(account, "playerWeapons") 
    if (weapons) then 
        for weapon, ammo in pairs(fromJSON(weapons)) do 
            giveWeapon(player, weapon, ammo, true) 
        end 
    end 
    return weapons 
end 
  
addEventHandler( "onPlayerLogout", root, 
    function (prevAcc) 
        if savePlayerWeapons(source, prevAcc) then 
            takeAllWeapons(source) 
        end 
        onDeath = false 
    end 
) 
  
addEventHandler( "onPlayerSpawn", root, 
    function () 
        local account = getPlayerAccount(source) 
        if (account and isGuestAccount(account)) or (onDeath) then 
            account = false 
        end 
        loadPlayerWeapons(source, onDeath, account) 
    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...