VenomOG Posted March 13, 2019 Share Posted March 13, 2019 hey , so firstly thank you for looking at my problem and here is my problem so i have a level system and i want to make diffrent xp needed to level up example LEVELS = { [1] = 3000 [2] = 6000 }, see 1 need 3000 xp and 2 need 6000 xp Quote how can i make it like this i use data for levels example setElementData(source,"Level",etc) setElementData(source,"kill.level",etc) - xp Link to comment
XaskeL Posted March 13, 2019 Share Posted March 13, 2019 (edited) Test it please. I did not check this code, I wrote it directly in the editor without testing. I tried to find on the Internet already ready for 2014-2015, but I could not find it. -- enable OOP in meta.xml -- <oop>true</oop> -- Author: XaskeL. 13 mar., 2019 local levels = { [1] = 1000, -- EXP needed to get this level } local function getPlayerLevel() return localPlayer:getData('level') or 0 end local function getPlayerExp() return localPlayer:getData('exp') or 0 end local function getPlayerNext() local level = getPlayerLevel() local current = getPlayerExp() local next = levels[level + 1] return next-current end local function givePlayerExp(i) assert(type(i) == "number", "invalid argument type in function givePlayerExp. Was expected integer.") local level = getPlayerLevel() local current = getPlayerExp() local next = levels[level + 1] - current if current+i >= next then next = (current+i)-next localPlayer:setData('level', level + 1) localPlayer:setData('exp', next) else localPlayer:setData('exp', current + i) end return true end Edited March 13, 2019 by XaskeL Link to comment
Tekken Posted March 13, 2019 Share Posted March 13, 2019 (edited) Try this one You only have to change xpNeed in server.lua and client.lua (IT MUST HAVE THE SAME VALUE) Greetings! Edited March 13, 2019 by Tekken Link to comment
JeViCo Posted March 14, 2019 Share Posted March 14, 2019 (edited) @Knuck you can simply iterate through table function addXp(player, amount) local xp = getElementData(player, "XP") + amount -- move to new level for i, v in pairs (LEVELS) do if xp >= v then xp = v - xp -- if you need it ofc setElementData(player, "Level", xp) break end end setElementData(player, "XP", xp) end Edited March 14, 2019 by JeViCo 1 Link to comment
VenomOG Posted March 14, 2019 Author Share Posted March 14, 2019 1 hour ago, JeViCo said: @Knuck you can simply iterate through table function addXp(player, amount) local xp = getElementData(player, "XP") + amount -- move to new level for i, v in pairs (LEVELS) do if xp >= v then xp = v - xp -- if you need it ofc setElementData(player, "Level", xp) break end end setElementData(player, "XP", xp) end It goes to the needed xp the just breaks even when I added the rest levels 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