• 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 1.4.1+] Super Foods instantly heal

Sarah Wesker

ƐƖєgαηт Sуηтαx ❤
Staff member
TFS Developer
Support Team
Joined
Mar 16, 2017
Messages
1,407
Solutions
154
Reaction score
1,957
Location
London
GitHub
MillhioreBT
Twitch
millhiorebt
I saw this thread and it made me want to do it for current TFS with Revscript.

Here I leave the script.
data/scripts/superfoods.lua

Lua:
local superFoods = {
    [31944] = {
        hp = 1000,
        mana = 2000,
        hpPercent = 10,
        manaPercent = 10,
        removable = true, -- remove food when is used?
        exhaustedTime = 1000 * 3, -- 3 seconds
        says = "Aaahhh..."
    }
}

local exhausteds = {}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local food = superFoods[item.itemid]
    if not food then
        return false
    end

    local playerId = player:getId()
    local exhausted = exhausteds[playerId]
    if exhausted and os.mtime() < exhausted then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are exhausted.")
        return true
    end

    local playerHealth = player:getHealth()
    local playerMaxHealth = player:getMaxHealth()
    local playerMana = player:getMana()
    local playerMaxMana = player:getMaxMana()
    if playerHealth == playerMaxHealth and playerMana == playerMaxMana then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are already at full health and mana.")
        return true
    end

    local gainHp = 0
    if food.hp or food.hpPercent then
        if playerHealth < playerMaxHealth then
            gainHp = food.hp or 0
            gainHp = gainHp + (player:getMaxHealth() / 100 * (food.hpPercent or 0))
            gainHp = math.min(gainHp, playerMaxHealth - playerHealth)
            player:addHealth(gainHp)
        end
    end

    local gainMana = 0
    if food.mana or food.manaPercent then
        if playerMana < playerMaxMana then
            gainMana = food.mana or 0
            gainMana = gainMana + (player:getMaxMana() / 100 * (food.manaPercent or 0))
            gainMana = math.min(gainMana, playerMaxMana - playerMana)
            player:addMana(gainMana)
        end
    end

    if food.removable then
        item:remove(1)
    end

    if food.exhaustedTime then
        exhausteds[playerId] = os.mtime() + food.exhaustedTime
    end

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:say(food.says, TALKTYPE_MONSTER_SAY)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, string.format("You have been fed, You recover %s%s.", (gainHp > 0 and string.format("%d hit points", gainHp) or ""), (gainMana > 0 and string.format("%s%s", (gainHp > 0 and " and " or ""), string.format("%d mana points", gainMana)) or "")))
    return true
end

for id, _ in pairs(superFoods) do
    action:id(id)
end
action:register()
 
I saw this thread and it made me want to do it for current TFS with Revscript.

Here I leave the script.
data/scripts/superfoods.lua

Lua:
local superFoods = {
    [31944] = {
        hp = 1000,
        mana = 2000,
        hpPercent = 10,
        manaPercent = 10,
        removable = true, -- remove food when is used?
        exhaustedTime = 1000 * 3, -- 3 seconds
        says = "Aaahhh..."
    }
}

local exhausteds = {}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local food = superFoods[item.itemid]
    if not food then
        return false
    end

    local playerId = player:getId()
    local exhausted = exhausteds[playerId]
    if exhausted and os.mtime() < exhausted then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are exhausted.")
        return true
    end

    local playerHealth = player:getHealth()
    local playerMaxHealth = player:getMaxHealth()
    local playerMana = player:getMana()
    local playerMaxMana = player:getMaxMana()
    if playerHealth == playerMaxHealth and playerMana == playerMaxMana then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are already at full health and mana.")
        return true
    end

    local gainHp = 0
    if food.hp or food.hpPercent then
        if playerHealth < playerMaxHealth then
            gainHp = food.hp or 0
            gainHp = gainHp + (player:getMaxHealth() / 100 * (food.hpPercent or 0))
            gainHp = math.min(gainHp, playerMaxHealth - playerHealth)
            player:addHealth(gainHp)
        end
    end

    local gainMana = 0
    if food.mana or food.manaPercent then
        if playerMana < playerMaxMana then
            gainMana = food.mana or 0
            gainMana = gainMana + (player:getMaxMana() / 100 * (food.manaPercent or 0))
            gainMana = math.min(gainMana, playerMaxMana - playerMana)
            player:addMana(gainMana)
        end
    end

    if food.removable then
        item:remove(1)
    end

    if food.exhaustedTime then
        exhausteds[playerId] = os.mtime() + food.exhaustedTime
    end

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:say(food.says, TALKTYPE_MONSTER_SAY)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, string.format("You have been fed, You recover %s%s.", (gainHp > 0 and string.format("%d hit points", gainHp) or ""), (gainMana > 0 and string.format("%s%s", (gainHp > 0 and " and " or ""), string.format("%d mana points", gainMana)) or "")))
    return true
end

for id, _ in pairs(superFoods) do
    action:id(id)
end
action:register()
hello in tfs 1.4 it works? 7.72
 
It is better to ask before trying and wasting time, if you are looking for controversy why ask what a pity for you you did not make it good luck king.
Well, I disagree with you, it is better to try instead of asking because you would be "wasting time" from the person who dedicated time doing this script so you can have it free and without effort aside of copy-paste.

