Hi. Recently i have been trying to implement XP and levelling into the gamemode i am creating. I am able to assign the player their level as well as give them XP for doing damage to enemies which is currently damage done divided by two.
Basically the code works well however it is not very efficient meaning i will have to write hundreds of lines of code for each level doing it this way.
Does anyone have and ideas on how i can simplify this process and make the code more efficient?
Here is the xp values for each level
lvl1 = 0 lvl2 = 83 lvl3 = 174 lvl4 = 276 lvl5 = 388 lvl6 = 512 lvl7 = 650 lvl8 = 801 lvl9 = 969 lvl10 = 1154 lvl11 = 1358 lvl12 = 1584 lvl13 = 1833 lvl14 = 2107 lvl15 = 2411 lvl16 = 2746 lvl17 = 3115 lvl18 = 3523 lvl19 = 3973 lvl20 = 4470 lvl21 = 5018 lvl22 = 5624 lvl23 = 6291 lvl24 = 7028 lvl25 = 7842 lvl26 = 8740 lvl27 = 9730 lvl28 = 10824 lvl29 = 12031 lvl30 = 13363
This code is then using these values and checking them against their XP and tells me if they are above the level.
If i was to do this for every level as well as assign the player the actual level too. It would require a lot of lines of code. Is there a simpler way to do this?
function meta:addgunxp(amount) local currentxp = self:getgunxp() self:setgunxp( currentxp + amount ) end function meta:setgunxp(amount) self:SetNetworkedInt( "gunxp", amount ) self:savexp() end function meta:getgunxp() return self:GetNetworkedInt("gunxp") end function meta:checkxp() local currentxp = self:getgunxp() if currentxp > lvl1 then self:ChatPrint("above level 1") elseif currentxp > lvl20 then self:ChatPrint("above level 20") end end function meta:savexp() local xp = self:getgunxp() self:SetPData("gunxp", xp) end