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

cleanArea(frompos, topos) [Works just like source-clean]

Tufte

Member
Joined
Nov 19, 2007
Messages
652
Reaction score
24
Location
Norway
I have created a clean-function for lua. It is almost as fast as the source-clean, and it will not give errors when there is no tile on the area! It will only clean moveable items, and it will not remove creatures!

Why would you ever use this function when you already got it in source?

Well, first of all, source function dosent clean pz-zones, so this requires source edit.

Secondly, areas like temple and depot gets trashed maybe 10x faster than the rest of the map, so instead of cleaning the whole server every hour (which makes lag), you can use my function to clean only the depot and temple for I.E every 30 minutes, and clean the whole map every 3 hours!

Put this in your lib/function.lua
PHP:
function tileArea(fromPos, toPos, stack)
	-- Area iterator by Colandus, edit by Tufte for tiles
	local pos = {x=fromPos.x, y=fromPos.y-1, z=fromPos.z}
	return function()
		if (pos.y < toPos.y) then
			pos.y = pos.y+1
		elseif (pos.x <= toPos.x) then
			pos.y = fromPos.y
			pos.x = pos.x+1
		else
			pos.x = fromPos.x
			pos.y = fromPos.y
			pos.z = pos.z+1
		end
		if (pos.x <= toPos.x and pos.y <= toPos.y or pos.z < toPos.z) then
			if (stack == nil) then
				return pos
			else
				pos.stackpos = stack
				return pos, getTileThingByPos(pos)
			end
		end
	end
end

Then, you put the clean-function below the one you just added:

PHP:
function cleanArea(frompos, topos)
	for pos, thing in tileArea(frompos, topos, 0) do
		if thing.uid ~= 0 then
			pos.stackpos = 255
			while isCreature(getThingfromPos(pos).uid) ~= TRUE and getThingfromPos(pos).itemid > 0 and hasProperty(getThingfromPos(pos).uid, 6) == TRUE and getTileInfo(pos).house == FALSE do
				if getThingfromPos(pos).type ~= 0 then
					doRemoveItem(getThingfromPos(pos).uid, getThingfromPos(pos).type)
				else
					doRemoveItem(getThingfromPos(pos).uid, 1)
				end
			end		
		end
	end
end

Hope it gets handy
Would'nt mind rep+ ;)
 
Last edited:
damn weird noone made this before now! its very useful, now i can clean small areas without lagg and as often as i want :D thanks rep++
 
So this won't clean houses? which players has bought and drop thier items? And how do I make this in a /clean script?
 
Last edited:
Can anyone help how to add it to global events? :p
I don't know how to configure the positions in cleanArea(frompos, topos).
 
from 0.3.5 you can use something like this to clean area 3x3 for example:

Code:
for _, pos in ipairs(getArea({x = , y = , z = }, 3, 3) do
	doCleanTile(pos)
end
 
Back
Top