Forum

> > CS2D > Scripts > Portal Creator
Forums overviewCS2D overview Scripts overviewLog in to reply

English Portal Creator

29 replies
Page
To the start Previous 1 2 Next To the start

old Portal Creator

francis007
BANNED Off Offline

Quote
Hey everyone!

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!

old Re: Portal Creator

Rainoth
Moderator Off Offline

Quote
Alright. Pretty good request to remember how to script with 'object' ^.o

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

old Re: Portal Creator

Baloon
GAME BANNED Off Offline

Quote
@user Rainoth: To remove old hud, may be wrong, not pro at Lua.
1
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

old Re: Portal Creator

Rainoth
Moderator Off Offline

Quote
@user francis007:
Step 1: Take my code and put it in a notepad file.
Step 2: Take user Baloon's code and put it in that same notepad file
Step 3: Save the notepad file.
Congratulations! You got the full script

old Re: Portal Creator

Rainoth
Moderator Off Offline

Quote
@user francis007:
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 ?

old Re: Portal Creator

Rainoth
Moderator Off Offline

Quote
Either escape the quotes with '\' or experiment with using " and ' in various places until it works. If I had to say, grab a random script with hud and see how it handles text with variables. Then basically write what you want to display in the same way.
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")

old Re: Portal Creator

Baloon
GAME BANNED Off Offline

Quote
@user francis007: I thought you have some knowledge, here:
1
parse('hudtxt2 0 '..id..' "\169255000000Created by '..player(v[2],'name')..'" '..rel_x..' '..rel_y)

@user 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

old Re: Portal Creator

Rainoth
Moderator Off Offline

Quote
@user francis007: nice
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...

old Re: Portal Creator

GeoB99
Moderator Off Offline

Quote
I can surely bet you put the script inside the autorun folder which for some reason the Console simply refuses to output any Lua errors. I recommend you to not do that.
[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, user 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')

old Re: Portal Creator

Rainoth
Moderator Off Offline

Quote
Right. Guess I'll have to get off my ass for once and test it myself. Brb.

// 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

old Re: Portal Creator

Rainoth
Moderator Off Offline

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

old Re: Portal Creator

Cure Pikachu
User Off Offline

Quote
The
_cld
function can be improved further because of cs2d lua cmd objectat. Also user 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
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
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview