• 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 Open trap, preventing overstacks.

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
593
Solutions
2
Reaction score
64
Location
México
Hello, otlanders. i have this script. But i spot a possible abuse from stacking multiple traps in one sqm, how can i prevent that?

here is the script
LUA:
function onStepIn(cid, item, pos)
 if(item.itemid == 2579) then
  if(not isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -15, -30, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid - 1)
  end
 else
  if(isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -50, -100, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid + 1)
  end
 end
 return true
end
function onStepOut(cid, item, pos)
 doTransformItem(item.uid, item.itemid - 1)
 return true
end
function onRemoveItem(item, tile, pos)
 local thingPos = getThingPos(item.uid)
 if(getDistanceBetween(thingPos, pos) > 0) then
  doTransformItem(item.uid, item.itemid - 1)
  doSendMagicEffect(thingPos, CONST_ME_POFF)
 end
 return true
end
 
too tired to Think, can't you just use something like this?

LUA:
function onStepIn(cid, item, toPosition, fromPosition)
    toPosition.stackpos = 255
    if getTileThingByPos(toPosition).itemid == 2579 then
        return doTargetCombatHealth(0, getTopCreature(toPosition).uid, COMBAT_PHYSICALDAMAGE, isPlayer(cid) and -15 or -30, isPlayer(cid) and -30 or -100, CONST_ME_NONE), doTransformItem(item.uid, item.itemid == 2579 and 2578 or 2579)
    end
end
 
Last edited:
too tired to Think, can't you just use something like this?

LUA:
function onStepIn(cid, item, toPosition, fromPosition)
    toPosition.stackpos = 255
    if getTileThingByPos(toPosition).itemid == 2579 then
        return doTargetCombatHealth(0, getTopCreature(toPosition).uid, COMBAT_PHYSICALDAMAGE, isPlayer(cid) and -15 or -30, isPlayer(cid) and -30 or -100, CONST_ME_NONE), doTransformItem(item.uid, item.itemid == 2579 and 2578 or 2579)
    end
end

thanks for your help, but your script is not working, doest not do anything.
 
Add onAddItem.
When anyone put any item on trap, then close trap.
This way allow only one trap on top? :)
So how it might get done?
if onAddItem (pos, open trap) then
doTransformItem (pos, closed trap)

what do i have to write on 'pos'?

too tired to Think, can't you just use something like this?

LUA:
function onStepIn(cid, item, toPosition, fromPosition)
    toPosition.stackpos = 255
    if getTileThingByPos(toPosition).itemid == 2579 then
        return doTargetCombatHealth(0, getTopCreature(toPosition).uid, COMBAT_PHYSICALDAMAGE, isPlayer(cid) and -15 or -30, isPlayer(cid) and -30 or -100, CONST_ME_NONE), doTransformItem(item.uid, item.itemid == 2579 and 2578 or 2579)
    end
end

this script wont close trap or damage players/monsters. could anyone give some help?
 
Last edited by a moderator:
LUA:
function onAddItem(pos, item)
  doTransformItem(item.uid, some_item_id)
end
seems is not working. im using this script tho
LUA:
function onStepIn(cid, item, pos)
 if(item.itemid == 2579) then
  if(not isPlayer(cid)) or (isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -15, -30, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid - 1)
  end
 else
  if(isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -50, -100, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid - 1)
  end
 end
 return true
end
function onStepOut(cid, item, pos)
 doTransformItem(item.uid, item.itemid - 1)
 return true
end
function onStepIn(cid, item, pos)
 doTransformItem(item.uid, item.itemid - 1)
 return true
end
function onRemoveItem(item, tile, pos)
 local thingPos = getThingPos(item.uid)
 if(getDistanceBetween(thingPos, pos) > 0) then
  doTransformItem(item.uid, item.itemid - 1)
  doSendMagicEffect(thingPos, CONST_ME_POFF)
 end
 return true
end
function onAddItem(pos, item)
doTransformItem(item.uid, 2578)
end
 
seems is not working. im using this script tho
LUA:
function onStepIn(cid, item, pos)
 if(item.itemid == 2579) then
  if(not isPlayer(cid)) or (isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -15, -30, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid - 1)
  end
 else
  if(isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -50, -100, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid - 1)
  end
 end
 return true
end
function onStepOut(cid, item, pos)
 doTransformItem(item.uid, item.itemid - 1)
 return true
end
function onStepIn(cid, item, pos)
 doTransformItem(item.uid, item.itemid - 1)
 return true
end
function onRemoveItem(item, tile, pos)
 local thingPos = getThingPos(item.uid)
 if(getDistanceBetween(thingPos, pos) > 0) then
  doTransformItem(item.uid, item.itemid - 1)
  doSendMagicEffect(thingPos, CONST_ME_POFF)
 end
 return true
end
function onAddItem(pos, item)
doTransformItem(item.uid, 2578)
end
How You registered it in xml file?
Show snippet
 
Hello, otlanders. i have this script. But i spot a possible abuse from stacking multiple traps in one sqm, how can i prevent that?

