• 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 fromPosition (how use this with stackpos)

rexgandi

Member
Joined
Oct 22, 2011
Messages
189
Reaction score
9
Hello.
I try use function fromPosition when use a ID, create item fromPosition (apples)
But items create in the same stackpos (Plum Tree - stackpos = 1 , create apples the same stackpos = 1).
I cant eat apples on tree becouse when I use the same ID fromPosition, my script autmaticaly work.

BTW. Click on Plum Tree > poof and create apples on fromPosition, next I click on apples (eat) - not work, again creating next apples.

I need script - Click on Plum Tree, create apples on the same position and click again (eat apple) - no have aplles on the same position, again create a apples when click on plum tree.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == 2703 then
doCreateItem(2764, math.random(1, 3), fromPosition)
return true
end

This is my script. Work, create apples on tree but i can't eat.
 
And when you move this created apple out of tree position to inventory and then use there, it works?
Maybe you just dont have added 2764 in actions.xml and in others/food.lua table since 2764 is not standard id for apple
Lua:
[2674] = {6, "Yum."}, -- red apple
 
And when you move this created apple out of tree position to inventory and then use there, it works?
Maybe you just dont have added 2764 in actions.xml and in others/food.lua table since 2764 is not standard id for apple
Lua:
[2674] = {6, "Yum."}, -- red apple

On other position or in backpack work great, but dont work only when item create in the same position as plum tree.
(I use standard ID for Apples - Id in script is invalid).

Maybe has work with this, but code 100% have bad values.

Code:
local storage = 69420
local exhaust = 5 -- seconds
if player:getStorageValue(storage) - os.time() <= 0 then
if item.itemid == 2703 then
doCreateItem(2764, math.random(1, 3), fromPosition)
    player:setStorageValue(storage, os.time() + exhaust)
else
    --you are exhausted, give the player a message or w.e
    doRemoveItem(2764,1), fromPosition))
    doPlayer (cid,function with eat apples)
end
 
Last edited:
I mean both scripts you posted dont even suppose to run not mention work, do you have any errors in tfs console? you should have add something like this in actions.xml
Lua:
<action itemid="2703" script="yourscriptname.lua" />
and something like this in script
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storage = 69420
local exhaust = 1 -- seconds
if item.itemid == 2703 then
local getTimeStorage = player:getStorageValue(storage)
if getTimeStorage - os.time() <= 0 then
doCreateItem(2674, math.random(1, 3), fromPosition)
player:setStorageValue(storage, (os.time()+exhaust)) 
else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to wait ".. getTimeStorage  - os.time() .." seconds.")
end
end
return true
end
 
I mean both scripts you posted dont even suppose to run not mention work, do you have any errors in tfs console? you should have add something like this in actions.xml
Lua:
<action itemid="2703" script="yourscriptname.lua" />
and something like this in script
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storage = 69420
local exhaust = 1 -- seconds
if item.itemid == 2703 then
local getTimeStorage = player:getStorageValue(storage)
if getTimeStorage - os.time() <= 0 then
doCreateItem(2674, math.random(1, 3), fromPosition)
player:setStorageValue(storage, (os.time()+exhaust))
else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to wait ".. getTimeStorage  - os.time() .." seconds.")
end
end
return true
end

My scripts in OT work 100%, but have one problem - can't eat apples on ID2703. This is a TOP topic in this thread...
 
creating item by default should create apple on top of tree i assume your problem is that it is creating under the tree so you can check your dat/otb attributes as i remember there was something that specify if the item will be on top/bottom of stack or you can loop tree position with something like that
Lua:
function useFood(player,item,fullnes,words)
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and math.floor(condition:getTicks() / 1000 + (fullnes * 12)) >= 1200 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are full.")
    else
        player:feed(fullnes * 12)
        player:say(words, TALKTYPE_MONSTER_SAY)
        item:remove(1)
    end
    return true
    end



function onUse(cid, item, fromPosition, itemEx, toPosition)
local storage = 69420
local exhaust = 1 -- seconds
local eatWords = "working"
local fullnes = 6
local foodId = 2674
if item.itemid == 2703 then
local getTimeStorage = player:getStorageValue(storage)
if getTimeStorage - os.time() <= 0 then
doCreateItem(foodId, math.random(1, 3), fromPosition)
player:setStorageValue(storage, (os.time()+exhaust))
else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to wait ".. getTimeStorage  - os.time() .." seconds.")
end

for i,child in pairs(Tile(fromPosition):getItems()) do
if child.itemid == foodId then
useFood(player,child,fullnes,eatWords)
end
end

end
return true
end
wrote on website so check for errors
 
I wrote this for a request thread, it might be exactly what you need/want too:
From your request thread asking for pretty much the same thing:

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
ezgif.com-gif-maker (1).gif
 
Back
Top