-Doc- Posted January 15, 2016 Share Posted January 15, 2016 Hey, i have a problem with my experience and level saver. It saves only when i quit, but when i do /logout all my killing xp disappears and it returns to last xp i had when i logged in function onLogin (_,account) setElementData(source, "player.level", getAccountData(account, "level") or 1) setElementData(source, "player.experience", getAccountData(account, "experience") or 0) end addEventHandler ("onPlayerLogin", root, onLogin) function onLogout (_,account) setElementData(source, "player.level", 1) setElementData(source, "player.experience", 0) setElementData(source,"Rankicon","private") end addEventHandler ("onPlayerLogout", root, onLogout) function saveData(thePlayer, theAccount) local theAccount = getPlayerAccount(source) if (theAccount and not isGuestAccount(theAccount)) then setAccountData (theAccount, "level", getElementData(thePlayer, "player.level")) setAccountData (theAccount, "experience", getElementData(thePlayer, "player.experience")) end end addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) addEventHandler ("onPlayerLogout", root, function () saveData(source, getPlayerAccount(source)) end) Link to comment
Dealman Posted January 15, 2016 Share Posted January 15, 2016 Why do you have 2 onPlayerLogout handlers? You first reset it to default values and then you try and save the data with the other function. Link to comment
tosfera Posted January 15, 2016 Share Posted January 15, 2016 The first even that's being called is the first one in the file, which in this case is the function bound to this eventHandler: addEventHandler ("onPlayerLogout", root, onLogout) The best thing to do is to move the second event catcher you have inside the onLogout function. So move the saveData ( source, theAccount ) inside the onLogout function. Link to comment
-Doc- Posted January 15, 2016 Author Share Posted January 15, 2016 Still nothing. function savePlayerExp( player ) if ( player and isElement( player ) and getElementType( player ) == 'player' ) and ( getPlayerAccount( player ) and not isGuestAccount( getPlayerAccount( player ) ) ) then setAccountData ( getPlayerAccount( player ), "level", getElementData( player, 'player.level' ) ); setAccountData ( getPlayerAccount( player ), "experience", getElementData( player, 'player.experience' ) ); setAccountData ( getPlayerAccount( player ), "rank", getElementData( player, 'Rankicon' ) ); end end function loadPlayerExp( player ) if ( player and isElement( player ) and getElementType( player ) == 'player' ) then setElementData( player, 'player.level', getAccountData( getPlayerAccount( player ), "level") or 1 ); setElementData( player, 'player.experience', getAccountData( getPlayerAccount( player ), "experience") or 0 ); setElementData( player, 'Rankicon', getAccountData( getPlayerAccount( player ), "rank") or 0 ); end end addEventHandler ( 'onPlayerQuit', root, function( ) savePlayerExp( source ); end ); addEventHandler ( 'onPlayerLogin', root, function( ) loadPlayerExp( source ); end ) function onLogout (_,account) setElementData(source, "player.level", 1) setElementData(source, "player.experience", 0) setElementData(source,"Rankicon","private") savePlayerExp( source ) end addEventHandler ("onPlayerLogout", root, onLogout) Link to comment
tosfera Posted January 15, 2016 Share Posted January 15, 2016 You've placed your "savePlayerExp( source )" after resetting the information from the player, try it like this; function onLogout (_,account) savePlayerExp( source ) setElementData(source, "player.level", 1) setElementData(source, "player.experience", 0) setElementData(source,"Rankicon","private") end addEventHandler ("onPlayerLogout", root, onLogout) Link to comment
-Doc- Posted January 15, 2016 Author Share Posted January 15, 2016 The position matters? Link to comment
Chris!i! Posted January 15, 2016 Share Posted January 15, 2016 function onLogin (_,account) setElementData(source, "player.level", getAccountData(account, "level") or 1) setElementData(source, "player.experience", getAccountData(account, "experience") or 0) end addEventHandler ("onPlayerLogin", root, onLogin) function onLogout (_,account) saveData(account, "experience") saveData(account, "level") or 1) setElementData(source, "player.level", 1) setElementData(source, "player.experience", 0) setElementData(source,"Rankicon","private") end addEventHandler ("onPlayerLogout", root, onLogout) function saveData(thePlayer, theAccount) local theAccount = getPlayerAccount(source) if (theAccount and not isGuestAccount(theAccount)) then setAccountData (theAccount, "level", getElementData(thePlayer, "player.level")) setAccountData (theAccount, "experience", getElementData(thePlayer, "player.experience")) end end addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) addEventHandler ("onPlayerLogout", root, function () saveData(source, getPlayerAccount(source)) end) This maybe should work Link to comment
Dealman Posted January 15, 2016 Share Posted January 15, 2016 The position matters? Of course it does, you expect Lua to magically know what you want to happen? Link to comment
-Doc- Posted January 15, 2016 Author Share Posted January 15, 2016 I added this and still nothing. function onLogout (_,account) savePlayerExp( source ) setElementData(source, "player.level", 1) setElementData(source, "player.experience", 0) setElementData(source,"Rankicon","private") end addEventHandler ("onPlayerLogout", root, onLogout) I want to show by a video but youtube wont load. Link to comment
tosfera Posted January 17, 2016 Share Posted January 17, 2016 Try this approach; --[[ -- void:saveData -- Requires the player and it's account as a paramater to save -- the data from the player into the account. ]] function saveData ( thePlayer, theAccount ) if ( thePlayer and theAccount ) then if ( not isGuestAccount ( theAccount ) ) then setAccountData ( theAccount, "level", getElementData ( thePlayer, "player.level" ) ); setAccountData ( theAccount, "experience", getElementData ( thePlayer, "player.experience" ) ); end end end --[[ -- event:onPlayerLogin -- Once the event gets executed, the player will receive it's -- experience and level which is saved into it's account. ]] addEventHandler ( "onPlayerLogin", getRootElement(), function ( _, theAccount ) setElementData ( source, "player.level", getAccountData ( theAccount, "level" ) or 1 ); setElementData ( source, "player.experience", getAccountData ( theAccount, "experience" ) or 0 ); end ); --[[ -- event:onPlayerLogout -- Once the player logs out of their account, we still have -- the account and we should save the data. ]] addEventHandler ( "onPlayerLogout", getRootElement(), function ( theAccount ) saveData ( source, theAccount ); end ); --[[ -- event:onPlayerQuit -- A player can quit the game without being logged in, we -- should first check if the player is logged in. If so, -- save it's data. ]] addEventHandler ( "onPlayerQuit", getRootElement(), function () local theAccount = getPlayerAccount ( source ); if ( theAccount ) then saveData ( source, theAccount ); end end ); I've given a small documentation in the script itself too. Link to comment
-Doc- Posted January 17, 2016 Author Share Posted January 17, 2016 Thanks, it's working Link to comment
-Doc- Posted January 18, 2016 Author Share Posted January 18, 2016 Now i have another question, when im killing a team member i should not get xp by im getting heres the script addEventHandler( 'onPlayerWasted', root, function ( ammo, killer, killerweapon, bodypart ) if getPlayerTeam(killer) == getPlayerTeam(killer) then return true end if ( killer ) and ( killer ~= source ) then if bodypart == 9 then givePlayerExp( killer, math.random ( 300,500 ) ); else givePlayerExp( killer, math.random ( 100,300 ) ); end end end ); Link to comment
tosfera Posted January 18, 2016 Share Posted January 18, 2016 try this; addEventHandler( 'onPlayerWasted', root, function ( ammo, killer, killerweapon, bodypart ) if ( killer ) and ( killer ~= source ) then if ( getPlayerTeam ( source ) == getPlayerTeam ( killer ) ) then return end if bodypart == 9 then givePlayerExp( killer, math.random ( 300,500 ) ); else givePlayerExp( killer, math.random ( 100,300 ) ); end end end ); I've added the following line; if ( getPlayerTeam ( source ) == getPlayerTeam ( killer ) ) then return end and removed this line; if getPlayerTeam(killer) == getPlayerTeam(killer) then return true end Link to comment
-Doc- Posted January 18, 2016 Author Share Posted January 18, 2016 1 more question. I have the killmessages and i dont know what to edit to show correct image, when im killing someone with hydra it outputs weapon choosen from f1, and the victim its in a vehicle and i shoot him it shows he killed himself or blown image. Script: local vehicleIDs = { [50]=true,[49]=true,[31]=true,[38]=true,[52]=true,[21]=true,[19]=true,[51]=true} function KillMessages_onPlayerWasted ( totalammo, killer, killerweapon, bodypart ) ---These are special checks for certain kill types local usedVehicle if killerweapon == 19 and isElement(killer) then --rockets killerweapon = killer and getElementType ( killer ) == "player" and getPedWeapon(killer) if not killerweapon then killerweapon = 51 end elseif vehicleIDs[killerweapon] then --heliblades/rammed if ( isElement(killer) and getElementType ( killer ) == "vehicle" ) then usedVehicle = getElementModel ( killer ) killer = getVehicleOccupant ( killer, 0 ) end elseif ( usedVehicle and isElement(killer) ) then if ( getElementType ( killer ) == "player" ) then local vehicle = getPedOccupiedVehicle(killer) if ( vehicle ) then usedVehicle = getElementModel ( vehicle ) outputChatBox ( ""..getPlayerName(killer).."has killed"..getPlayerName(source).."by "..getElementModel(usedVehicle).."" ); end end end --finish this -- Got a killer? Print the normal "* X died" if not if ( killer and isElement(killer) and getElementType ( killer ) == "player" ) then local kr,kg,kb = getPlayerNametagColor ( killer ) if getPlayerTeam ( killer ) then kr,kg,kb = getTeamColor ( getPlayerTeam ( killer ) ) end -- Suicide? if (source == killer) then if not killerweapon then killerweapon = 255 end local triggered = triggerEvent ( "onPlayerKillMessage", source,false,killerweapon,bodypart ) --outputDebugString ( "Cancelled: "..tostring(triggered) ) if ( triggered ) then eventTriggered ( source,false,killerweapon,bodypart,true,usedVehicle) return end end local triggered = triggerEvent ( "onPlayerKillMessage", source,killer,killerweapon,bodypart ) --outputDebugString ( "Cancelled: "..tostring(triggered) ) if ( triggered ) then eventTriggered ( source,killer,killerweapon,bodypart,false,usedVehicle) end else local triggered = triggerEvent ( "onPlayerKillMessage", getRandomPlayer(),false,killerweapon,bodypart ) --outputDebugString ( "Cancelled: "..tostring(triggered) ) if ( triggered ) then eventTriggered ( source,false,killerweapon,bodypart,false,usedVehicle) end end end addEventHandler ( "onPlayerWasted", getRootElement(), KillMessages_onPlayerWasted ) 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