• SendLua and chat.AddText problems
    12 replies, posted
I'm trying to make a little notifier to everybody when somebody respawns, but... Nothing happens. No lua errors on the client, nothing on the server... Just... nothing. I'm probably escaping improperly. [LUA]local function Appears( ply ) local name = ply:GetName() for _, v in pairs( Player.GetAll() ) do v:SendLua( "chat.AddText("..Color( 255, 255, 255 )..",\"A wild \","..Color( 255, 0, 0 )..","..name..","..Color( 255, 255, 255 )..",".."\" appears!\")" ) v:SendLua( "print(\"PlayerRespawnedDebug\")" ) end end hook.Add( "PlayerSpawn", "Appears!", Appears )[/LUA] Please help.
Two problems there. When using chat.AddText with SendLua, your Color arguments are a string as well. So, it would be as so: [code]v:SendLua( "chat.AddText( Color( 255, 255, 255 ) , \"A wild \",[/code] Second, it won't work if you put it in the wrong place. Where are you putting the code?
I've been working on a way to run chat.addtext from server.
[QUOTE=grea$emonkey;18396762]I've been working on a way to run chat.addtext from server.[/QUOTE] Something like a meta function but much better? Meta (Untested): [lua] local pmeta = FindMetaTable( "Player" ) // Usage p:AddText("AMIDOINITRITE?") function pmeta:AddText( txt ) self:SendLua( "chat.AddText(".. txt ..")" ) end [/lua]
That'd be no good, as the whole point of chat.AddText is to use color.
[QUOTE=jonney934;18396907]Something like a meta function but much better? Meta (Untested): [lua] local pmeta = FindMetaTable( "Player" ) function pmeta:AddText( txt ) self:SendLua( "chat.AddText(".. txt ..")" ) end [/lua][/QUOTE] Yeah, mine transfers colors.
[QUOTE=Entoros;18396930]That'd be no good, as the whole point of chat.AddText is to use color.[/QUOTE] Yeah, I don't know a whole lot about chat.AddText, I've never needed to use it yet, thanks for telling me.
[url]http://www.facepunch.com/showpost.php?p=15917714&postcount=1[/url]
[QUOTE=iRzilla;18404423]I just type into chat: ")RunConsoleCommand("quit[/QUOTE] Yeah, string injections :neckbeard:
So don't use what overv had in that other topic?
I don't see whats wrong with it. Or what rambo posted in that same thread either. If you have a message that is the same format each time you should just setup a usermessage. But if it can change in its formatting then I don't see why you wouldn't use them. They're just convenience functions really.
%q. Use it. [code] function SendText( pl, ... ) local t, k, v, s t = { ... } for k, v in ipairs( t ) do if type( v ) == "table" then if v.r and v.g and v.b then t[ k ] = string.format( "Color(%d,%d,%d,255)", tonumber( v.r ) or 255, tonumber( v.g ) or 255, tonumber( v.b ) or 255 ) end else t[ k ] = string.format( "%q", tostring( v ) ) end end s = "chat.AddText( %s )" pl:SendLua( s:format( table.concat( t, "," ) ) ) end [/code] Eg, iRzilla's injection could come out as: [code] chat.AddText( "A wild ",Color(255,0,0,255),"\")RunConsoleCommand(\"quit\"",Color(255,255,255,255),"has appeared!" ) [/code] Assuming var 2 was the user input.
Sorry, you need to Log In to post a reply to this thread.