Xeno Posted February 4, 2012 Share Posted February 4, 2012 How would I go about saving weapon stats? I know I have to use setAccountData and getAccountData, but i Don't know what to put. I would appreciate it if you could give me some help. Xeno Link to comment
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 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
Castillo Posted February 4, 2012 Share Posted February 4, 2012 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
Xeno Posted February 4, 2012 Author Share Posted February 4, 2012 Thanks for the replies guys. It doesn't work and I dont get any errors. Link to comment
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 did you use my post ? Link to comment
Xeno Posted February 4, 2012 Author Share Posted February 4, 2012 Yours works Evil. Do I have to add every weapon manually? Link to comment
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 i think you can make a table For the first time i help some one and my code works iam so Happy Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 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
Kenix Posted February 4, 2012 Share Posted February 4, 2012 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
Xeno Posted February 4, 2012 Author Share Posted February 4, 2012 Thanks for the replys. But neither work... I have logout disabled, could that have anything to do with it? Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 Which one doesn't work? I have tested my last code and it worked perfectly. It doesn't save on logout, it'll save on quit and then load on login. Link to comment
Xeno Posted February 4, 2012 Author Share Posted February 4, 2012 I tested both of yours and they don't work... Does it matter if I set the stat VAI admin panel? Link to comment
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 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
Castillo Posted February 4, 2012 Share Posted February 4, 2012 @Evil-Codr3: What has a login system to do with what Xeno want's? @Xeno: You have set it up as server side, right? Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 Well, I don't know what's wrong then, it works perfectly here. Link to comment
Xeno Posted February 4, 2012 Author Share Posted February 4, 2012 Nevermind. It was not working when I set it on the admin panel for some reason... Thanks for the help Link to comment
Xeno Posted February 4, 2012 Author Share Posted February 4, 2012 Ahh, It was because I set a timer on spawn player. Thanks for all your help again. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now