Hi everyone
how Change Script Tfs-to Otx Like Resets System amendment every time get 3500 level Can get resets
<talkaction access="0-4" words="!reset" event="script" value="reset_system_talk.lua"/>
how Change Script Tfs-to Otx Like Resets System amendment every time get 3500 level Can get resets
LUA:
ResetSystem = {
storage = 14335,
back_to_level = 100,
needed_level_per_reset = 1000,
max_count = 1000,
bonus_per_reset = {
experiencePercent = 10,
damagePercent = 2.5,
healthAndManaGainPercent = 5
}
}
function ResetSystem:getCount(pid)
return math.max(0, (tonumber(getCreatureStorage(pid, self.storage)) or 0))
end
function ResetSystem:setCount(pid, count)
doCreatureSetStorage(pid, self.storage, count)
db.executeQuery("UPDATE `players` SET `reset` = '"..count.."' WHERE `id` = '"..getPlayerGUID(pid).."';")
end
function ResetSystem:addCount(pid)
db.executeQuery("UPDATE `players` SET `reset` = '".. (self:getCount(pid) + 1) .."' WHERE `id` = '"..getPlayerGUID(pid).."';")
self:setCount(pid, self:getCount(pid) + 1)
end
function ResetSystem:getCurrentBonus(pid)
local resets = math.min(self:getCount(pid), self.max_count)
if (resets > 0) then
local currentBonus = {}
for bonus, value in pairs(self.bonus_per_reset) do
currentBonus[bonus] = value * resets
end
return currentBonus
end
return nil
end
function ResetSystem:applyBonuses(pid)
local bonus = self:getCurrentBonus(pid)
if (bonus and bonus.damagePercent) then
setPlayerDamageMultiplier(pid, 1.0 + (bonus.damagePercent / 100.0))
else
setPlayerDamageMultiplier(pid, 1.0)
end
end
function ResetSystem:updateHealthAndMana(pid)
local bonus = self:getCurrentBonus(pid)
if (bonus and bonus.healthAndManaGainPercent) then
local vocationInfo = getVocationInfo(getPlayerVocation(pid))
if (vocationInfo) then
local oldMaxHealth = getCreatureMaxHealth(pid)
local oldMaxMana = getCreatureMaxMana(pid)
local level = getPlayerLevel(pid)
local totalHealth = (vocationInfo.healthGain * level)
local totalMana = (vocationInfo.manaGain * level)
local newMaxHealth = math.floor(totalHealth + (totalHealth * (bonus.healthAndManaGainPercent / 100)))
local newMaxMana = math.floor(totalMana + (totalMana * (bonus.healthAndManaGainPercent / 100)))
setCreatureMaxHealth(pid, newMaxHealth)
setCreatureMaxMana(pid, newMaxMana)
if (newMaxHealth > oldMaxHealth) then
doCreatureAddHealth(pid, newMaxHealth - oldMaxHealth)
elseif (newMaxHealth < oldMaxHealth) then
doCreatureAddHealth(pid, 1) -- evita barra bugada
end
if (newMaxMana > oldMaxMana) then
doCreatureAddMana(pid, newMaxMana - oldMaxMana)
elseif (newMaxMana < oldMaxMana) then
doCreatureAddMana(pid, 1)
end
end
end
end
function ResetSystem:execute(pid)
self:addCount(pid)
local playerLevel = getPlayerLevel(pid)
if (playerLevel > self.back_to_level) then
doPlayerAddExperience(pid, getExperienceForLevel(self.back_to_level) - getPlayerExperience(pid))
playerLevel = self.back_to_level
end
self:applyBonuses(pid)
self:updateHealthAndMana(pid)
local bonus = self:getCurrentBonus(pid)
if (bonus) then
local message = "Voc� efetuou seu " .. self:getCount(pid) .. "� reset."
if (bonus.damagePercent) then
message = message .. "\n+" .. bonus.damagePercent .. "% de dano"
end
if (bonus.healthAndManaGainPercent) then
message = message .. "\n+" .. bonus.healthAndManaGainPercent .. "% de vida e mana"
local vocationInfo = getVocationInfo(getPlayerVocation(pid))
if (vocationInfo) then
local healthAndManaMultiplier = 1.0 + (bonus.healthAndManaGainPercent / 100.0)
local healthBonusSum = (vocationInfo.healthGain * playerLevel) * healthAndManaMultiplier
local manaBonusSum = (vocationInfo.manaGain * playerLevel) * healthAndManaMultiplier
setCreatureMaxHealth(pid, healthBonusSum)
setCreatureMaxMana(pid, manaBonusSum)
doCreatureAddHealth(pid, healthBonusSum)
doCreatureAddMana(pid, manaBonusSum)
end
end
if (bonus.experiencePercent) then
message = message .. "\n+" .. bonus.experiencePercent .. "% de EXP"
end
doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, message)
end
end
LUA:function onSay(cid, words, param, channel) if (param:lower() == "info") then local message = "~~~~~~~~~~Reset Infos ~~~~~~~~~~\n" local resetsCount = ResetSystem:getCount(cid) message = message .. "\nN�mero de Resets: " .. resetsCount .. "." local level = getPlayerLevel(cid) local vocationInfo = getVocationInfo(getPlayerVocation(cid)) local baseHealth, extraHealth local baseMana, extraMana local resetBonus = ResetSystem:getCurrentBonus(cid) if (resetBonus and vocationInfo) then baseHealth = vocationInfo.healthGain * level extraHealth = getCreatureMaxHealth(cid) - baseHealth baseMana = vocationInfo.manaGain * level extraMana = getCreatureMaxMana(cid) - baseMana else baseHealth, extraHealth = getCreatureMaxHealth(cid), 0 baseMana, extraMana = getCreatureMaxMana(cid), 0 end message = message .. "\nVida normal: " .. baseHealth .. " + " .. extraHealth .. "." message = message .. "\nMana normal: " .. baseMana .. " + " .. extraMana .. "." message = message .. "\nExp Stage Bon�s: " .. getExperienceStage(level) .. "x + " .. ((resetBonus and resetBonus.experiencePercent) or "0") .. "%." message = message .. "\nDamage Bon�s: " .. ((resetBonus and resetBonus.damagePercent) or "0") .. "%." message = message .. "\nProximo Reset: Lv" .. (resetsCount < ResetSystem.max_count and ((resetsCount + 1) * ResetSystem.needed_level_per_reset) or "0") .. "." doShowTextDialog(cid, 8983, message) else local position = getThingPosition(cid) local tileInfo = getTileInfo(position) if (tileInfo and not tileInfo.protection) then doPlayerSendCancel(cid, "Voc� s� pode usar esse comando em protection zone.") doSendMagicEffect(position, CONST_ME_POFF) return true end local resetsCount = ResetSystem:getCount(cid) if (resetsCount >= ResetSystem.max_count) then doPlayerSendCancel(cid, "Voc� j� atingiu o n�vel m�ximo de resets.") doSendMagicEffect(position, CONST_ME_POFF) return true end local levelNeeded = (resetsCount + 1) * ResetSystem.needed_level_per_reset if (levelNeeded > getPlayerLevel(cid)) then doPlayerSendCancel(cid, "Voc� precisa ser level " .. levelNeeded .. " ou maior.") doSendMagicEffect(position, CONST_ME_POFF) return true end ResetSystem:execute(cid) doSendMagicEffect(position, CONST_ME_TELEPORT) doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT) end return true end