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

Help with Script (avesta)

armyman

Member
Joined
Feb 15, 2014
Messages
318
Reaction score
14
I need help with this "Spike Sword Rook' script, i want do if the character walk in special sqm, the item 2383 in Position x=32101,y=32085,z=7) is deleted
 
LUA:
-- <movevent type="StepIn" actionid="111111111111111111" event="script" value="aaaaaaaaaaaaaaaaaaaaaaaa.lua"/>

local item_position = {x = 32101, y = 32085, z = 7}
local item_id = 2383

-- my custom function
-- https://otland.net/threads/count-items-on-specific-tile.241788/#post-2341132
local function getItemCountOnPosition(item, pos)
   local item_pos = {x = pos.x, y = pos.y, z = pos.z}
   local item_count = 0
   for i = 1, 255 do
       local check_pos = {x = item_pos.x, y = item_pos.y, z = item_pos.z, stackpos = i}
       if getThingFromPos(check_pos).itemid <= 0 then
           break
       elseif getThingFromPos(check_pos).itemid == item then
           if isItemStackable(getThingFromPos(check_pos).itemid) == true then
               item_count = item_count + getThingFromPos(check_pos).type
           else
               item_count = item_count + 1
           end
       end
   end 
   return item_count
end

function onStepIn(cid, item, position, fromPosition)
   if not isPlayer(cid) then
       return true
   end
   if getItemCountOnPosition(item_id, item_position) >= 1 then
       doRemoveItem(getTileItemById(item_position, item_id).uid, 1)
   end
   return true
end

-- Edit
Ooops. Thought this was in requests.

Hopefully you find this helpful. :eek: :confused:
 
Last edited by a moderator:
:: Loading MoveEvents ...Error: [MoveEvent::configureMoveEvent] No valid event n
ame script
Warning: [BaseEvents::loadFromXml] Can not configure event

LUA:
local item_position = {x = 32101, y = 32085, z = 7}
local item_id = 2383

-- my custom function
-- https://otland.net/threads/count-items-on-specific-tile.241788/#post-2341132
local function getItemCountOnPosition(item, pos)
   local item_pos = {x = pos.x, y = pos.y, z = pos.z}
   local item_count = 0
   for i = 1, 255 do
       local check_pos = {x = item_pos.x, y = item_pos.y, z = item_pos.z, stackpos = i}
       if getThingFromPos(check_pos).itemid <= 0 then
           break
       elseif getThingFromPos(check_pos).itemid == item then
           if isItemStackable(getThingFromPos(check_pos).itemid) == true then
               item_count = item_count + getThingFromPos(check_pos).type
           else
               item_count = item_count + 1
           end
       end
   end  
   return item_count
end

function onStepIn(cid, item, position, fromPosition)
   if not isPlayer(cid) then
       return true
   end
   if getItemCountOnPosition(item_id, item_position) >= 1 then
       doRemoveItem(getTileItemById(item_position, item_id).uid, 1)
   end
   return true
end
 
Last edited by a moderator:
:: Loading MoveEvents ...Error: [MoveEvent::configureMoveEvent] No valid event n
ame script
Warning: [BaseEvents::loadFromXml] Can not configure event
It means your movements.xml line you added is not correct for your server.
Delete the line I provided for TFS 0.3.7 and replace for your avesta movements.xml lines
 
Now i got error when i move the character on "tile"

LUA:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/rookgaard/spikesword.lua:onStepIn

data/movements/scripts/rookgaard/spikesword.lua:11: attempt to call global 'getT
hingFromPos' (a nil value)
stack traceback:
        data/movements/scripts/rookgaard/spikesword.lua:11: in function 'getItem
CountOnPosition'
        data/movements/scripts/rookgaard/spikesword.lua:28: in function <data/mo
vements/scripts/rookgaard/spikesword.lua:24>
 
Back
Top