I need a script if a player use portal gun then other players see the player name who create the portal by pointing on the portal. I want it red and as a hudtxt. Thanks!
Forum
CS2D Scripts Portal CreatorPortal Creator
29 repliesI need a script if a player use portal gun then other players see the player name who create the portal by pointing on the portal. I want it red and as a hudtxt. Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
portals = {} addhook("build","_b") function _b(id,type,x,y,mode,objectid) 	if type == 21 or type == 22 then 		table.insert(portals,{objectid,id}) 	end end addhook("second","_s") function _s() 	for _, id in pairs (player(0,"tableliving")) do 		reqcld(id,2) 	end end addhook("clientdata","_cld") function _cld(id, mode, x, y) 	if mode == 2 then 		local tx = math.floor(x/32) 		local ty = math.floor(y/32) 		for k,v in pairs (portals) do 			if object(v[1],"tilex") == tx and object(v[1],"tiley") == ty then 				local rel_x = x - player(id, "x") - 320 				local rel_y = y - player(id, "y") - 240 				parse("hudtxt2 0 "..id.." "\169255000000Created by '..v[2]..'" "..rel_x.." "..rel_y.." 0") 			end 		end 	end end
Something like that. Mind that I don't remember and cbb to check how exactly to do the hud command with the single/double quotes and stuff. The position thingy might be wrong too but you never know. Everything else should be fine.
Change second hook to something else if you want more lag and faster response when you hover over the portals.
Now that I took a second look at it, this doesn't handle when portals disappear. So ask someone else to handle table.remove when a portal is built. I might do it myself later. Later.
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
addhook("attack","atk") addhook("attack2","atk") function atk(id) for k,v in ipairs(portals) do if id==v[2] and player(id,"weapontype")==88 then portals[k]={} end end end
See what I did there?
Step 1: Take my code and put it in a notepad file.
Step 2: Take Baloon's code and put it in that same notepad file
Step 3: Save the notepad file.
Congratulations! You got the full script
Quote
Mind that I don't remember and cbb to check how exactly to do the hud command with the single/double quotes and stuff.
You think ?
Just so you know v[1] returns object id and v[2] returns the id of player who made it.
So for example if you wanted name of player you'd go for
1
player(v[2],"name")
1
parse('hudtxt2 0 '..id..' "\169255000000Created by '..player(v[2],'name')..'" '..rel_x..' '..rel_y)
@ Rainoth: Eh, it's not only about quotation marks, you wrote
"Created by '..v[2]..'"v[2] returns an ID of portal builder, nor the name, so I fix it.
Edit: whatever, he knows it.
Edit: Also, considering this is a plugin script, change the hud id number.
edited 1×, last 13.10.16 04:10:20 pm
Have you considered telling us more than just "not work" so we know what exactly doesn't work? Is there an error? Cmon, you can't be that dense...
[17:16:04] LUA ERROR: sys/lua/test.lua:26: ')' expected near '\' [17:16:04] -> [C]: in function 'dofile' [17:16:04] -> sys/lua/server.lua:22: in main chunk
This is what you've got, it prevented the script to work. Reading from the Lua error, Rainoth kinda messed up with the quotation within
parse('hudtxt2 ' ...). Replace the 26 line with this one and tell me if it works.
1
parse('hudtxt2 0 ' .. id .. '\169255000000Created by ' .. v[2] .. ' ' .. rel_x .. ' ' .. rel_y .. ' 0')
// k. apparently build hook isn't triggered by portal gun. It should be if portals are considered to be buildings.
In other words none of this crap will work because of this. Guess I'll have to do it some other way. Gimme some time.
edited 1×, last 13.10.16 06:37:34 pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
addhook("ms100","_ms") function _ms() 	for _,id in pairs (player(0,"tableliving")) do 		reqcld(id,2) 	end end addhook("clientdata","_cld") function _cld(id,m,x,y) 	if m == 2 then 		for k,v in pairs (object(0,"table")) do 			if object(v,"type") == 22 or object(v,"type") == 23 and object(v,"tilex") == math.floor(x/32) and object(v,"tiley") == math.floor(y/32) then 				parse('hudtxt2 0 '..id..' "\169255000000Created by '..player(object(v,"player"),'name')..'" '..x-player(id,"x")+320 ..' '..y-player(id,"y")+240 ..' 0') 			else 				if objectat(math.floor(x/32),math.floor(y/32)) == 0 then 					parse('hudtxt2 0 '..id..' "" 0 0 0') 				end 			end 		end 	end end
Tested. Works.
_cldfunction can be improved further because of objectat. Also francis007 wanted it to display for the user only when the portal gun is equipped.
Also adjusted the offset so the text doesn't get blocked by the default crosshair at least.
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
addhook("clientdata","_cld") function _cld(id,m,x,y) 	if m == 2 then 		local tx, ty = math.floor(x/32), math.floor(y/32) 		local oid = math.max(objectat(tx,ty,22),objectat(tx,ty,23)) 		if oid > 0 and player(id,"weapontype") == 88 then 			parse('hudtxt2 '..id..' 0 "\169255000000Created by '..player(object(oid,"player"),'name')..'" '..x-player(id,"x")+324 ..' '..y-player(id,"y")+244 ..' 0') 		else 			parse('hudtxt2 '..id..' 0 "" 0 0 0') 		end 	end end
edited 4×, last 08.05.18 11:40:28 am