Forum

> > CS2D > Scripts > Compare location to table
Forums overviewCS2D overview Scripts overviewLog in to reply

English Compare location to table

4 replies
To the start Previous 1 Next To the start

old Compare location to table

Mami Tomoe
User Off Offline

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

old Re: Compare location to table

Gaios
Reviewer Off Offline

Quote
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.

edited 1×, last 14.04.17 12:14:53 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview