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

isTrapped(cid), getThingsFromPos(pos [,except]), isTileBlocking(pos)

QuaS

Cykotitan Pwned =/
Joined
Sep 11, 2008
Messages
838
Reaction score
28
Location
Poland/ Wroclaw
I didn't relase anything last time so here we go. It's example of using my lua function : http://otland.net/f35/gettimesincelastmove-103625/

Lua:
PLAYER_NO_MOVE_MAX_TIME_TRAPPED = 5; -- example time, seconds.

function isTrapped(cid)
	local timee = getTimeSinceLastMove(cid);
	local bool = true;
	
	if (timee < PLAYER_NO_MOVE_MAX_TIME_TRAPPED*1000) then
		return false;
	end
	
	if(not getCreatureCondition(cid,CONDITION_INFIGHT)) then
		return false;
	end
	local player_pos = getCreaturePosition(cid);
	local count = 0;
	for ax = player_pos.x-1,player_pos.x+1 do
		for ay = player_pos.y-1, player_pos.y+1 do
			if((player_pos.x ~= ax or player_pos.y ~= ay) and not isTileBlocking({x=ax,y=ay,z=player_pos.z})) then
				return false;
			end
		end
	end
	return true;
end

function getThingsFromPos(pos, except)
	local table_, excl = {}, except or 0;
	local yea  = true;
	if(excl==0) then
		yea = false;
	end
	yea = true;
	for i=1,254 do
		pos.stackpos=i;
		local itemt = getThingFromPos(pos);
		if(itemt.itemid>0) then
			if(yea) then
				if(type(excl) == "table") then
					if(not isInArray(excl, itemt.itemid)) then
						table.insert(table_,itemt.uid);
					end
				else
					if(not (excl == itemt.itemid)) then
						table.insert(table_,itemt.uid);
					end
				end
			end		
		end
	end
	return #table_>0 and table_ or 0;
end

function isTileBlocking(pos, cid)
	cid = cid or false;
	local items = getThingsFromPos(pos);
	if(type(items) ~= "table") then
		return false;
	end
	for i=1,#items do
		if(isCreature(items[i])) then
			return true;
		elseif(hasProperty(items[i], 0) or hasProperty(items[i], 3)) then
			return true;
		end
	end
	if(getHouseFromPos(getThingPos(items[i])) and cid)then
		local hinfo = getHouseInfo(getHouseFromPos(getThingPos(items[i])));
		if(getPlayerGUID(cid) ~= hinfo.owner) then --not sure. hinfo.owner or hinfo['owner'];
			return true;
		end
	end
	return false;
end

@Down. Function isTrapped return true if you're trapped.
Function isTileBlocking return true if player cannot enter this tile.
Function getThingsFromPos is not optimized. It return table with items from this pos.
 
Last edited:
can you give more info about this ?
 
hmm, something like trap place switch handling here? xD
but I cannot see house tile check(just like in cipbia, if you stand next to open house door, even if you cannot enter "you are not trapped")
if it is here, can you show me where?
@down: still not perfect, can return true if you can enter the house, but better than cip one for sure ^^
 
Last edited:
Code:
function isTileBlocking(pos)
	local items = getThingsFromPos(pos);
	if(type(items) ~= "table") then
		return false;
	end
	for i=1,#items do
		if(isCreature(items[i])) then
			return true;
		elseif(hasProperty(items[i], 0) or hasProperty(items[i], 3)) then
			return true;
		[B][COLOR="red"]elseif(getHouseFromPos(getThingPos(items[i]))) then
			return true;[/COLOR][/B]
		end
	end
	return false;
end

Fast editing is not bad!

hmm, something like trap place switch handling here? xD
but I cannot see house tile check(just like in cipbia, if you stand next to open house door, even if you cannot enter "you are not trapped")
if it is here, can you show me where?
@down: still not perfect, can return true if you can enter the house, but better than cip one for sure ^^

I don't know anything about cip system. i made it while ago (like 3 months)
 
Last edited:
isn't there already a function to check if a tile is blocked? i'm pretty sure ^.^

and no need to use "count", enough with:
Lua:
	for ax = player_pos.x-1,player_pos.x+1 do
		for ay = player_pos.y-1, player_pos.y+1 do
			if(player_pos.x ~= ax or player_pos.y ~= ay
			and not isTileBlocking({x=ax,y=ay,z=player_pos.z})) then
				return false
			end
		end
	end
	return true;
 
isn't there already a function to check if a tile is blocked? i'm pretty sure ^.^

and no need to use "count", enough with:
Lua:
	for ax = player_pos.x-1,player_pos.x+1 do
		for ay = player_pos.y-1, player_pos.y+1 do
			if(player_pos.x ~= ax or player_pos.y ~= ay
			and not isTileBlocking({x=ax,y=ay,z=player_pos.z})) then
				return false
			end
		end
	end
	return true;

Actually You\re Wrong. Player's Trapped when he doesn't has any way out (all 8 tiles arround are blocking path). Either ur statement is Wrong ^^

Code:
if([B][COLOR="red"]([/COLOR][/B]player_pos.x ~= ax or player_pos.y ~= ay[B][COLOR="red"])[/COLOR][/B] and not isTileBlocking({x=ax,y=ay,z=player_pos.z})) then

:p.

Updated Script Which Checks if house belongs to you.
 
Last edited:
i am not wrong... if there's only 1 free tile then he's not blocked, which means we can return false once we find 1....... and you don't necessarily need those parentheses there
 
Last edited:
Back
Top