• 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 0.3.7] Food on Tree

rexgandi

Member
Joined
Oct 22, 2011
Messages
189
Reaction score
9
Hello,
I create script - food on tree (etc. mango).
When I click, it keeps creating food on the tree.
What to do so that after creating food, it can be eaten and only after eating, for example, new ones can be created?



Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == 5157 then
doCreateItem(5097, math.random(1, 3), fromPosition)
return true
end
 
data/actions/scripts/mango.lua
Lua:
local exhausteds, config, MAX_FOOD = {}, {
    count = 2,
    itemId = 5097, -- Mango
    size = 48,
    says = "Yum.",
    exhaustedTime = 10, -- seconds
    exhaustedMessage = "They're not ripe yet!"
}, 1200
local function getFoodOnTree(pos)
    local food = getTileItemById(pos, config.itemId)
    if food.uid ~= 0 then
        return food
    end
end
function onUse(cid, item, fp, itemEx, toPosition)
    local food = getFoodOnTree(fp)
    if not food then
        local key = string.format("%d%d%d", fp.x, fp.y, fp.z)
        local exhausted = exhausteds[key] or 0
        if exhausted <= os.time() then
            doCreateItem(config.itemId, config.count, fp)
            exhausteds[key] = os.time() + config.exhaustedTime
            return true
        end
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, config.exhaustedMessage)
        return true
    end
    if(getPlayerFood(cid) + config.size > MAX_FOOD) then
        doPlayerSendCancel(cid, "You are full.")
        return true
    end
    doPlayerFeed(cid, config.size)
    doRemoveItem(food.uid, 1)
    doCreatureSay(cid, config.says, TALKTYPE_MONSTER)
    return true
end

GIF 28-11-2021 06-06-32 a. m..gif
The same script takes care of the food, since by default the action in the tree does not allow the default event of the food to be activated
 
Back
Top