• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Removing items with game. TFS 1.2

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
Hello guys! Im trying to do a script that does the next:

Use tool only on X tile, and when you do so, an item is created.
After ,say, 24h another item is spawned and the previous item is deleted. (So they dont overlap)

I've got it working fine so far.. but i'm having problems deleting the item that is already there since there
isnt any game.removeItem or something like that.

Here's the code:

Code:
local seconds = 1       
local seconds2 = 10

function doCreateStone(pos, itemid)     
     local tile = Tile(pos)
     if tile:getTopCreature() then
     pos:sendMagicEffect(CONST_ME_POFF)
     return addEvent(doCreateStone, seconds * 1000, pos, 8640)
     else
       Game.createItem(8640, 1, pos)
       pos:sendMagicEffect(CONST_ME_MAGIC_RED)
     end
end
function doCreateStone2(pos, itemid) 
     local tile = Tile(pos)
     if tile:getTopCreature() then
     pos:sendMagicEffect(CONST_ME_POFF)
     return addEvent(doCreateStone2, seconds2 * 1000, pos, 8636)
     else
       Game.createItem(8636, 1, pos)
       pos:sendMagicEffect(CONST_ME_MAGIC_RED)
     end
end

local shards = {               
  [804] = {
  itemid = 8640,
  itemid2 = 8636
  }
}

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
  local player = type(cid) == 'number' and Player(cid) or cid
  if shards[target.itemid] then
         toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
         addEvent(doCreateStone, seconds * 1000, toPosition, target.itemid)
         addEvent(doCreateStone2, seconds2 * 1000, toPosition, target.itemid)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "XXXXXXX")
  return true
end
end

Thanks for your time guys!
 
You were not clear what you want, but here is a example how you can do it:

Code:
local function createItem(position, itemid)
    local item = Tile(position):getItemById(itemid)
    if item then -- If item exsist, lets remove it else create a new one
        item:remove()
    else
        Game.createItem(itemid, 1, position)
    end
end
       

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isInArray({8640, 8636}, target.itemid) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "XXXXXXX")
        addEvent(createItem, 1000, toPosition, target.itemid)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end

    return true
end
 
The remove part works perfect. But for some reason i dont understand at all.. the function doCreateStone it doesnt create the item :/
The red magic effect shows up 1 second after using it, but no item. After 10 seconds, the new item from the function createItem shows up.
Why? the hell if i know.. been testing around and got nothing :S

Code:
function doCreateStone(pos, itemid)
       local tile = Tile(pos)
       Game.createItem(8635, 1, pos)
       pos:sendMagicEffect(CONST_ME_MAGIC_RED)
     end

function createItem(pos, itemid)
    local tile = Tile(pos)
    local item = Tile(pos):getItemById(8635)
    if item then
        item:remove()
    else
        Game.createItem(8636, 1, pos)
        pos:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
  local player = type(cid) == 'number' and Player(cid) or cid
if isInArray({804}, target.itemid) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "XXXXXXX")
        addEvent(doCreateStone, 1000, toPosition, target.itemid)
        addEvent(createItem, 10000, toPosition, target.itemid)
        toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end

  return true

end
 
addEvent(doCreateStone, 1000, toPosition, target.itemid)
addEvent(createItem, 10000, toPosition, target.itemid)
addevent makes these functions execute 10000 milliseonds later, brah
 
Yeah i know that.. but the problem is that addEvent(doCreateStone, 1000, toPosition, target.itemid) only executes the animation part, there's no item created.
That what i dont understand why :/
 
the thing is that game.createItem works on the second addEvent :/ That why i dont understand why is not working correctly!
 
Back
Top