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

Check Item in Area

HeberPcL

[PowerOT.com.br]
Joined
Aug 21, 2007
Messages
1,294
Reaction score
54
Location
Brazil
GitHub
heberpcl
I'm trying to create a function to check if there is one item in a particular area.

config
PHP:
	area = {
		{fromx=202, fromy=254, fromz=5, tox=204, toy=256, toz=5}, -- Area 1
		{fromx=220, fromy=292, fromz=5, tox=222, toy=294, toz=5} -- Area 2
	}

Functions:
getTileItemById(pos, itemId[, subType = -1])
doRemoveItem(uid[, count = -1])



Can help?
 
try this
LUA:
function cleararea()
local cfg = {
	from_pos = {x = ,y = ,z = },
	to_pos = {x = ,y = ,z = },
	item_id = {id,count}
	}
	local room = {fromX = cfg.from_pos.x, toX = cfg.to_pos.x, fromY = cfg.from_pos.y, toY = cfg.to_pos.y, fromZ = cfg.from_pos.z, toZ = cfg.to_pos.z}
	for x = room.fromX, room.toX do
		for y = room.fromY, room.toY do
			for z = room.fromZ, room.toZ do
				for i = 1,6 do
					Thing = getThingFromPos({x = x, y = y, z = z, stackpos = i}, false)
					if Thing.itemid == cfg.item_id[1] then
						doRemoveItem(Thing.uid, cfg.item_id[2])
					end
				end
			end
		end
	end
end
 
Thanks SpiderOT,

i try ussing...

PHP:
function clearAreaNew(from, to, itemid)
    local room = {fromX = from.x, toX = to.x, fromY = from.y, toY = to.y, fromZ = from.z, toZ = to.z}
    for x = room.fromX, room.toX do
        for y = room.fromY, room.toY do
            for z = room.fromZ, room.toZ do
                EXE = getTileItemById({x = x, y = y, z = z}, itemid)
                if EXE.uid > 0 then
                    print("Clean!")
                    doRemoveItem(EXE.uid)
                end
            end
        end
    end
end

Don't Work. =\

Help Me, i can't fix.
 
Last edited by a moderator:
I found,
Link Ref: lib/Functions
PHP:
function getItemsInPos(items, pos) -- function by vodka
	local items = type(items) == "table" and items or {items}    
    local check = true 
    local t = {}
    for i = 1,#items do 
        t[i] = getThingFromPos({x=pos.x,y=pos.y,z=pos.z,stackpos=i}).itemid 
        if not table.find(items, t[i]) then 
            check = false 
			break 
        end 
    end 
	if check then 
		return true
	end 
	return nil 
end

function doRemoveItensInPos(items, pos) -- function by vodka
	local items = type(items) == "table" and items or {items}   
	for i = 1, table.maxn(items) do 
		doRemoveItem(getThingFromPos({x=pos.x,y=pos.y,z=pos.z,stackpos=1}).uid)
	end
	return nil
end
 

Similar threads

Back
Top