Castillo Posted May 31, 2010 Posted May 31, 2010 hey, i want to save player weapons,ammo in sqlite and then when he logins in he will get them back, here is my code so far. local slotT = "slot" local ammoT = "ammo" function start () executeSQLCreateTable(slotT, "accountname TEXT, slot INT") executeSQLCreateTable(ammoT, "accountname TEXT, ammo INT") outputDebugString ( "Resource loaded.", 3 ) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start) function savePlayerData() local acc = getPlayerAccount(source) if not isGuestAccount(acc) then local i = 0 while i < 13 do local temp = getPlayerWeapon(source, i) executeSQLUpdate(slotT, "slot = '"..temp.."'", "accountname = '"..getAccountName(acc).."'") local temp2 = getPlayerTotalAmmo(source, i) executeSQLUpdate(ammoT, "ammo = '"..temp2.."'", "accountname = '"..getAccountName(acc).."'") i = i +1 end end end addEventHandler("onPlayerQuit", getRootElement(), savePlayerData) addEventHandler("onPlayerLogout", getRootElement(), savePlayerData) addEventHandler("onPlayerWasted", getRootElement(), savePlayerData) function login1(prev, account, autologin) local account = getPlayerAccount(source) local result = executeSQLQuery("SELECT slot FROM slot WHERE accountname='" .. getAccountName(account) .. "'") local result2 = executeSQLQuery("SELECT ammo FROM ammo WHERE accountname='" .. getAccountName(account) .. "'") if result and #result > 0 then --giveWeapon(source, result, result2) giveWeapon(source, result, tonumber(result2)) end outputDebugString(tostring(executeSQLInsert(slotT, "'0', '"..getAccountName(account).."'", "slot, accountname"))) outputDebugString(tostring(executeSQLInsert(ammoT, "'0', '"..getAccountName(account).."'", "ammo, accountname"))) end addEventHandler("onPlayerLogin", getRootElement(), login1) addEventHandler("onPlayerSpawn", getRootElement(), login1) btw this code is creating somthing called ERROR: ERROR: Infinite/too long execution (weapon) ERROR: Aborting; infinite running script
50p Posted June 1, 2010 Posted June 1, 2010 Your while loop is infinite. I suggest you use for loop instead.
Castillo Posted June 1, 2010 Author Posted June 1, 2010 Your while loop is infinite. I suggest you use for loop instead. but the save weapon part is it fine or is buggi? the code should look like this then? local slotT = "slot" local ammoT = "ammo" function start () executeSQLCreateTable(slotT, "accountname TEXT, slot INT") executeSQLCreateTable(ammoT, "accountname TEXT, ammo INT") outputDebugString ( "Resource loaded.", 3 ) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start) function savePlayerData() local acc = getPlayerAccount(source) if not isGuestAccount(acc) then local i = 0 for i < 13 do local temp = getPlayerWeapon(source, i) executeSQLUpdate(slotT, "slot = '"..temp.."'", "accountname = '"..getAccountName(acc).."'") local temp2 = getPlayerTotalAmmo(source, i) executeSQLUpdate(ammoT, "ammo = '"..temp2.."'", "accountname = '"..getAccountName(acc).."'") i = i +1 end end end addEventHandler("onPlayerQuit", getRootElement(), savePlayerData) addEventHandler("onPlayerLogout", getRootElement(), savePlayerData) addEventHandler("onPlayerWasted", getRootElement(), savePlayerData) function login1(prev, account, autologin) local account = getPlayerAccount(source) local result = executeSQLQuery("SELECT slot FROM slot WHERE accountname='" .. getAccountName(account) .. "'") local result2 = executeSQLQuery("SELECT ammo FROM ammo WHERE accountname='" .. getAccountName(account) .. "'") if result and #result > 0 then --giveWeapon(source, result, result2) giveWeapon(source, result, tonumber(result2)) end outputDebugString(tostring(executeSQLInsert(slotT, "'0', '"..getAccountName(account).."'", "slot, accountname"))) outputDebugString(tostring(executeSQLInsert(ammoT, "'0', '"..getAccountName(account).."'", "ammo, accountname"))) end addEventHandler("onPlayerLogin", getRootElement(), login1) addEventHandler("onPlayerSpawn", getRootElement(), login1)
The_Ex Posted June 1, 2010 Posted June 1, 2010 No, it shouldn't. Learn to use google for fucks sake... for i=0,12 do end
Castillo Posted June 1, 2010 Author Posted June 1, 2010 No, it shouldn't. Learn to use google for sake... for i=0,12 do end ok, but it gives a error when trying to give weapon weapon.lua: Bad argument @ "giveWeapon" - Line: 35
KingMofo Posted June 1, 2010 Posted June 1, 2010 Instead of giveWeapon(source, result, tonumber(result2) Try giveWeapon(source, result[1]['slot'], result2[1]['ammo'])
Castillo Posted June 1, 2010 Author Posted June 1, 2010 Instead of giveWeapon(source, result, tonumber(result2) Try giveWeapon(source, result[1]['slot'], result2[1]['ammo']) this works but itsnt saving all weapons only saves player current weapon not all slots
DakiLLa Posted June 1, 2010 Posted June 1, 2010 As far as I know result[1]['slot'] is an outdated syntax. Use result[1].slot instead of.
Castillo Posted June 1, 2010 Author Posted June 1, 2010 As far as I know result[1]['slot'] is an outdated syntax. Use result[1].slot instead of. but still not saving all or loading them...
DakiLLa Posted June 1, 2010 Posted June 1, 2010 only saves player current weapon not all slots getPlayerWeapon has the 'slot' parameter server side only in 1.0.4 MTA version. I guess you are using an older version, so this function takes only current weapon.
Castillo Posted June 1, 2010 Author Posted June 1, 2010 only saves player current weapon not all slots getPlayerWeapon has the 'slot' parameter server side only in 1.0.4 MTA version. I guess you are using an older version, so this function takes only current weapon. oh i see, then if i use a 1.0.4 version beta will work?
KingMofo Posted June 1, 2010 Posted June 1, 2010 As far as I know result[1]['slot'] is an outdated syntax. Use result[1].slot instead of. It still works regardless if it's outdated.
Castillo Posted June 1, 2010 Author Posted June 1, 2010 Yes. i installed it and now dosnt even save his current
50p Posted June 1, 2010 Posted June 1, 2010 Yes. i installed it and now dosnt even save his current You can get all player weapons in client-side script and send them to the server with triggerServerEvent or you can use setElementData which can sync the data but is unsafe.
Castillo Posted June 1, 2010 Author Posted June 1, 2010 Yes. i installed it and now dosnt even save his current You can get all player weapons in client-side script and send them to the server with triggerServerEvent or you can use setElementData which can sync the data but is unsafe. well, a friend had this script using account data and worked all saving all without a client part so ?
50p Posted June 1, 2010 Posted June 1, 2010 So, you have a chance to make it work. I'm worried that cheaters' weapons aren't synced but getPedWeapon client-side will get these weapons and if you save them then they'll have "cheated" weapons saved. Maybe that's what he meant..
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