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!
Scripts
Portal Creator
Portal Creator
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
Rainoth: To remove old hud, may be wrong, not pro at Lua.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
francis007:
Baloon's code and put it in that same notepad file
Rainoth I think you make a mistake on line 26
francis007:
? player(v[2],"name")
francis007: I thought you have some knowledge, here: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.
francis007: nice[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
Rainoth kinda messed up with the quotation within parse('hudtxt2 ' ...) . Replace the 26 line with this one and tell me if it works.parse('hudtxt2 0 ' .. id .. '\169255000000Created by ' .. v[2] .. ' ' .. rel_x .. ' ' .. rel_y .. ' 0')
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
_cldfunction can be improved further because of
objectat. Also
francis007 wanted it to display for the user only when the portal gun is equipped.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