Jump to content

Ajuda com save system


Recommended Posts

Posted

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

n-560x95_0778B0_A6CC35_000000_000000.png

kpnN6Q.png

Posted

Se nenhum existente funciona, faça-os, Vodka.

Eventos

onPlayerLogin 
onPlayerQuit 

Funções

setAccountData() 
// ou, em alguns casos 
setElementData() 

Software Engineer & Entrepreneur Running Lustrel and VilarikA • Highly engaged on open source community

Posted

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

n-560x95_0778B0_A6CC35_000000_000000.png

kpnN6Q.png

Posted

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.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Não funciono não percebo porquê que não funciona já tentei com o seu DNL, mas também não funciono, já não sei o que fazer :/

Esta tudo direito como deveria, mas não percebo o porque de não estar a funcionar :(

n-560x95_0778B0_A6CC35_000000_000000.png

kpnN6Q.png

Posted

voce deve usa as funçoes citadas "setAccountData" para guardar uma data na conta de um jogador, porque o código só salva quando morre.

560x95_FFFFFF_09FF00_050505_000000.png

"Querer não é poder, mas tentar é avançar"!

Posted

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 
) 

Please do not PM me with scripting related question nor support, use the forums instead.

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