Dominatrix Posted February 15, 2013 Share Posted February 15, 2013 Hi! i have a script that i use to reload saved skins/weapons after death and set them when onPlayerSpawn has been called here is the function that will be called by onPlayerSpawn: function loadSkinWep () local serial = getPlayerSerial ( source ) local result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `serial` = '"..serial.."'") if result then while true do local row = mysql_fetch_assoc(result) if not row then break end timer1 = setTimer (setPedSkin, 2000, 1, source, row.skin) timer2 = setTimer (giveWeapon, 2000, 1, source, row.weaponid, row.weaponammo, true) break end end end the problem is, that when any other resource calls spawnPlayer, it triggers that script, when i want it to trigger only when spawn has been caused by death. example: admin menu skin set will "virtually respawn" the player, triggering the script. other function is working, that saves current skin after... well.. player enters a vehicle, as i didn't know any other functions to get it to work with. here is the function: function saveSkin () local serial = getPlayerSerial ( source ) local skin = getPedSkin ( source ) mysql_query ( database, "UPDATE `accounts` SET skin = ".. skin .." WHERE `serial` = '"..serial.."'") end can these functions be formatted some other way so they will work only when intended, like loadSkinWep gets called only when spawnPlayer is caused by death, and the saveskin gets called when skin has been changed Link to comment
Castillo Posted February 15, 2013 Share Posted February 15, 2013 When the player dies, you can get the data and insert it on a temp table, then when they spawn, if there's an index for that player, you give him the data and remove him from the table. To save the skin only when it changes, use the event: onElementModelChange Link to comment
Dominatrix Posted February 16, 2013 Author Share Posted February 16, 2013 can i get somehow working examples to get me started as i dont know that much about MTA scripting.. and onElementModelChange wont work with setPedSkin as far as i know.. so how i would go converting that? only replacing? Link to comment
Castillo Posted February 16, 2013 Share Posted February 16, 2013 It does trigger, also, use getElementModel and setElementModel, getPedSkin and setPedSkin are deprecated. Link to comment
Dominatrix Posted February 17, 2013 Author Share Posted February 17, 2013 i think i nailed it.. would this be correct? function loadSkinWep () local serial = getPlayerSerial ( source ) local result = mysql_query ( database ,"SELECT * FROM `tempdata` WHERE `serial` = '"..serial.."'") if result then while true do local row = mysql_fetch_assoc(result) if not row then break end timer1 = setTimer (setElementModel, 2000, 1, source, row.skin) timer2 = setTimer (giveWeapon, 2000, 1, source, row.weaponid, row.weaponammo, true) mysql_query( database, "DELETE FROM `tempdata` WHERE `serial` = '"..serial.."'" ) break end end end function saveSkin () local serial = getPlayerSerial ( source ) local skin = getElementModel ( source ) mysql_query ( database, "UPDATE `accounts` SET skin = ".. skin .." WHERE `serial` = '"..serial.."'") end function saveDeath () local serial = getPlayerSerial ( source ) local skin = getElementModel ( source ) local weaponid = getPedWeapon ( source ) local weaponammo = getPedTotalAmmo ( source ) local q = mysql_query(database,"SELECT * FROM `tempdata` WHERE `serial` = '".. serial .."'") if(mysql_num_rows(q) == 0) then mysql_query( database, "INSERT INTO tempdata ( `serial` , skin, weaponid, weaponammo ) VALUES ( '" .. serial .. "', " .. skin .. ", "..weaponid ..", ".. weaponammo .." )" ) end end addEventHandler ( "onPlayerJoin", getRootElement(), loadAccounts ) addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts ) addEventHandler ( "onPlayerSpawn", getRootElement(), loadSkinWep ) addEventHandler ( "onPlayerWasted", getRootElement(), saveDeath ) addEventHandler ( "onElementModelChange", getRootElement(), saveSkin ) Link to comment
Castillo Posted February 17, 2013 Share Posted February 17, 2013 The best way to know is to test it. Link to comment
Dominatrix Posted February 17, 2013 Author Share Posted February 17, 2013 i tested it in the end, and it did break the part where it is supposed to load the data on join/login, so it did not work at all.. here is the functions to load and save on join/quit: function saveAccounts () local serial = getPlayerSerial ( source ) local x,y,z = getElementPosition( source ) local i = getElementInterior( source ) local d = getElementDimension( source ) local skin = getElementModel ( source ) local money = getPlayerMoney ( source ) local health = getElementHealth ( source ) local armor = getPedArmor ( source ) local wanted = getPlayerWantedLevel ( source ) local weaponid = getPedWeapon ( source ) local weaponclip = getPedAmmoInClip ( source ) local weaponammo = getPedTotalAmmo ( source ) local q = mysql_query(database,"SELECT * FROM `accounts` WHERE `serial` = '".. serial .."'") if(mysql_num_rows(q) == 0) then mysql_query( database, "INSERT INTO accounts ( `serial` , x, y, z, intterior, demension, skin, money, health, armor, wanted, weaponid, weaponclip, weaponammo ) VALUES ( '" .. serial .. "', " .. x .. ", " .. y .. ", " .. z .. "," .. i .. ", " .. d .. "," .. skin .. "," .. money .. ", ".. health ..", ".. armor ..", " .. wanted .. ", weaponid = "..weaponid ..", weaponclip = ".. weaponclip ..", weaponammo = ".. weaponammo .." )" ) else res = mysql_query ( database, "UPDATE `accounts` SET x = ".. x ..", y = ".. y ..", z = ".. z ..", intterior = ".. i ..", demension = ".. d ..", skin = ".. skin ..", money = ".. money ..", health = ".. health ..", armor = ".. armor ..", wanted = ".. wanted ..", weaponid = ".. weaponid ..", weaponclip = ".. weaponclip ..", weaponammo = ".. weaponammo .." WHERE `serial` = '"..serial.."'") end end function loadAccounts () local serial = getPlayerSerial ( source ) local result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `serial` = '"..serial.."'") if result then while true do local row = mysql_fetch_assoc(result) if not row then break end setElementPosition ( source, row.x, row.y, row.z) setElementInterior ( source, row.intterior ) setElementDimension ( source, row.demension ) setElementModel ( source, row.skin ) setPlayerMoney ( source, row.money ) setElementHealth ( source, row.health) setPedArmor ( source, row.armor ) setPlayerWantedLevel ( source, row.wanted ) setTimer (giveWeapon, 2000, 1, source, row.weaponid, row.weaponammo, true) break end end end addEventHandler ( "onPlayerJoin", getRootElement(), loadAccounts ) addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts ) that will work fine IF i remove the death save and such. here are those functions: function loadSkinWep () local serial = getPlayerSerial ( source ) local result = mysql_query ( database ,"SELECT * FROM `tempdata` WHERE `serial` = '"..serial.."'") if result then while true do local row = mysql_fetch_assoc(result) if not row then break end timer1 = setTimer (setElementModel, 2000, 1, source, row.skin) timer2 = setTimer (giveWeapon, 2000, 1, source, row.weaponid, row.weaponammo, true) mysql_query( database, "DELETE FROM `tempdata` WHERE `serial` = '"..serial.."'" ) break end end end function saveSkinWep () local serial = getPlayerSerial ( source ) local skin = getElementModel ( source ) local weaponid = getPedWeapon ( source ) local weaponclip = getPedAmmoInClip ( source ) local weaponammo = getPedTotalAmmo ( source ) mysql_query ( database, "UPDATE `accounts` SET skin = ".. skin ..", weaponid = ".. weaponid ..", weaponclip = ".. weaponclip ..", weaponammo = ".. weaponammo .." WHERE `serial` = '"..serial.."'") end function saveDeath () local serial = getPlayerSerial ( source ) local skin = getElementModel ( source ) local weaponid = getPedWeapon ( source ) local weaponammo = getPedTotalAmmo ( source ) local q = mysql_query(database,"SELECT * FROM `tempdata` WHERE `serial` = '".. serial .."'") if(mysql_num_rows(q) == 0) then mysql_query( database, "INSERT INTO tempdata ( `serial` , skin, weaponid, weaponammo ) VALUES ( '" .. serial .. "', " .. skin .. ", "..weaponid ..", ".. weaponammo .." )" ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), loadSkinWep ) addEventHandler ( "onPlayerWasted", getRootElement(), saveDeath ) addEventHandler ( "onElementModelChange", getRootElement(), saveSkinWep ) with this attached, everything else works but not loading on join. i am probably missing something very simple but im not seeing it EDIT: this error started happening when loading on death: [2013-02-18 19:41:27] WARNING: datasaver1/datasaver.lua:24: Bad 'player' pointer @ 'getPlayerSerial'(1) [2013-02-18 19:41:27] WARNING: datasaver1/datasaver.lua:26: Bad 'ped' pointer @ 'getPedWeapon'(1) [2013-02-18 19:41:27] WARNING: datasaver1/datasaver.lua:27: Bad 'ped' pointer @ 'getPedAmmoInClip'(1) [2013-02-18 19:41:27] WARNING: datasaver1/datasaver.lua:28: Bad 'ped' pointer @ 'getPedTotalAmmo'(1) [2013-02-18 19:41:27] ERROR: datasaver1/datasaver.lua:30: attempt to concatenate local 'serial' (a boolean value) this error actually makes no sense to me probably due to not being able to script correctly 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