here is the script
LUA:
function onStepIn(cid, item, pos)
 if(item.itemid == 2579) then
  if(not isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -15, -30, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid - 1)
  end
 else
  if(isPlayer(cid)) then
   doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -50, -100, CONST_ME_NONE)
   doTransformItem(item.uid, item.itemid + 1)
  end
 end
 return true
end
function onStepOut(cid, item, pos)
 doTransformItem(item.uid, item.itemid - 1)
 return true
end
function onRemoveItem(item, tile, pos)
 local thingPos = getThingPos(item.uid)
 if(getDistanceBetween(thingPos, pos) > 0) then
  doTransformItem(item.uid, item.itemid - 1)
  doSendMagicEffect(thingPos, CONST_ME_POFF)
 end
 return true
end

This should work

movements.xml
XML:
<movevent type="AddItem" tileitem="1" itemid="2579" event="script" value="trap.lua"/>

trap.lua script
LUA:
function onAddItem(moveitem, tileitem, position, cid)
   if moveitem.itemid == 2578 or moveitem.itemid == 2579 then
       local trap = getTileItemById(position, 2579)
       if getTileItemById(position, 2579).itemid == 2579 then
           doTransformItem(trap.uid, trap.itemid-1)
           doSendMagicEffect(position, CONST_ME_POFF)
       end
       return true
   end
end

Edit:
Updated the onAddItem script to only close if you throw an open or closed trap on an already open trap
 
Last edited:
This should work

movements.xml
XML:
<movevent type="AddItem" tileitem="1" itemid="2579" event="script" value="trap.lua"/>

trap.lua script
LUA:
function onAddItem(moveitem, tileitem, position, cid)
   if moveitem.itemid == 2578 or moveitem.itemid == 2579 then
       local trap = getTileItemById(position, 2579)
       if getTileItemById(position, 2579).itemid == 2579 then
           doTransformItem(trap.uid, trap.itemid-1)
           doSendMagicEffect(position, CONST_ME_POFF)
       end
       return true
   end
end

Edit:
Updated the onAddItem script to only close if you throw an open or closed trap on an already open trap

Thanks for your help, sir. but the bug is not fixed yet :/ still overstack traps.
 
Thanks for your help, sir. but the bug is not fixed yet :/ still overstack traps.
I did test it, and it was impossible to put more traps on the same sqm. Since the one that was on the sqm would close.
Not sure what you mean whit overstack then.

Edit:
I did test it on 0.3.6 but it should work on 0.4 aswell

Edit2:
If you meant that you can put items over the trap to hide it then try to use this inside your trap.lua
it should make the trap close when you push any item over an open trap
LUA:
function onAddItem(moveitem, tileitem, position, cid)
   local trap = getTileItemById(position, 2579)
   if trap.itemid == 2579 then
       doTransformItem(trap.uid, trap.itemid-1)
       doSendMagicEffect(position, CONST_ME_POFF)
   end
   return true
end
 
Last edited:
I did test it, and it was impossible to put more traps on the same sqm. Since the one that was on the sqm would close.
Not sure what you mean whit overstack then.

Edit:
I did test it on 0.3.6 but it should work on 0.4 aswell

Edit2:
If you meant that you can put items over the trap to hide it then try to use this inside your trap.lua
it should make the trap close when you push any item over an open trap
LUA:
function onAddItem(moveitem, tileitem, position, cid)
   local trap = getTileItemById(position, 2579)
   if trap.itemid == 2579 then
       doTransformItem(trap.uid, trap.itemid-1)
       doSendMagicEffect(position, CONST_ME_POFF)
   end
   return true
end
still not working :/
 
still not working :/
Thats strange can you test and see if the script its executed at all?
Simply put this print("Test") below this line
function onAddItem(moveitem, tileitem, position, cid)
then just throw any item over an open or closed trap
and check the server consol if it printed Test

Edit:
I cant find the distro you use on google do you mind linking where you found your tfs 0.4 rev 7441
 
Last edited:
Thats strange can you test and see if the script its executed at all?
Simply put this print("Test") below this line
function onAddItem(moveitem, tileitem, position, cid)
then just throw any item over an open or closed trap
and check the server consol if it printed Test
Edit:
I cant find the distro you use on google do you mind linking where you found your tfs 0.4 rev 7441

my bad, im using distro 3777, from fir3elemental (downloaded otland)
btw, i put print("Test")
and console wont print anything when i put an ítem with id 2579 over it
 
LUA:
function onAddItem(moveitem, tileitem, position, cid)
   print("Test")
   local trap = getTileItemById(position, 2579)
   if trap.itemid == 2579 then
       doTransformItem(trap.uid, trap.itemid-1)
       doSendMagicEffect(position, CONST_ME_POFF)
   end
   return true
end

Like this. And see if the console returns anything.
 
my bad, im using distro 3777, from fir3elemental (downloaded otland)
btw, i put print("Test")
and console wont print anything when i put an ítem with id 2579 over it
Check the post above.

Well you should not put the trap over an item you should put an item over the trap to make it run

Edit:
If you have teamviewer you can pm me and we can take a look at it live instead
 
Back
Top