Tox Posted January 7, 2016 Share Posted January 7, 2016 hi, i am trying to save an SQL weapon data onPlayerQuit. it seems fine if you don't get killed, gives weapons when spawning etc. once you die and after spawn, it gives weapons again but when player quits and connects again data gets lost for some reason. do you know why it could be? Link to comment
#RooTs Posted January 7, 2016 Share Posted January 7, 2016 hi, i am trying to save an SQL weapon data onPlayerQuit. it seems fine if you don't get killed, gives weapons when spawning etc.once you die and after spawn, it gives weapons again but when player quits and connects again data gets lost for some reason. do you know why it could be? show me all your code Link to comment
Tox Posted January 7, 2016 Author Share Posted January 7, 2016 --quit addEventHandler ("onPlayerQuit",root, function() if isPedDead(source) then return end local id = getPlayerData (source,"userinfo","userid") local x,y,z = getElementPosition(source) local r,g,b = source:getNametagColor() local int,dim = getElementInterior(source),getElementDimension(source) local money,bank = source:getMoney(), getPlayerData (source,"userinfo","userbank") local skin = getElementModel(source) sql.Exec ("UPDATE userinfo SET userX = ?, userY = ?, userZ = ?, userR = ?, userG = ?, userB = ?,userskin= ?, userdim = ?, userint = ?, usermoney = ?, userbank =?, userfirstjoin = ? WHERE userid = ? ",x,y,z,r,g,b,skin,int,dim,money,bank,0,id) for i = 1 , 12 do setPlayerData (source, "userinfo","userweapon_"..i,getPedWeapon(source,i) ) setPlayerData(source,"userinfo","userammo_"..i,getPedTotalAmmo(source,i)) end end ) --spawn addEventHandler ("onPlayerSpawn",root, function() local weapon = {} local wep,ammo = {},{} local data_weapon,data_ammo = {},{} for i = 1, 12 do data_weapon[i], data_ammo[i] = tonumber (getPlayerData (source,"userinfo","userweapon_"..i)),tonumber(getPlayerData (source,"userinfo","userammo_"..i)) wep[i],ammo[i] = data_weapon[i], data_ammo[i] giveWeapon (source,wep[i],ammo[i]) end end ) P.S setPlayerData and getPlayerData are custom functions of mine Link to comment
#RooTs Posted January 7, 2016 Share Posted January 7, 2016 add more functions Example -- dead and diad addEventHandler ("onPlayerWasted",root, function() if isPedDead(source) then return end local id = getPlayerData (source,"userinfo","userid") local x,y,z = getElementPosition(source) local r,g,b = source:getNametagColor() local int,dim = getElementInterior(source),getElementDimension(source) local money,bank = source:getMoney(), getPlayerData (source,"userinfo","userbank") local skin = getElementModel(source) sql.Exec ("UPDATE userinfo SET userX = ?, userY = ?, userZ = ?, userR = ?, userG = ?, userB = ?,userskin= ?, userdim = ?, userint = ?, usermoney = ?, userbank =?, userfirstjoin = ? WHERE userid = ? ",x,y,z,r,g,b,skin,int,dim,money,bank,0,id) for i = 1 , 12 do setPlayerData (source, "userinfo","userweapon_"..i,getPedWeapon(source,i) ) setPlayerData(source,"userinfo","userammo_"..i,getPedTotalAmmo(source,i)) end end ) -- login addEventHandler ("onPlayerLogin",root, function() local weapon = {} local wep,ammo = {},{} local data_weapon,data_ammo = {},{} for i = 1, 12 do data_weapon[i], data_ammo[i] = tonumber (getPlayerData (source,"userinfo","userweapon_"..i)),tonumber(getPlayerData (source,"userinfo","userammo_"..i)) wep[i],ammo[i] = data_weapon[i], data_ammo[i] giveWeapon (source,wep[i],ammo[i]) end end ) Link to comment
Tox Posted January 7, 2016 Author Share Posted January 7, 2016 by my reckoning player's weapon data is deleted after dying and how do you think you're going to add onPlayerWasted event and check if player is not dead if isPedDead(source) then return end Link to comment
#RooTs Posted January 7, 2016 Share Posted January 7, 2016 by my reckoning player's weapon data is deleted after dyingand how do you think you're going to add onPlayerWasted event and check if player is not dead if isPedDead(source) then return end when you die, you can sit in sql data not to lose the spawn onPlayerWasted = setPlayerData (source, "userinfo","userweapon_"..i,getPedWeapon(source,i) ) setPlayerData(source,"userinfo","userammo_"..i,getPedTotalAmmo(source,i)) onPlayerLogin = getPlayerData or remove line in event "onPlayerWasted" if isPedDead(source) then return end Link to comment
#RooTs Posted January 7, 2016 Share Posted January 7, 2016 anyway, you need to save data when you die Link to comment
Tox Posted January 7, 2016 Author Share Posted January 7, 2016 well, tried your way desperately but it didn't work 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