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

Lua TFS 1.3 - Eat a demon shield!

SorketROrk

Well-Known Member
Joined
Oct 14, 2020
Messages
152
Solutions
1
Reaction score
69
Location
Sweden
Hi :)

After looking around with no luck, for what I think should be a simple script I ask for your help!


Is it possible to click and "use" an item that would then dissapear on use and give player "food regeneration" but stronger?
Lets say I wanna eat a demon shield, that would then give me a faster regeneration tick or stronger tick amount?

My idea here is to have some type of food that is better than "average" when it comes to regeneration, It is not in my intention to actually eat the demon shield xD:)

All help is greatly appreciated!

Yours,
SRO
 
Solution
Lua:
local specialFoodTimeStor = 90000
local specialFoodIdStor = 90001
local specialFoodEvStor = 90002

local specialFoodConfig = {
    [5944] = {mana = 10, health = 10, time = 60 * 10, tick = 1, text = "You have eaten a soul orb, you will recharge 10 mana and health every second", foodEatSound = "crunch."}
}

local actionEvent = Action()
function actionEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item then
        local cfg = specialFoodConfig[item:getId()]
        player:setStorageValue(specialFoodTimeStor, os.time() + cfg.time)
        player:setStorageValue(specialFoodIdStor, item:getId())
        player:sendTextMessage(MESSAGE_INFO_DESCR, cfg.text)
        if cfg.foodEatSound then...
Last edited:
For the most part you can just add the item to food.lua script.
First, Register the item usage as an action and have it call the food.lua script otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/data/actions/actions.xml#L48)
Second, Add the item to food array in the script otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/data/actions/scripts/other/food.lua)
Hey

I have tried adding it as food, but how do I control the regeneration rate for the player that eats it to be faster than the rest of the food? :)
 
Actually quite a good question, I imagine this could be accomplished trough LUA somehow, by taking control over CONDITION_REGENERATION and adding hp/mana on an event function altough Idk how that will play out if player logged out..
Another way could be editing sources and adding a separate condition for special foods..
You should wait for someone experienced to comment on here, I feel I might be missing something and it could be done way easier..
 
Lua:
local foods = {
    --[item] = {[1]subID, [2]"sound", [3]hp per tick, [4]mana per tick, [5]How many seconds between hp tick, {6]How many seconds between mp tick} -- Guide
    [2666] = {1, "Munch.", 1, 1, 5, 10}, -- meat(lvl 1)
    [2671] = {1, "Chomp.", 2, 2, 5, 10}, -- ham(lvl 2)
    [2672] = {1, "Chomp.", 3, 3, 5, 10}, -- dragon ham(lvl 3)
    [21312] = {1, "Munch.", 4, 4, 5, 10}, -- venison(lvl 4)
    
    [2667] = {1, "Munch.", 1, 1, 10, 5}, -- fish(lvl 1)
    [7159] = {1, "Munch.", 2, 2, 10, 5}, -- green perch(lvl 2)
    [7158] = {1, "Munch.", 3, 3, 10, 5}, -- rainbow trout(lvl 3)
    
    
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local food = foods[item.itemid]
    if food == nil then
        return false
    end
    local foodCondition = Condition(CONDITION_REGENERATION)
    foodCondition:setParameter(CONDITION_PARAM_SUBID, food[1]) --(1)food, (2)mushrooms, (3)candy, (10)bodySkills
    foodCondition:setParameter(CONDITION_PARAM_TICKS, 10 * 60 * 1000)
    foodCondition:setParameter(CONDITION_PARAM_HEALTHGAIN, food[3])
    foodCondition:setParameter(CONDITION_PARAM_HEALTHTICKS, (food[5] * 1000))
    
    if player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
        --do nothing
        else
        foodCondition:setParameter(CONDITION_PARAM_MANATICKS, (food[6] * 1000))
        foodCondition:setParameter(CONDITION_PARAM_MANAGAIN, food[4])
    end
    player:addCondition(foodCondition)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Food effect updated.")
    player:say(food[2], TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    item:remove(1)
    return true
end

If you eat two different things with the same subID, the last one will be the active one. You also only need to eat 1x of the food then you will have the same effect as when you are "full" even if you can eat as many as you want.

You need to change the script to what you are after. But with this one i think you can figure our the rest.

This is an actionscript.

Hope it helps!
 
Lua:
local specialFoodTimeStor = 90000
local specialFoodIdStor = 90001
local specialFoodEvStor = 90002

local specialFoodConfig = {
    [5944] = {mana = 10, health = 10, time = 60 * 10, tick = 1, text = "You have eaten a soul orb, you will recharge 10 mana and health every second", foodEatSound = "crunch."}
}

local actionEvent = Action()
function actionEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item then
        local cfg = specialFoodConfig[item:getId()]
        player:setStorageValue(specialFoodTimeStor, os.time() + cfg.time)
        player:setStorageValue(specialFoodIdStor, item:getId())
        player:sendTextMessage(MESSAGE_INFO_DESCR, cfg.text)
        if cfg.foodEatSound then
            player:say(cfg.foodEatSound, TALKTYPE_MONSTER_SAY)
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        local evId = addEvent(doSpecialFood, cfg.tick*1000, player:getId())
        if player:getStorageValue(specialFoodEvStor) ~= -1 then
            stopEvent(player:getStorageValue(specialFoodEvStor))
        end
        player:setStorageValue(specialFoodEvStor, evId)
        item:remove(1)
    end
    return true
end
for k,_ in pairs(specialFoodConfig) do
    actionEvent:id(k)
end
actionEvent:register()

function doSpecialFood(playerId)
    local player = Player(playerId)
    if player and player:getStorageValue(specialFoodTimeStor) >= os.time() then
        local foodId = player:getStorageValue(specialFoodIdStor)
        local cfg = specialFoodConfig[foodId]
        if not cfg then return false end

        if cfg.health then
            doTargetCombatHealth(0, player, COMBAT_HEALING, cfg.health, cfg.health)
        end
        if cfg.mana then
            doTargetCombatMana(0, player, cfg.mana, cfg.mana)
        end
        local evId = addEvent(doSpecialFood, cfg.tick*1000, playerId)
        player:setStorageValue(specialFoodEvStor, evId)
    end
end

local loginEvent = CreatureEvent("SpecialFoodLogin")
function loginEvent.onLogin(player)
    if player:getStorageValue(specialFoodTimeStor) >= os.time() and specialFoodConfig[player:getStorageValue(specialFoodIdStor)] then
        addEvent(doSpecialFood, specialFoodConfig[player:getStorageValue(specialFoodIdStor)].tick*1000, player:getId())
    end
    return true
end
loginEvent:register()
Done with revscript. It will also apply again after player log in. All you have to set is the storages you wish to use at the start of script and the config on specialFoodConfig.
*time and tick is in seconds

With this script if you eat any other special food it will replace the old one
 
Solution
Back
Top