• 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 Remove an due to an event

Sytoxian

New Member
Joined
Aug 19, 2010
Messages
40
Reaction score
1
Hey!
It's just a item that creates an item (id:289) if the ground tile is walkable. After this it shall be removed but nothing happens.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

if isWalkable(toPosition, false, true, true) then
     doCreateItem(289, 1, toPosition)
     addEvent(doRemoveItem, 5000, getThingFromPos(toPosition).uid, 1)
end
return true
end

function isWalkable(pos, creature, proj, pz)-- by Nord
if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
pos.stackpos = i
local tile = getTileThingByPos(pos)
if tile.itemid ~= 0 and not isCreature(tile.uid) then
if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
return false
end
end
end
return true
end

It does not work at all. I would be very grateful if somebody helps me.
 
Try this
Code:
  function isWalkable(pos, creature, proj, pz)-- by Nord
     local p = {x = pos.x, y = pos.y, z = pos.z, stackpos = 0}
     if getTileThingByPos(p).itemid == 0 then
       return false
     end
     if getTopCreature(p).uid > 0 and creature then -- this won't execute because the value passed to it is false
       return false
     end
     if getTileInfo(p).protection and pz then -- if this executes then false is returned and the true value is lost
       return false, true
     end
     local n = not proj and 3 or 2
     for i = 0, 255 do
       p.stackpos = i
       local tile = getTileThingByPos(p)
       if tile.itemid ~= 0 and not isCreature(tile.uid) then
         -- (CONST_PROP_BLOCKPROJECTILE / CONST_PROP_BLOCKPATHFIND) or CONST_PROP_BLOCKINGANDNOTMOVABLE
         if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
           return false
         end
       end
     end
     return true
   end
  
   function onUse(cid, item, fromPosition, itemEx, toPosition)
     if isWalkable(toPosition, false, true, true) then
        doCreateItem(289, 1, toPosition)
        addEvent(doRemoveItem, 5000, getThingFromPos(toPosition).uid, 1)
     end
     return true
   end
 
Last edited:
It caused this error:
Code:
[14/08/2015 15:41:19] [Error - Action Interface]
[14/08/2015 15:41:19] In a timer event called from:
[14/08/2015 15:41:19] data/actions/scripts/dynamite.lua:onUse
[14/08/2015 15:41:19] Description:
[14/08/2015 15:41:19] (luaDoRemoveItem) Item not found
actually its the same problem like before
 
instead of itemid it should be uid within isWalkable
Code:
      function isWalkable(pos, creature, proj, pz)-- by Nord
         local p = {x = pos.x, y = pos.y, z = pos.z, stackpos = 0}
         if getTileThingByPos(p).uid == 0 then
           return false
         end
         if getTopCreature(p).uid > 0 and creature then -- this won't execute because the value passed to it is false
           return false
         end
         if getTileInfo(p).protection and pz then -- if this executes then false is returned and the true value is lost
           return false, true
         end
         local n = not proj and 3 or 2
         for i = 0, 255 do
           p.stackpos = i
           local tile = getTileThingByPos(p)
           if tile.uid ~= 0 and not isCreature(tile.uid) then
             -- (CONST_PROP_BLOCKPROJECTILE / CONST_PROP_BLOCKPATHFIND) or CONST_PROP_BLOCKINGANDNOTMOVABLE
             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
               return false
             end
           end
         end
         return true
       end
    
       function onUse(cid, item, fromPosition, itemEx, toPosition)
         if isWalkable(toPosition, false, true, true) then
            doCreateItem(289, 1, toPosition)
            addEvent(doRemoveItem, 5000, getThingFromPos(toPosition).uid, 1)
         end
         return true
       end
 
Ok the problem is still not solved.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

function tileChecker(pos)
  local myTable = {}
  if (type(pos) == 'table') then
  for i = 1, 5 do
  pos.stackpos = i
  local thisID = getThingFromPos(pos).itemid
  if thisID > 1 then
  table.insert(myTable, thisID)
  end
  end
  end
  return #myTable > 0 and myTable or nil
end

local function findItem(pos, t)
  if (type(pos) == 'table' and type(t) == 'table') then
  for _i, i in ipairs(tileChecker(pos)) do
  if isInArray(t, i) then
  pos.stackpos = _i
  ret = getThingFromPos(pos).uid
  break
  end
  end
  end
  return ret
end

local function reCreate()
  doRemoveItem(findItem(toPosition, {289}))
end


if isWalkable(toPosition, false, true, true) then
doCreateItem(289, 1, toPosition)
addEvent(reCreate, 1 * 1000)
end
return true
end

function isWalkable(pos, creature, proj, pz)-- by Nord
local p = {x = pos.x, y = pos.y, z = pos.z, stackpos = 0}
if getTileThingByPos(p).uid == 0 then
return false
end
if getTopCreature(p).uid > 0 and creature then -- this won't execute because the value passed to it is false
return false
end
if getTileInfo(p).protection and pz then -- if this executes then false is returned and the true value is lost
return false, true
end
local n = not proj and 3 or 2
for i = 0, 255 do
p.stackpos = i
local tile = getTileThingByPos(p)
if tile.uid ~= 0 and not isCreature(tile.uid) then
-- (CONST_PROP_BLOCKPROJECTILE / CONST_PROP_BLOCKPATHFIND) or CONST_PROP_BLOCKINGANDNOTMOVABLE
if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
return false
end
end
end
return true
end

Everything works fine, but when I stand on the item 289, while it should be removed, I get the following error.

Code:
[17/08/2015 12:30:51] [Error - Action Interface]
[17/08/2015 12:30:51] In a timer event called from:
[17/08/2015 12:30:51] data/actions/scripts/dynamite.lua:onUse
[17/08/2015 12:30:51] Description:
[17/08/2015 12:30:51] (luaDoRemoveItem) Item not found

The error appears every time if something is placed on the item 289 in retrospect.
 
Hm, when I use
Code:
addEvent(doRemoveItem, 1 * 1000, getTileItemById(toPosition, 289).uid)
instead of
Code:
addEvent(reCreate, 1 * 1000)
it causes the same error (item not found)
 
You can't add it directly in addEvent because uids change, so you have to add the function doRemoveItem in a Lua made function that is called in addEvent like the function reCreate.
 
ok, done
it works fine!
thank you



For all who are interested:
Code:
function reCreate()
tnt = getTileItemById(toPosition, 289)
if tnt.itemid == 289 then
doRemoveItem(tnt.uid,1)
end
return TRUE
end
Code:
addEvent(reCreate,1 *1000)
 
Back
Top