• 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!

RevScripts Damage increase potion (TFS 1.3) REVSCRIPT

Brasilingos

New Member
Joined
Oct 25, 2020
Messages
13
Reaction score
1
Hi guys i created a damage boost potion but after player uses potion they dont have dmg boost. Can someone help me and find where is the solution?
TFS 1.3
Lua:
local DMGboostpotion = Action()

local DMGboostpotions = CreatureEvent("DMGboostpotions")

function DMGboostpotion.onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    if player:getStorageValue(18060) >= os.time() then
        player:say('You already have +10% dmg deals!', TALKTYPE_MONSTER_SAY)
        return true
    end

    player:setStorageValue(18060, os.time() + 86400)
    Item(item.uid):remove(1)
    player:say('Your 24 hours of +10% dmg deals has started!', TALKTYPE_MONSTER_SAY)
    return true
end


    function DMGboostpotions.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker:getStorageValue(18060) >= os.time() then
        if origin == ORIGIN_MELEE then
            creature:say("SKULLBASH!", TALKTYPE_MONSTER_SAY)
        elseif origin == ORIGIN_RANGED then
            creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
        end
        return primaryDamage * 1000, primaryType, secondaryDamage, secondaryType
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end


DMGboostpotion:id(12544)
DMGboostpotion:register()
DMGboostpotions:register()
 
You need to register the onHealthChange to the player/monsters receiving the damage

for players, you'd use a login method
for monsters, you'd either assign it into the monster file itself, or register the event using the onSpawn method
Lua:
local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("onHealthChange_EventName")
    return true
end

loginEvent:register()
 
You need to register the onHealthChange to the player/monsters receiving the damage

for players, you'd use a login method
for monsters, you'd either assign it into the monster file itself, or register the event using the onSpawn method
Lua:
local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("onHealthChange_EventName")
    return true
end

loginEvent:register()
Do you know maybe how to do to return back for the original player maxHealth after the time of boost is gone? This script is working but after time the hp are not returning to the normal but stays still in the boosted

Lua:
local HPboostpotion = Action()



function HPboostpotion.onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local ileHP = 10 -- w procentach
    if player:getStorageValue(18061) >= os.time() then
        player:say('You already have +10% HP Boost!', TALKTYPE_MONSTER_SAY)
        return true
    end

    player:setStorageValue(18061, os.time() + 15)
    local maxHealth = player:getMaxHealth()
    Item(item.uid):remove(1)
    player:say('Your 24 hours of +10% HP boost has started!', TALKTYPE_MONSTER_SAY)
    player:setMaxHealth(maxHealth * 1.1)
    return true

end





HPboostpotion:id(7477)
HPboostpotion:register()
 
You'd have to store the amount of health that the player gained in a storage value, and then do some sort of addEvent, I guess.

Something like this, should work

Lua:
local buffTime = 15 -- seconds
local maxHealthStorage = 11111
local damageBoostStorage = 18061


local function resetPlayer(playerId)
    local player = Player(playerId)
    if not player then
        return
    end
   
    local newMaxHealth = player:getMaxHealth() - player:getStorageValue(maxHealthStorage)
    player:setMaxHealth(newMaxHealth)
   
    player:setStorageValue(maxHealthStorage, -1)
    player:setStorageValue(damageBoostStorage, -1)
end


local HPboostpotion = Action()

function HPboostpotion.onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local ileHP = 10 -- w procentach
   
    if player:getStorageValue(damageBoostStorage) ~= -1 then
        player:say('You already have +10% HP Boost!', TALKTYPE_MONSTER_SAY)
        return true
    end

    player:setStorageValue(damageBoostStorage, os.time() + buffTime)
   
    Item(item.uid):remove(1)
    player:say('Your 24 hours of +10% HP boost has started!', TALKTYPE_MONSTER_SAY)
   
    local maxHealth = player:getMaxHealth()
    local newMaxHealth = maxHealth * 1.1
    local storedHealth = newMaxHealth - maxHealth
    player:setStorageValue(maxHealthStorage, storedHealth)
   
    player:setMaxHealth(newMaxHealth)
    addEvent(resetPlayer, 1000 * buffTime, player:getId())   
    return true
end

HPboostpotion:id(7477)
HPboostpotion:register()


local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("onHealthChange_EventName")
   
    local storageValue = player:getStorageValue(damageBoostStorage)
    if storageValue ~= -1 then
        local timer = storageValue > os.time() and storageValue - os.time() or 0
        addEvent(resetPlayer, timer, player:getId())   
    end
   
    return true
end

loginEvent:register()

Another alternative would be to not adjust their max health permanently, and instead use a temporary buff.
A quick search of the forums using "Spell that buffs max health temporarily" should find you some examples.
 
You must also register the event for monsters!
for that add an EventCallback:

example:
Lua:
local ec = EventCallback

function ec.onTargetCombat(creature, target)
    if creature and target then
        if creature:isPlayer() then
            target:registerEvent("SarahWesker_onHealthChange")
        end
    end
    return RETURNVALUE_NOERROR
end

ec:register(7)
 
Back
Top