Forum

> > CS2D > Scripts > Portal Creator
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Portal Creator

29 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Portal Creator

francis007
BANNED Off Offline

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

alt Re: Portal Creator

Rainoth
Moderator Off Offline

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

alt Re: Portal Creator

Baloon
GAME BANNED Off Offline

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

alt Re: Portal Creator

Rainoth
Moderator Off Offline

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

alt Re: Portal Creator

Rainoth
Moderator Off Offline

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

alt Re: Portal Creator

Rainoth
Moderator Off Offline

Zitieren
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")

alt Re: Portal Creator

Baloon
GAME BANNED Off Offline

Zitieren
@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.
1× editiert, zuletzt 13.10.16 16:10:20

alt Re: Portal Creator

Rainoth
Moderator Off Offline

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

alt Re: Portal Creator

GeoB99
Moderator Off Offline

Zitieren
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')

alt Re: Portal Creator

Rainoth
Moderator Off Offline

Zitieren
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.
1× editiert, zuletzt 13.10.16 18:37:34

alt Re: Portal Creator

Rainoth
Moderator Off Offline

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

alt Re: Portal Creator

Cure Pikachu
User Off Offline

Zitieren
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
4× editiert, zuletzt 08.05.18 11:40:28
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht