Forum

> > CS2D > Scripts > portal on the grown position
Forums overviewCS2D overview Scripts overviewLog in to reply

English portal on the grown position

14 replies
To the start Previous 1 Next To the start

old portal on the grown position

tontonEd
User Off Offline

Quote
hello

I was wondering how to get the position(x/y) of the blue and orange portal of a player(id) or a list of position from all active portal on the grown.
- combinaison of attack hook and projectiles seem not working.

old Re: portal on the grown position

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
addhook("attack","leattackhook")
function leattackhook(id)
	if player(id,"weapontype") == 88 then
		for k,v in pairs (object(0,"table")) do
			if v.type == 22 or v.type == 23 then
				msg("orange or blue portal belongs to "..v.player.." and is located at "..v.tilex.."|"..v.tiley)
			end
		end
	end
end

Try changing hook if "attack" doesn't work.

old Re: portal on the grown position

Rainoth
Moderator Off Offline

Quote
No that's lua.
Like say we have
1
MyTable = {something = 8, anotherthing = 2}
so we can call it
1
MyTable[1]
which is 8 or
1
MyTable.something
which is also 8
It works both ways.
I loop object table and get a table of ONE object (v). I then access type/player/etc. by just pointing with .whatIneed

v.x v.y v.player. v.type

old Re: portal on the grown position

Cure Pikachu
User Off Offline

Quote
@user Rainoth: cs2d lua cmd object(0,"table") returns a table of just object IDs, not a table of arrays because I got this error (Ignore the fact that I used server.lua, I am just using it to test a piece of code):
1
2
3
LUA ERROR: sys/lua/server.lua:113: attempt to index local 'v' (a number value)
-> sys/lua/server.lua:113: in function <sys/lua/server.lua:110>
-> in Lua hook 'attack', params: 1
Patched:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("attack","leattackhook")
addhook("attack2","leattackhook2")
function leattackhook(id)
	if player(id,"weapontype") == 88 then
		for k, v in pairs(object(0,"table")) do
			if object(v,"type") == 22 then
				msg(object(v,"typename").." belongs to "..player(object(v,"player"),"name").." and is located at "..object(v,"tilex").."|"..object(v,"tiley"))
			end
		end
	end
end
function leattackhook2(id)
	if player(id,"weapontype") == 88 then
		for k, v in pairs(object(0,"table")) do
			if object(v,"type") == 23 then
				msg(object(v,"typename").." belongs to "..player(object(v,"player"),"name").." and is located at "..object(v,"tilex").."|"..object(v,"tiley"))
			end
		end
	end
end
edited 2×, last 13.12.15 02:06:47 pm

old Re: portal on the grown position

Rainoth
Moderator Off Offline

Quote
@user Cure Pikachu: Ooops, didn't notice that. Been a while...
@user VADemon: Fairly sure in my example both would return the integer 8
I mean, it's true that MyTable[1] will return the variable and MyTable.something will return what the variable is equal to but in my example it does not make a difference cause you'd get the same result (8) in both ways.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview