someone help me with this error
tfs 1.3

tfs 1.3

LUA:
if not StatSystem then
StatSystem = {}
end
StatSystem.config = {
levels = {10000, 100000, 1000000, 2000000, 4000000}, -- predefined levels which give 1 point to player
effects = {getPoints = CONST_ME_TELEPORT, addMana = CONST_ME_TELEPORT, addHealth = CONST_ME_TELEPORT, addAttack = CONST_ME_TELEPORT},
message = "+1 Point",
storages = {
pointsBalance = 10000,
healthPoints = 10001,
manaPoints = 10002,
attackPoints = 10003,
nextLevel = 10004,
addedHealth = 10005,
addedMana = 10006,
},
}
function StatSystem.onAdvanceLevel(player, oldLevel, newLevel)
local nextLevel = player:getStorageValue(StatSystem.config.storages.nextLevel) == -1 and StatSystem.config.levels[1] or player:getStorageValue(StatSystem.config.storages.nextLevel)
if nextLevel > StatSystem.config.levels[#StatSystem.config.levels] then
return true
end
for index, level in ipairs(StatSystem.config.levels) do
if newLevel >= level and newLevel >= nextLevel and level >= nextLevel then
StatSystem.addPoints(player, 1)
player:say(StatSystem.config.message, TALKTYPE_MONSTER_SAY)
player:getPosition():sendMagicEffect(StatSystem.config.effects.getPoints)
player:setStorageValue(StatSystem.config.storages.nextLevel, StatSystem.config.levels[index + 1] or StatSystem.config.levels[#StatSystem.config.levels] + 1)
end
end
return true
end
function StatSystem.sendModalWindow(player)
player:registerEvent("StatSystemModal")
local modalwindow = ModalWindow(16556, "Stat System", "Welcome to stat system, your point balance is " .. math.max(0, player:getStorageValue(StatSystem.config.storages.pointsBalance)) .. ".")
modalwindow:addChoice(0, "Add 1% Health")
modalwindow:addChoice(1, "Add 1% Mana")
modalwindow:addChoice(2, "Add 1% Attack Damage")
modalwindow:addButton(0, "Confirm")
modalwindow:addButton(1, "Reset")
modalwindow:addButton(2, "Cancel")
modalwindow:setDefaultEnterButton(0)
modalwindow:setDefaultEscapeButton(2)
modalwindow:sendToPlayer(player)
end
function StatSystem.answerModal(player, modalId, buttonId, choiceId)
if modalId ~= 16556 then
return true
end
if buttonId == 0 then
if math.max(0, player:getStorageValue(StatSystem.config.storages.pointsBalance)) < 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have enough points.")
return true
end
if choiceId == 0 then
StatSystem.addPointToStat(player, "health", 1)
StatSystem.addPoints(player, -1)
local value = player:getMaxHealth() * 1 / 100
player:setMaxHealth(player:getMaxHealth() + value)
player:setStorageValue(StatSystem.config.storages.addedHealth, math.max(0, player:getStorageValue(StatSystem.config.storages.addedHealth)) + value)
player:getPosition():sendMagicEffect(StatSystem.config.effects.addHealth)
elseif choiceId == 1 then
StatSystem.addPointToStat(player, "mana", 1)
StatSystem.addPoints(player, -1)
local value = player:getMaxMana() * 1 / 100
player:setMaxMana(player:getMaxMana() + value)
player:setStorageValue(StatSystem.config.storages.addedMana, math.max(0, player:getStorageValue(StatSystem.config.storages.addedMana)) + value)
player:getPosition():sendMagicEffect(StatSystem.config.effects.addMana)
elseif choiceId == 2 then
StatSystem.addPointToStat(player, "attack", 1)
StatSystem.addPoints(player, -1)
player:getPosition():sendMagicEffect(StatSystem.config.effects.addAttack)
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You added one point to chosen stat.")
elseif buttonId == 1 then
-- reset all points
local spentPoints = math.max(0, player:getStorageValue(StatSystem.config.storages.healthPoints)) + math.max(0, player:getStorageValue(StatSystem.config.storages.manaPoints)) + math.max(0, player:getStorageValue(StatSystem.config.storages.attackPoints))
if spentPoints > 0 then
player:setMaxHealth(player:getMaxHealth() - math.max(0, player:getStorageValue(StatSystem.config.storages.addedHealth)))
player:setMaxMana(player:getMaxMana() - math.max(0, player:getStorageValue(StatSystem.config.storages.addedMana)))
player:setStorageValue(StatSystem.config.storages.addedHealth, 0)
player:setStorageValue(StatSystem.config.storages.addedMana, 0)
player:setStorageValue(StatSystem.config.storages.healthPoints, 0)
player:setStorageValue(StatSystem.config.storages.manaPoints, 0)
player:setStorageValue(StatSystem.config.storages.attackPoints, 0)
StatSystem.addPoints(player, spentPoints)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your stats were succesfully reset, your points were returned.")
end
end
player:unregisterEvent("StatSystemModal")
return true
end
function StatSystem.addPointToStat(player, statType, value)
if statType == "health" then
player:setStorageValue(StatSystem.config.storages.healthPoints, math.max(0, player:getStorageValue(StatSystem.config.storages.healthPoints)) + value)
elseif statType == "mana" then
player:setStorageValue(StatSystem.config.storages.manaPoints, math.max(0, player:getStorageValue(StatSystem.config.storages.manaPoints)) + value)
elseif statType == "attack" then
player:setStorageValue(StatSystem.config.storages.attackPoints, math.max(0, player:getStorageValue(StatSystem.config.storages.attackPoints)) + value)
end
return true
end
function StatSystem.removePointFromStat(player, statType, value)
if statType == "health" then
player:setStorageValue(StatSystem.config.storages.healthPoints, math.max(0, player:getStorageValue(StatSystem.config.storages.healthPoints)) - value)
elseif statType == "mana" then
player:setStorageValue(StatSystem.config.storages.manaPoints, math.max(0, player:getStorageValue(StatSystem.config.storages.manaPoints)) - value)
elseif statType == "attack" then
player:setStorageValue(StatSystem.config.storages.attackPoints, math.max(0, player:getStorageValue(StatSystem.config.storages.attackPoints)) - value)
end
return true
end
function StatSystem.addPoints(player, value)
player:setStorageValue(StatSystem.config.storages.pointsBalance, math.max(0, player:getStorageValue(StatSystem.config.storages.pointsBalance)) + value)
return true
end
function StatSystem.addAttackBonus(player, primary, secondary)
local attackPoints = math.max(0, player:getStorageValue(StatSystem.config.storages.attackPoints))
for i = 1, attackPoints do
primary = primary + (primary * 1 / 100)
secondary = secondary + (secondary * 1 / 100)
end
return primary, secondary
end