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

Solved TimedEvent, CreateItem and DestroyItem [TFS 1.1]

Ramirow

Veteran OT User
Joined
Aug 22, 2009
Messages
584
Solutions
15
Reaction score
301
Location
Argentina
YouTube
ramirogrant
Hello to everyone, I'm just trying to learn a bit about lua functions for TFS 1.1
I assume this kind of functions exist even tough I don't know how they are called or what parameters to pass..
I'm trying to create something like this:

1) You use a hammer and destroy an item with id A (Some rocks for example)
2) Then, after some seconds, let's say, 30. The rock is recreated again in the same position.
3) But ONLY if at the moment of creation there's not a player standing there.

I'm pretty confused in how to proceed, investigating some scripts that came with the server I've found target:transform() but it doesn't work quite well for what I'm trying to do.
I'm not asking for a complete script, only the functions and parameters involved in such tasks as I don't know them.

Thanks in advance!
 
Do you want it to transform into a different rock (like small ones as if it's broken) or be removed and created again?
To transform an item you can use this.
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L542
So that will be.
Code:
target:transform(newItemId)
To remove the item.
Code:
target:remove()

To create it back you can create a function and use it with addEvent.
Code:
addEvent(doCreateStone, 30 * 1000, toPosition, target.itemid)
How the function should look like depens on if it should be transformed or just created.
Code:
function doCreateStone(pos, itemid)
     Game.createItem(itemid, 1, pos)
end
If it should transform you can use
Code:
local tile = Tile(pos)
local item = tile:getItemById(itemid)
if item then
     item:transform(newItemId)
end
To check if there is a player you can use getTopCreature.
If it should create the stone later after that you can add addEvent in the doCreateStone function to execute it again.
Code:
if tile:getTopCreature() then
     return addEvent(doCreateStone, 30 * 1000, pos, itemid)
end
 
I've managed to go trough it and it works flawlessly! I will release the script once I finish it! :D
I tought it was going to be harder for me to pull it off, but it seems I was wrong.
Thanks a lot for the help sir Limos!
 
Back
Top