Forum

> > CS2D > Scripts > Compare location to table
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Compare location to table

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Compare location to table

Mami Tomoe
User Off Offline

Zitieren
Hi all!
I need a small help because I don't know how to do something in Lua!

I have this:
1
2
3
4
5
SPAWNS   = {
	FULLMAP    = {{0, 0}, {135, 208}},
	TOPHALF    = {{0, 0}, {74, 92}},
	BOTTOMHALF = {{0, 100}, {150, 249}},
}
HINT: IT HAS MORE INSIDE IT I JUST SHOWED THIS TO MAKE IT SHORT
And I'm planning to add more things inside it!

I want that to work on a function to find where is a player like that:
1
2
3
4
5
6
function getLocation(id)
	for k,v in pairs(SPAWNS) do
		
	end
	return "outOfMapBounds"
end
ANOTHER HINT: I THINK YOU NEED ANOTHER FOR INSIDE THE FOR
But I don't know how the IF should look like
Plz Help!

alt Re: Compare location to table

Gaios
Reviewer Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
function getLocation(id)
	local x, y = player(id, "tilex"), player(id, "tiley")
	
	for _, i in pairs(SPAWNS) do
		local x1, y1, x2, y2 = i[1][1], i[1][2], i[2][1], i[2][2]
		
		if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
			return _
		end
	end
	
	return "outOfMapBounds"
end

Also you did mistake in
SPAWNS
table, because locations are summing.

1× editiert, zuletzt 14.04.17 12:14:53
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht