• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X SetMaxHealth / Addlevel bug.

DukeeH

Active Member
Joined
Dec 6, 2010
Messages
550
Solutions
3
Reaction score
39
Hello,

I've made this function as a Rebirth:
Using TFS 0.3.7/OTX2.

Lua:
function resetPlayer(cid)
    if isSorcerer(cid) or isDruid(cid) then
        HpBonus = 350
        ManaBonus = 500
    else
        HpBonus = 500
        ManaBonus = 350
    end
    doPlayerRemoveMoney(cid, 100000000)
    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    
    local ResetHp = 185 + (getCreatureStorage(cid, HpStorage)*HpBonus)
    local ResetMana = 35 + (getCreatureStorage(cid, ManaStorage)*ManaBonus)

    repeat
        doPlayerAddLevel(cid, -(getPlayerLevel(cid) - 8))
        setCreatureMaxHealth(cid, ResetHp)
        setCreatureMaxMana(cid, ResetMana)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
        doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    until getPlayerLevel(cid) == 8
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Agora você tem " .. getCreatureStorage(cid, ResetsStorage) .. " " .. (getCreatureStorage(cid, ResetsStorage) == 1 and "reset" or "resets") .. ".\n\nReset Stats:\nHealth: +" .. getCreatureStorage(cid, HpStorage)*HpBonus .. " (" .. getCreatureStorage(cid, HpStorage) .. "x)\nMana: +" .. getCreatureStorage(cid, ManaStorage)*ManaBonus .. " (" .. getCreatureStorage(cid, ManaStorage) .. "x)\nDodge: " .. getPlayerStorageValue(cid, 48902) .. " (" .. getCreatureStorage(cid, DodgeStorage) .. "x)\nCritical: " .. getPlayerStorageValue(cid, 48901) .. " (" .. getCreatureStorage(cid, CriticalStorage) .. "x)\nPoints: " .. getAccountPoints(cid) .. " (" .. getCreatureStorage(cid, PointsStorage) .. "x).")
    return true
end

But I was having problems that a guy rebirthed to level 17.
(I couldnt reproduce, I've tested it 20 times and it all worked okay to level 8.)
But then I've tried adding that until to see if it helps with level part, don't know if it's right, but I think worked.

But now a guy rebirth with wrong max hp (more than it should).
On my tests it worked normally.

How can i make sure that it don't fail?

I've test like 20 times and it worked, but sometimes the doPlayerAddLevel or the setCreatureMaxHealthbreaks.

Could you help me, or guide me in the right direction?
 
I think you should just remove all of their experience minus the experience to be level 8, in 1 big swoop.
Get rid of the while loop altogether.

That should solve all of the level issues.

After you've reset their level by removing experience, just set their hp / mana, send effects, send text and you're done.

That being said, your HpBonus and ManaBonus are both set as global variables currently, and could possibly mess with other scripts.
I'd highly suggest for you to make both of those local variables.
 
@Xikini
The thing with addlevel is sometimes it works, sometimes don't.
Will search for experience functions.
Same thing happents to max hp, sometimes it works okay but for some it breaks.
I don't know why.

About varibles, will change to local.
 
@Xikini
The thing with addlevel is sometimes it works, sometimes don't.
Will search for experience functions.
Same thing happents to max hp, sometimes it works okay but for some it breaks.
I don't know why.

About varibles, will change to local.
Lua:
function resetPlayer(cid)
    -- I assume that the money is checked before this function is activated
    -- remove reset cost and teleport to temple
    doPlayerRemoveMoney(cid, 100000000)
    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
   
    -- reset level
    local experienceToRemove = (getPlayerExperience(cid) - 4200) * -1
    doPlayerAddExperience(cid, experienceToRemove)
   
    -- set new character values
    local HpBonus = 500
    local ManaBonus = 350
    if isSorcerer(cid) or isDruid(cid) then
        HpBonus = 350
        ManaBonus = 500
    end
    local ResetHp = 185 + (getCreatureStorage(cid, HpStorage) * HpBonus)
    local ResetMana = 35 + (getCreatureStorage(cid, ManaStorage) * ManaBonus)
    setCreatureMaxHealth(cid, ResetHp)
    setCreatureMaxMana(cid, ResetMana)
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
   
    -- send effects and text
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Agora você tem " .. getCreatureStorage(cid, ResetsStorage) .. " " .. (getCreatureStorage(cid, ResetsStorage) == 1 and "reset" or "resets") .. ".\n\nReset Stats:\nHealth: +" .. getCreatureStorage(cid, HpStorage)*HpBonus .. " (" .. getCreatureStorage(cid, HpStorage) .. "x)\nMana: +" .. getCreatureStorage(cid, ManaStorage)*ManaBonus .. " (" .. getCreatureStorage(cid, ManaStorage) .. "x)\nDodge: " .. getPlayerStorageValue(cid, 48902) .. " (" .. getCreatureStorage(cid, DodgeStorage) .. "x)\nCritical: " .. getPlayerStorageValue(cid, 48901) .. " (" .. getCreatureStorage(cid, CriticalStorage) .. "x)\nPoints: " .. getAccountPoints(cid) .. " (" .. getCreatureStorage(cid, PointsStorage) .. "x).")
    doPlayerSave(cid)
    return true
end
 
Lua:
function resetPlayer(cid)
    -- I assume that the money is checked before this function is activated
    -- remove reset cost and teleport to temple
    doPlayerRemoveMoney(cid, 100000000)
    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  
    -- reset level
    local experienceToRemove = (getPlayerExperience(cid) - 4200) * -1
    doPlayerAddExperience(cid, experienceToRemove)
  
    -- set new character values
    local HpBonus = 500
    local ManaBonus = 350
    if isSorcerer(cid) or isDruid(cid) then
        HpBonus = 350
        ManaBonus = 500
    end
    local ResetHp = 185 + (getCreatureStorage(cid, HpStorage) * HpBonus)
    local ResetMana = 35 + (getCreatureStorage(cid, ManaStorage) * ManaBonus)
    setCreatureMaxHealth(cid, ResetHp)
    setCreatureMaxMana(cid, ResetMana)
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
  
    -- send effects and text
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Agora você tem " .. getCreatureStorage(cid, ResetsStorage) .. " " .. (getCreatureStorage(cid, ResetsStorage) == 1 and "reset" or "resets") .. ".\n\nReset Stats:\nHealth: +" .. getCreatureStorage(cid, HpStorage)*HpBonus .. " (" .. getCreatureStorage(cid, HpStorage) .. "x)\nMana: +" .. getCreatureStorage(cid, ManaStorage)*ManaBonus .. " (" .. getCreatureStorage(cid, ManaStorage) .. "x)\nDodge: " .. getPlayerStorageValue(cid, 48902) .. " (" .. getCreatureStorage(cid, DodgeStorage) .. "x)\nCritical: " .. getPlayerStorageValue(cid, 48901) .. " (" .. getCreatureStorage(cid, CriticalStorage) .. "x)\nPoints: " .. getAccountPoints(cid) .. " (" .. getCreatureStorage(cid, PointsStorage) .. "x).")
    doPlayerSave(cid)
    return true
end

Had to use removecreature + dbquery, because item hp bonuses and stuff breaks maxhealth and maxmana.
Thanks for the help, but I don't think it's posssible to do without this.
I just want to know if there any way to deequip player items? (all of it)
And send a bag with them to his backpack, or something like this.
 
get the item in each slot, remove it and create container and add the items inside it

getPlayerSlotItem(cid, slot)

SLOTS AVAILABLE :
Lua:
CONST_SLOT_FIRST = 1
CONST_SLOT_HEAD = CONST_SLOT_FIRST
CONST_SLOT_NECKLACE = 2
CONST_SLOT_BACKPACK = 3
CONST_SLOT_ARMOR = 4
CONST_SLOT_RIGHT = 5
CONST_SLOT_LEFT = 6
CONST_SLOT_LEGS = 7
CONST_SLOT_FEET = 8
CONST_SLOT_RING = 9
CONST_SLOT_AMMO = 10
CONST_SLOT_LAST = CONST_SLOT_AMMO
 
maybe some thing like this
Code:
    local id = getPlayerGUID(cid)
    doRemoveCreature(cid)
 db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 0, `healthmax` = " .. ResetHp .. ", `health` = " .. ResetHp .. ", `manamax` = " .. ResetMana .. ", `mana` = " .. ResetMana .. " WHERE `id` = "..id)
 
Back
Top