I have a script that says when a player leaves in the chat but I am not sure where to put it. I want to add it to my server running TTT.
[LUA]function GM:PlayerDisconnected(ply)
chat.AddText(Color(255, 0, 0)(ply:Name()…“has left the server.”))
end[/LUA]
Thanks!
add it to cl_init.lua since chat.AddText is a client side function.
Put it in “lua/autorun/server” I have mine saved as ply_steamid.lua
function FirstSpawn( ply )
PrintMessage( HUD_PRINTTALK, ply:Nick().. " has connected with the SteamID: " ..ply:SteamID() )
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
function PlayerDisconnect( ply )
PrintMessage( HUD_PRINTTALK, ply:Nick().. " has disconnected with the SteamID: " ..ply:SteamID() )
end
hook.Add( "PlayerDisconnected", "playerDisconnected", PlayerDisconnect )
hook.Add("ChatText", "ChatText", function( filter, name, text )
if (filter == 0) then
chat.AddText(text, "Server:")
end
end)
Edit: Gets rated dumb for posting an entire file for someone -.- thank-you valid members of facepunch
Just curious, why did you hook ChatText after?
Richtofen and OP’s won’t work since chat.AddText is only available clientside, so you will need to use a net message.
[lua]
if CLIENT then
net.Receive( “chatAddText”, function()
local tab = net.ReadTable()
chat.AddText( unpack(tab) )
end )
return
end
AddCSLuaFile()
util.AddNetworkString( “chatAddText” )
chat = {}
function chat.AddText( … )
local args = {…}
if IsValid(args[1]) and args[1]:IsPlayer() then
local ply = table.remove(args, 1)
net.Start( “chatAddText” )
net.WriteTable( args )
net.Send( ply )
else
net.Start( “chatAddText” )
net.WriteTable( args )
net.Broadcast()
end
end[/lua]
I get what you guys mean about chat.AddText being client side, but could you please explain what a net message is? :downs: