jingzhi Posted June 20, 2015 Posted June 20, 2015 Help? levels = { 100, 200, 300, } maxlvl = 4 function givePlayerXP ( _,player) if not getElementData ( player, "xp" ) then setElementData(player,"xp",0) end if not getElementData(player,"level") then setElementData(player,"level",1) end local currXP = getElementData (player,"xp") local currLVL = getElementData(player,"level") setElementData(player,"xp",currXP + 10) if currLVL ~= 4 then if currXP >= levels[currLVL] then setElementData(player,"xp",getElementData(player,"xp") - levels[currLVL]) setElementData(player,"level",getElementData(player,"level") + 1) outputChatBox ("Rank up"..getElementData(player,"level"), player, 255, 25, 0, true) end end end addEventHandler("onPlayerWasted",root,givePlayerXP)
Walid Posted June 20, 2015 Posted June 20, 2015 Try this one untested levels = { [1] = 100, [2] = 200, [3] = 300, } maxlvl = 4 function givePlayerXP ( _,player) if isElement(player) and getElementType(player) == "player" then local currXP = getElementData (player,"xp") or 0 local currLVL = getElementData(player,"level") or 1 setElementData(player,"xp",currXP + 10) if currLVL < 4 then setElementData(player,"xp",currXP + levels[currLVL]) setElementData(player,"level",currLVL + 1) outputChatBox ("Rank up"..(currLVL+1), player, 255, 25, 0, true) end end end addEventHandler("onPlayerWasted",root,givePlayerXP)
jingzhi Posted June 20, 2015 Posted June 20, 2015 Not working levels = { 100, 200, 300, } maxlvl = 4 function givePlayerXP ( _,player) if not getElementData ( player, "xp" ) then setElementData(player,"xp",0) end if not getElementData(player,"level") then setElementData(player,"level",1) end local currXP = getElementData (player,"xp") local currLVL = getElementData(player,"level") setElementData(player,"xp",currXP + 10) outputChatBox ("+ 10 exp, current exp "..getElementData(player,"xp"), player, 255, 25, 0, true) if currLVL ~= 4 then if currXP >= levels[currLVL] then setElementData(player,"xp",getElementData(player,"xp") - levels[currLVL]) setElementData(player,"level",getElementData(player,"level") + 1) outputChatBox ("Rank up"..getElementData(player,"level"), player, 255, 25, 0, true) end end end addEventHandler("onPlayerWasted",root,givePlayerXP)
jingzhi Posted June 21, 2015 Posted June 21, 2015 This is my codeit wont work expToLevelUp = { [1] = "100", [2] = "300", } function givePlayerXP ( _,player) if not getElementData ( player, "xp" ) then setElementData(player,"xp",0) end if not getElementData(player,"level") then setElementData(player,"level",1) end local currXP = getElementData (player,"xp") local currLVL = getElementData(player,"level") setElementData(player,"xp",currXP + math.random(50,61)) if currLVL ~= 4 then if currXP >= expToLevelUp[currLVL] then setElementData(player,"xp",getElementData(player,"xp") - expToLevelUp[currLVL]) setElementData(player,"level",getElementData(player,"level") + 1) end end end addEventHandler("onPlayerWasted",root,givePlayerXP) Is there any error, how is it not working, and don't remove the outputChatBox because we can't see the problem without it
jingzhi Posted June 21, 2015 Posted June 21, 2015 This is my codeit wont work expToLevelUp = { [1] = "100", [2] = "300", } function givePlayerXP ( _,player) if not getElementData ( player, "xp" ) then setElementData(player,"xp",0) end if not getElementData(player,"level") then setElementData(player,"level",1) end local currXP = getElementData (player,"xp") local currLVL = getElementData(player,"level") setElementData(player,"xp",currXP + math.random(50,61)) if currLVL ~= 4 then if currXP >= expToLevelUp[currLVL] then setElementData(player,"xp",getElementData(player,"xp") - expToLevelUp[currLVL]) setElementData(player,"level",getElementData(player,"level") + 1) end end end addEventHandler("onPlayerWasted",root,givePlayerXP) Is there any error, how is it not working, and don't remove the outputChatBox because we can't see the problem without it Use numbers instead of strings in the table
jingzhi Posted June 22, 2015 Posted June 22, 2015 This will work. I wanna make when level up to exp be 0. exports.scoreboard:scoreboardAddColumn("ExP") exports.scoreboard:scoreboardAddColumn("Level") local levels = {[1] = 1, [50] = 2, [75] = 3, [240] = 4, [950] = 5, [1200] = 6, [2000] = 7, [5000] = 8, [9963] = 9, [20000] = 10, [100000] = 11} function win(ammo, killer, weapon, bodypart) if (killer and killer ~= source) then local H = getElementData(killer, "ExP") local S = getElementData(killer, "Level") local killer1 = getPlayerName(killer) local noob = getPlayerName(source) setElementData(killer, "ExP", tonumber(H)+math.random ( 5, 35 ) ) if levels[tonumber(H)] then setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." !") triggerClientEvent ( killer, "playSound", killer ) end end local H = getElementData ( source, "ExP" ) or 0 setElementData ( source, "ExP", tonumber ( H ) - math.random ( 5, 35 ) ) end addEventHandler( "onPlayerWasted", getRootElement(), win) function onLogin (_,account) setElementData(source, "Level", getAccountData(account, "lvl") or "Level 0 ") setElementData(source, "ExP", getAccountData(account, "exp") or "0") end addEventHandler ("onPlayerLogin", root, onLogin) function saveData(thePlayer, theAccount) if (theAccount and not isGuestAccount(theAccount)) then setAccountData (theAccount, "lvl", getElementData(thePlayer, "Level")) setAccountData (theAccount, "exp", getElementData(thePlayer, "ExP")) end end addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) I am not sure what you mean by working, but In my perspective this is not working, you need to have the exactly the same amount of exp with the exp of leveling up to lvl up
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