Hello friends, I am trying to lower the level of the players in certain events. I have achieved it and with storage I store its previous level and return it to you when you leave the event or at the end of it. The problem I face is that when there are a considerable amount of players the script causes a few seconds of freeze. Could someone help me to optimize? Part of the code.
To remove the level
To re-add the level
Lua:
function getExpForLevel(level)
level = level - 1
return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
To remove the level
Lua:
local realLevel = player:getLevel()
if player:getStorageValue(PrivateWar.levelReduced) < 1 then
player:setStorageValue(PrivateWar.levelLimit, realLevel)
player:setStorageValue(PrivateWar.levelReduced, 1)
player:removeExperience(player:getExperience() - getExpForLevel(300), false)
end
To re-add the level
Lua:
local realLevel = player:getStorageValue(PrivateWar.levelLimit)
if player:getStorageValue(PrivateWar.levelReduced) == 1 then
player:setStorageValue(PrivateWar.levelReduced, 0)
player:addExperience(getExpForLevel(realLevel) - player:getExperience(), false)
end