I get it, you are lazy, but there are limits to being lazy, at least try first, or do you want a batch file that automatically finds your server folder and add it as well?
Your logic is quite foolish you know, because you ended up testing it anyways, you "wasted time" asking, replying to Puncker and now reading this.
Joke is on you.
 
Well, I disagree with you, it is better to try instead of asking because you would be "wasting time" from the person who dedicated time doing this script so you can have it free and without effort aside of copy-paste.

I get it, you are lazy, but there are limits to being lazy, at least try first, or do you want a batch file that automatically finds your server folder and add it as well?
Your logic is quite foolish you know, because you ended up testing it anyways, you "wasted time" asking, replying to Puncker and now reading this.
Joke is on you.
Now say it but without crying xd, it's simple if I ask it's because it's an old version of Tibia and if it doesn't work why waste time sending screenshots of the error so that later they tell me no because your version won't work. It is simple and quick to understand if you do not achieve it, what a pity, but because it is premium, you are not right and the one above less so. And I'm not like that either, and if you don't like it, you have the problem. that you can't stand the ideals of others and if you come with a chair of ideals I'm not interested. good luck and thanks for the script works perfect.
 
Now say it but without crying xd, it's simple if I ask it's because it's an old version of Tibia and if it doesn't work why waste time sending screenshots of the error so that later they tell me no because your version won't work. It is simple and quick to understand if you do not achieve it, what a pity, but because it is premium, you are not right and the one above less so. And I'm not like that either, and if you don't like it, you have the problem. that you can't stand the ideals of others and if you come with a chair of ideals I'm not interested. good luck and thanks for the script works perfect.
Crying? Why should I be crying?
You'd need to test it first to have screenshots of an error but if you'd need to ask about a error when you'd clearly have the reason why it didn't work in this scenario, then you seriously gotta rethink of having a server when you need help to even identify such a error incase the version is not compatible.
And what if I am "Premium"? It has nothing to do with this, it is a way to support the forum you come to leech (and btw, do not support in any way than being a drama queen). I have no problem, it is my opinion and after all, I have the right to express it like everyone else.
Sadly the fix for the way you think won't be found here, good luck kid.
 
I saw this thread and it made me want to do it for current TFS with Revscript.

Here I leave the script.
data/scripts/superfoods.lua

Lua:
local superFoods = {
    [31944] = {
        hp = 1000,
        mana = 2000,
        hpPercent = 10,
        manaPercent = 10,
        removable = true, -- remove food when is used?
        exhaustedTime = 1000 * 3, -- 3 seconds
        says = "Aaahhh..."
    }
}

local exhausteds = {}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local food = superFoods[item.itemid]
    if not food then
        return false
    end

    local playerId = player:getId()
    local exhausted = exhausteds[playerId]
    if exhausted and os.mtime() < exhausted then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are exhausted.")
        return true
    end

    local playerHealth = player:getHealth()
    local playerMaxHealth = player:getMaxHealth()
    local playerMana = player:getMana()
    local playerMaxMana = player:getMaxMana()
    if playerHealth == playerMaxHealth and playerMana == playerMaxMana then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are already at full health and mana.")
        return true
    end

    local gainHp = 0
    if food.hp or food.hpPercent then
        if playerHealth < playerMaxHealth then
            gainHp = food.hp or 0
            gainHp = gainHp + (player:getMaxHealth() / 100 * (food.hpPercent or 0))
            gainHp = math.min(gainHp, playerMaxHealth - playerHealth)
            player:addHealth(gainHp)
        end
    end

    local gainMana = 0
    if food.mana or food.manaPercent then
        if playerMana < playerMaxMana then
            gainMana = food.mana or 0
            gainMana = gainMana + (player:getMaxMana() / 100 * (food.manaPercent or 0))
            gainMana = math.min(gainMana, playerMaxMana - playerMana)
            player:addMana(gainMana)
        end
    end

    if food.removable then
        item:remove(1)
    end

    if food.exhaustedTime then
        exhausteds[playerId] = os.mtime() + food.exhaustedTime
    end

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:say(food.says, TALKTYPE_MONSTER_SAY)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, string.format("You have been fed, You recover %s%s.", (gainHp > 0 and string.format("%d hit points", gainHp) or ""), (gainMana > 0 and string.format("%s%s", (gainHp > 0 and " and " or ""), string.format("%d mana points", gainMana)) or "")))
    return true
end

for id, _ in pairs(superFoods) do
    action:id(id)
end
action:register()
Nearly same i got for my Frutarian system :D nice work
 
Thanks for a great script. Would you wanna give any tips on how to make the exhaust time stay even if the character relogs? I put the CD to be 10 minutes, but if I relog it resets. Any tips? Also, how could I change it into giving for example +3 ml for 1 hour? :D Thanks again!
 
Thanks for a great script. Would you wanna give any tips on how to make the exhaust time stay even if the character relogs? I put the CD to be 10 minutes, but if I relog it resets. Any tips? Also, how could I change it into giving for example +3 ml for 1 hour? :D Thanks again!
change local playerId = player:getId() to local playerId = player:getGuid()
Note: in tfs 1.5 this problem does not exist if ALLOW_CLONES is false.
 
Back
Top