Just realized... I make a lot of threads here.
Anyways, I was wondering how system.GetCountry() works. I want to have it so that when someone joins a server, they will see {the 2 letter country code} | "their name" has joined. I've tried using this:
if SERVER then
util.AddNetworkString( "Get Country" )
net.Receive( "Get Country", function( len, pl )
userCountry = net.ReadString()
print( userCountry ) -- Tried to debug. Nothing prints.
end )
end
if CLIENT then
hook.Add( "PlayerConnect", "GetCountry", function( name, ip )
net.Start( "Get Country" )
net.WriteString( system.GetCountry() )
net.SendToServer()
for k,v in pairs( player.GetAll() ) do
if IsValid( v ) then
v:PrintMessage( HUD_PRINTTALK, "{" .. userCountry .. "} | " .. name .. " has connected." )
end
end
end )
hook.Add( "OnPlayerChat", "Add Country to Chat", function( ply, strText, bTeamOnly, bPlayerIsDead )
local tab = {}
if ( bPlayerIsDead ) then
table.insert( tab, Color( 255, 30, 40 ) )
table.insert( tab, "*DEAD* " )
table.insert( tab, Color( 255, 255, 255 ) )
end
if userCountry != nil then
table.insert( tab, "{" .. userCountry .. "} | " )
end
if ( IsValid( ply ) ) then
table.insert( tab, ply )
else
table.insert( tab, "Console" )
end
table.insert( tab, Color( 255, 255, 255 ) )
table.insert( tab, ": "..strText )
chat.AddText( unpack( tab ) )
return true
end )
end
Using the help of the code
here but it doesn't print anything. It has no errors, it just doesn't do anything. I put PlayerConnect hook in the CLIENT as it's shared, so I thought it could, because I thought I could run system.GetCountry() in the client and it will get the client's system information, but that didn't work. I have this in
garrysmod/addons/Viscosity%20Command/lua/autorun/get_country.lua, is there somewhere else I should put it or is this just not how this function works?