Last active
February 23, 2016 02:21
-
-
Save SunRed/891d974dbc619141b635 to your computer and use it in GitHub Desktop.
Small gmod script to make [dis-]connect messages a bit prettier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create shared ConVar | |
CreateConVar( "sv_connectsound", "1", FCVAR_REPLICATED ) | |
-- Sound used for [dis-]connect events | |
CreateConVar( "sv_connectsoundfile", "buttons/combine_button3.wav", FCVAR_REPLICATED ) | |
if SERVER then | |
util.AddNetworkString("FancyConnect.NetworkString") | |
hook.Add("PlayerConnect", "FancyConnect.ConnectMessage", function(name) | |
net.Start("FancyConnect.NetworkString") | |
net.WriteUInt(1, 2) | |
net.WriteString(name) | |
net.Broadcast() | |
end) | |
hook.Add("PlayerInitialSpawn", "FancyConnect.LoadedMessage", function(ply) | |
timer.Simple(5, function() -- Let the player load you noodle! | |
if IsValid(ply) and ply:IsPlayer() then | |
net.Start("FancyConnect.NetworkString") | |
net.WriteUInt(2, 2) | |
net.WriteString(ply:Nick()) | |
net.WriteString(ply:SteamID()) | |
net.Broadcast() | |
end | |
end) | |
end) | |
hook.Add("PlayerDisconnected", "FancyConnect.DisconnectMessage", function(ply) | |
if IsValid(ply) and ply:IsPlayer() then | |
net.Start("FancyConnect.NetworkString") | |
net.WriteUInt(3, 2) | |
net.WriteString(ply:Nick()) | |
net.WriteString(ply:SteamID()) | |
net.Broadcast() | |
end | |
end) | |
end | |
if CLIENT then | |
net.Receive("FancyConnect.NetworkString", function() | |
local mode = net.ReadUInt(2) | |
local name = net.ReadString() | |
if mode == 1 then | |
chat.AddText( Color(145,145,145), name, Color(255, 255, 255), " is ", Color(0, 127, 127), "joining", Color(255, 255, 255), " the server" ) | |
if GetConVar("sv_connectsound"):GetBool() then | |
surface.PlaySound(GetConVar("sv_connectsoundfile"):GetString()) | |
end | |
elseif mode == 2 then | |
chat.AddText( Color(145,145,145), name, Color(255, 255, 255), " has ", Color(0, 127, 31), "finished loading" ) | |
print("(".. net.ReadString() ..")") | |
elseif mode == 3 then | |
chat.AddText( Color(145,145,145), name, Color(255, 255, 255), " ", Color(255, 30, 30), "left", Color(255, 255, 255), " the server" ) | |
print("(".. net.ReadString() ..")") | |
if GetConVar("sv_connectsound"):GetBool() then | |
surface.PlaySound(GetConVar("sv_connectsoundfile"):GetString()) | |
end | |
end | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment