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

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,699
Solutions
408
Reaction score
3,812
Take a look at the blueberry bush script.

It spawns the berries on top of the bush, and the bush itself transforms into a regular bush for awhile before growing fruit again.
If I remember correctly, the decay/transform portion is done in items.xml

Is that what you were wanting?
 
OP
OP
R

rexgandi

Member
Joined
Oct 22, 2011
Messages
157
Reaction score
9
Take a look at the blueberry bush script.

It spawns the berries on top of the bush, and the bush itself transforms into a regular bush for awhile before growing fruit again.
If I remember correctly, the decay/transform portion is done in items.xml

Is that what you were wanting?

Hi, yes i look on blueberry bush.
But in server blueberry have two ID. Bush with blueberry and regular bush.
I need script with apples and use only one ID. I can't go to transform.
I have only one ID with this tree.

Maybe in script must use a stackpos ???
 

Silba

is stephany, the josh wife
Premium User
Joined
Aug 22, 2013
Messages
373
Solutions
8
Reaction score
287
Hi, yes i look on blueberry bush.
But in server blueberry have two ID. Bush with blueberry and regular bush.
I need script with apples and use only one ID. I can't go to transform.
I have only one ID with this tree.

Maybe in script must use a stackpos ???
I have a similar script for my server when players drink water where only 1 ID is available, what you need is storage.

If your script is currently fine except for the unlimited reuse then simply just add a storage check inside the onUse function.

Something like this

Lua:
local storage = 69420
local exhaust = 30 -- seconds
if player:getStorageValue(storage) - os.time() <= 0 then
    --your script to add apples here
    player:setStorageValue(storage, os.time() + exhaust)
else
    --you are exhausted, give the player a message or w.e
end
 
Last edited:

Michael 4463

Premium User
Premium User
Joined
Nov 15, 2007
Messages
778
Solutions
6
Reaction score
291
Location
Santiago, Chile (Australian)
Tested, works
Lua:
-- actions.xml
-- <action itemid="5157" script="mangotree.lua">

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local config = {
        foodId = 5097, -- food item ID
        foodCountMin = 1, -- food item count min
        foodCountMax = 3, -- food item count max
        growTimer = 5, -- 5 * 60, -- exhaust time
        growStorage = 1234, -- global storage value for the timer
        currentTime = os.time(), -- current time
        exhaustMessage = "They're not ripe yet!" -- message that displays if exhausted
    }
    growTime = Game.getStorageValue(config.growStorage)
    if not growTime then growTime = 0 end

    if config.currentTime >= growTime  then
        Game.createItem(config.foodId, math.random(config.foodCountMin, config.foodCountMax), fromPosition)
        Game.setStorageValue(config.growStorage, config.currentTime + config.growTimer)
        else
        player:sendTextMessage(MESSAGE_INFO_DESCR, config.exhaustMessage)
    end

    return true
end
 
Last edited:
OP
OP
R

rexgandi

Member
Joined
Oct 22, 2011
Messages
157
Reaction score
9
I have a similar script for my server when players drink water where only 1 ID is available, what you need is storage.

If your script is currently fine except for the unlimited reuse then simply just add a storage check inside the onUse function.

Something like this

Lua:
local storage = 69420
local exhaust = 30 -- seconds
if player:getStorageValue(storage) - os.time() <= 0 then
    --your script to add apples here
    player:setStorageValue(storage, os.time() + exhaust)
else
    --you are exhausted, give the player a message or w.e
end

Ok, I have storage in script, but i cant use aplles when create on tree (eat).
 

Gubailovo

Member
Joined
Dec 19, 2013
Messages
224
Solutions
1
Reaction score
18
Lua:
function onUse(cid, item, frompos, item2, topos)
 if item.itemid == 4006 then
      doTransformItem(item.uid,4008)
    doPlayerAddItem(cid,2675,7)
    doDecayItem(item.uid)
 end
return 1
    end
 
OP
OP
R

rexgandi

Member
Joined
Oct 22, 2011
Messages
157
Reaction score
9
Lua:
function onUse(cid, item, frompos, item2, topos)
 if item.itemid == 4006 then
      doTransformItem(item.uid,4008)
    doPlayerAddItem(cid,2675,7)
    doDecayItem(item.uid)
 end
return 1
    end

This script add Item to BP. I need create item on fromPosition, and only one ID, without decay.
 

RIPSoft

∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞∞
Joined
Jun 27, 2016
Messages
166
Reaction score
56
This is absolutely great. What Ive been looking for forever.. Ive literally had visions of these trees for years, this is the missing item in Tibia..
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,699
Solutions
408
Reaction score
3,812
Sorry for the delay.

There's no way to know when the fruit generated by the tree has been eaten, but we can set a respawn/grow timer on the tree?

Use tree -> get fruit -> wait 5 minutes -> Tree can be used again.

XML:
<action itemid="5157" event="script" value="foodSources.lua"/>
Lua:
local foodSources = {}
local foodSource = {
    [5157] = {food = 5097, min = 1, max = 3, respawnSeconds = 300},
    [1111] = {food = 1111, min = 1, max = 1, respawnSeconds = 11111},
    [1111] = {food = 1111, min = 1, max = 1, respawnSeconds = 11111}
}

local function covertPositionToString(position)
    local text = "x = " .. position.x
    text = text .. ", y = " .. position.y
    text = text .. ", z = " .. position.z
    return text
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local position = covertPositionToString(toPosition)
    if foodSources[position] and foodSources[position] > os.time() then
        doCreatureSay(cid, "Not ripe enough to harvest.\nWait awhile.", TALKTYPE_MONSTER)
        return true
    end
    foodSources[position] = os.time() + foodSource[item.itemid].respawnSeconds
    doCreateItem(foodSource[item.itemid].food, math.random(foodSource[item.itemid].min, foodSource[item.itemid].max), toPosition)
    return true
end
 

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
613
Solutions
12
Reaction score
77
Sorry for the delay.

There's no way to know when the fruit generated by the tree has been eaten, but we can set a respawn/grow timer on the tree?

Use tree -> get fruit -> wait 5 minutes -> Tree can be used again.

XML:
<action itemid="5157" event="script" value="foodSources.lua"/>
Lua:
local foodSources = {}
local foodSource = {
    [5157] = {food = 5097, min = 1, max = 3, respawnSeconds = 300},
    [1111] = {food = 1111, min = 1, max = 1, respawnSeconds = 11111},
    [1111] = {food = 1111, min = 1, max = 1, respawnSeconds = 11111}
}

local function covertPositionToString(position)
    local text = "x = " .. position.x
    text = text .. ", y = " .. position.y
    text = text .. ", z = " .. position.z
    return text
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local position = covertPositionToString(toPosition)
    if foodSources[position] and foodSources[position] > os.time() then
        doCreatureSay(cid, "Not ripe enough to harvest.\nWait awhile.", TALKTYPE_MONSTER)
        return true
    end
    foodSources[position] = os.time() + foodSource[item.itemid].respawnSeconds
    doCreateItem(foodSource[item.itemid].food, math.random(foodSource[item.itemid].min, foodSource[item.itemid].max), toPosition)
    return true
end
It does not work too as he wants. He ujebał sobie eat the fruit on the tree.
xd.gif
 
Top