blackzinbolado
New Member
- Joined
- Nov 2, 2019
- Messages
- 2
- Reaction score
- 1
Hello, I'm trying to use this reset system in TFS 0.4 https://otland.net/threads/amendment-reset-system-otx-8-60 but I'm having this problem when I say !reset, could anyone help me adapt this script to TFS 0.4 please?
My Talkaction:
My Lib:
and I'm using the changes in the source for TFS 0.4 that are in the topic I mentioned
My Talkaction:
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
My Lib:
ResetSystem = {
storage = 14335,
back_to_level = 3500,
needed_level_per_reset = 1000,
max_count = 1000,
bonus_per_reset = {
experiencePercent = 10,
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: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:updateHealthAndMana(pid)
local bonus = self:getCurrentBonus(pid)
if (bonus) then
local message = "Você efetuou seu " .. self:getCount(pid) .. "° reset."
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
and I'm using the changes in the source for TFS 0.4 that are in the topic I mentioned