Forum

> > CS2D > Scripts > Check ID of tiles around player
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Check ID of tiles around player

2 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Check ID of tiles around player

Mami Tomoe
User Off Offline

Zitieren
Hello! I'm here for a small function that I need, it will check for the 8 tiles around a player (and the tile below the player making it 9 tiles) and check if their ID is equal to a specific ID.

I (think that I) can make it but I need it to be efficient because my script is huge.

This is a small example of the tiles it's supposed to check and the tile that the player is standing on.

IMG:https://i.imgur.com/Yit9cuF.png


This is an example of the function:
1
2
3
4
5
6
7
function NearTile(playerid, tileid)
	if (neartile) then
		return true
	else
		return false
	end
end

Thanks in advance.

alt Re: Check ID of tiles around player

Vehk
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
function checktiles(x, y, tileid)
	local results = {}

	x = x - 1
	y = y - 1
	for j = 0, 2 do
		for i = 0, 2 do
			local match = tile(x + i, y + j, "frame") == tileid
			results[j * 3 + i + 1] = match
		end
	end
	return results
end

This function will compare the tiles around the specified position and return the results as a table.

There are 9 tiles checked, a 3 by 3 area. The table indexes are mapped like this:

1 2 3
4 5 6
7 8 9


Where 5 is the index for the result at position X, Y.

If you want it to be more efficient you could unwrap the two loops

alt Re: Check ID of tiles around player

Mami Tomoe
User Off Offline

Zitieren
Thanks but someone already PM'd me a working function.

function NearTile(playerid, tileid)
	for x = player(playerid,"tilex") - 1, player(playerid,"tiley") + 1 do
		for y = player(playerid,"tiley") - 1, player(playerid,"tiley") + 1 do
			if ( x > -1 and y > -1 and tile(x, y, "frame") == tonumber(tileid) ) and ( x < map("sizex") and y < map("sizey") ) then
				return true
			end
		end
	end
	return false
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht