Jump to content

Weapon Stats


Xeno

Recommended Posts

i dont know if it right or not

function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local stat = getPedStat ( source, 71 ) --- deset egal skill 
            setAccountData(playerAccount, "Whatever", stat) 
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
      local stat = getPedStat ( source, 71 ) 
      if (playerAccount) then 
            local stat1 = getAccountData(playerAccount, "Whatever", stat1) 
            if (stat1) then 
                setPedStat(source, 71, 999) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Link to comment

Try this (Not tested):

function saveWeaponStats(player) 
    if (not player or not isElement(player)) then return end 
    local account = getPlayerAccount(player) 
    if (account and not isGuestAccount(account)) then 
        local stats = {} 
        for stat=69, 81 do 
            local value = getPedStat(player, stat) 
            stats[stat] = value 
        end 
        setAccountData(account, "weaponStats", toJSON(stats)) 
    end 
end 
  
function loadWeaponStats(player) 
    if (not player or not isElement(player)) then return end 
    local account = getPlayerAccount(player) 
    if (account and not isGuestAccount(account)) then 
        local statsData = getAccountData(account,"weaponStats") 
        if (statsData and statsData ~= "") then 
            for stat, value in pairs(fromJSON(statsData)) do 
                setPedStat(player, stat, value) 
            end 
        end 
    end 
end 
  
addEventHandler("onPlayerQuit",root,function () saveWeaponStats(source) end) 
addEventHandler("onPlayerLogin",root,function () loadWeaponStats(source) end) 

It should save all stats and their values as a JSON string in the account data "weaponStats", then unpack the JSON string and set them.

Link to comment

Ok, I've found the problem, the account data has a character limit, so the JSON string is not 100% saved.

function saveWeaponStats(player) 
    if (not player or not isElement(player)) then return end 
    local account = getPlayerAccount(player) 
    if (account and not isGuestAccount(account)) then 
        local stats = "" 
        for stat=69, 81 do 
            local value = getPedStat(player, stat) 
            stats = stats ..",".. stat ..";".. value 
        end 
        setAccountData(account, "weaponStats", stats) 
    end 
end 
  
function loadWeaponStats(player) 
    if (not player or not isElement(player)) then return end 
    local account = getPlayerAccount(player) 
    if (account and not isGuestAccount(account)) then 
        local statsData = getAccountData(account,"weaponStats") 
        local stats = split(statsData, ",") 
        for k, v in ipairs(stats) do 
            local stat = split(v, ";") 
            setPedStat(player, tonumber(stat[1]), tonumber(stat[2])) 
        end 
    end 
end 
  
addEventHandler("onPlayerQuit",root,function () saveWeaponStats(source) end) 
addEventHandler("onPlayerLogin",root,function () loadWeaponStats(source) end) 

This one works.

Link to comment
function table.string( t,name,notVar ) 
    if type( t ) ~= 'table' then 
        return false 
    end 
     
    local eStr 
    if notVar then 
        eStr = '{ ' 
    else 
        eStr = tostring( name or 'Table' )..' = { ' 
    end 
    for i,v in pairs( t ) do 
        eStr = eStr.."["..tostring( i ).."] = "..tostring( v ).."," 
    end 
    return eStr:sub( 0,#eStr - 1 ).." }" 
end 
  
function saveWeaponStats( player ) 
    if isElement( player ) then  
        local account = getPlayerAccount( player ) 
        if not isGuestAccount( account ) then 
            local stats = { } 
            for stat = 69, 81 do 
                stats[ stat ] = getPedStat( player, stat ) 
            end 
            setAccountData( account, "weaponStats", table.string( stats,_,true ) ) 
            stats = nil 
        end 
    end 
    return false 
end 
  
function loadWeaponStats( player ) 
    if isElement( player ) then  
        local account = getPlayerAccount( player ) 
        if not isGuestAccount( account ) then 
            local statsData = getAccountData( account,"weaponStats" ) 
            if statsData then 
                loadstring( 
                    'for i,v in pairs( '..statsData..' ) do '.. 
                        'setPedStat( '..player..',i,v ) '.. 
                    'end' 
                )( ) 
            end 
        end  
    end 
end 
  
addEventHandler("onPlayerQuit",root,function () saveWeaponStats( source ) end ) 
addEventHandler("onPlayerLogin",root,function () loadWeaponStats( source ) end ) 

Updated.

Link to comment

do you know what i like in mta?

if there any script disable some thing make an anti for that and it well work fine 100%

function loginPlayer ( thePlayer, command, username, password ) 
    local account = getAccount ( username, password ) 
        if ( account ~= false ) then 
            logIn ( thePlayer, account, password ) 
        else 
            outputChatBox ( "Wrong username or password!", thePlayer, 255, 255, 0 ) 
        end 
end 
addCommandHandler ( "login", loginPlayer ) 

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