• 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
 
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.
console is not printing anything.
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
no ítem is printing, seems that i need a function or something.
 
Use this instead:
LUA:
<movevent type="AddItem" itemid="2579" event="script" value="trap.lua"/>

This way, the code will be fired even if the itemid "2579" is not a ground. Which it isn't. It is a moveable item, ontop of a ground. This way, through tile.cpp, it will fire the onItemMove function declared in movement.cpp

Let's see if this works.
 
Use this instead:
LUA:
<movevent type="AddItem" itemid="2579" event="script" value="trap.lua"/>

This way, the code will be fired even if the itemid "2579" is not a ground. Which it isn't. It is a moveable item, ontop of a ground. This way, through tile.cpp, it will fire the onItemMove function declared in movement.cpp

Let's see if this works.
I used to have problem whit the AddItem if you didnt have the tileitem="1"
but its always worth a try whitout it.
I need to point out that i use 0.3.6, so it might be different on 0.4
 
Can also try with tileitem="0". I understand from the sources, that tileitem is only fired for ground types. I might be wrong, though.
 
Use this instead:
LUA:
<movevent type="AddItem" itemid="2579" event="script" value="trap.lua"/>

This way, the code will be fired even if the itemid "2579" is not a ground. Which it isn't. It is a moveable item, ontop of a ground. This way, through tile.cpp, it will fire the onItemMove function declared in movement.cpp

Let's see if this works.
now it closes immediatly, not even an ítem over it (only ground below)
 
Try this:

LUA:
function onAddItem(moveitem, tileitem, position, cid)
   local npos = {x = position.x, y=position.y, z=position.z, stackpos=0}
   for i=0,252 do
     npos.stackpos = i
     local trap = getThingfromPos(npos)
     if trap.uid == moveitem.uid then
         break
     elseif trap.itemid == 2579 then
         doTransformItem(trap.uid, trap.itemid-1)
         doSendMagicEffect(position, CONST_ME_POFF)
     end
   end
   return true
end
This is highly unefficient and I don't recommend it. However, it will get the job done. If you have plenty of players dropping traps, it may lag the server.
An integrated C++ function would be better.
 
Back
Top