• Print

Author Topic: How does system.GetCountry() work?  (Read 4560 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
How does system.GetCountry() work?
« on: October 11, 2016, 04:35:46 pm »
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:
Code: Lua
  1.  
  2.  
  3. if SERVER then
  4.  
  5.  
  6.    util.AddNetworkString( "Get Country" )
  7.  
  8.  
  9.    net.Receive( "Get Country", function( len, pl )
  10.    
  11.       userCountry = net.ReadString()
  12.       print( userCountry ) -- Tried to debug. Nothing prints.
  13.  
  14.  
  15.    end )
  16.  
  17.  
  18. end  
  19.  
  20.  
  21. if CLIENT then
  22.  
  23.  
  24.    hook.Add( "PlayerConnect", "GetCountry", function( name, ip )
  25.  
  26.  
  27.       net.Start( "Get Country" )
  28.          net.WriteString( system.GetCountry() )
  29.       net.SendToServer()
  30.  
  31.  
  32.       for k,v in pairs( player.GetAll() ) do
  33.  
  34.  
  35.          if IsValid( v ) then
  36.  
  37.  
  38.             v:PrintMessage( HUD_PRINTTALK, "{" .. userCountry .. "} | " .. name .. " has connected." )
  39.  
  40.  
  41.          end
  42.  
  43.  
  44.       end
  45.  
  46.  
  47.    end )
  48.  
  49.  
  50.    hook.Add( "OnPlayerChat", "Add Country to Chat", function( ply, strText, bTeamOnly, bPlayerIsDead )
  51.  
  52.  
  53.       local tab = {}
  54.  
  55.  
  56.       if ( bPlayerIsDead ) then
  57.  
  58.  
  59.          table.insert( tab, Color( 255, 30, 40 ) )
  60.          table.insert( tab, "*DEAD* " )
  61.          table.insert( tab, Color( 255, 255, 255 ) )
  62.  
  63.  
  64.       end
  65.  
  66.  
  67.       if userCountry != nil then
  68.  
  69.  
  70.          table.insert( tab, "{" .. userCountry .. "} | " )
  71.  
  72.  
  73.       end
  74.  
  75.  
  76.       if ( IsValid( ply ) ) then
  77.  
  78.  
  79.          table.insert( tab, ply )
  80.  
  81.  
  82.       else
  83.  
  84.  
  85.          table.insert( tab, "Console" )
  86.  
  87.  
  88.       end
  89.  
  90.  
  91.       table.insert( tab, Color( 255, 255, 255 ) )
  92.       table.insert( tab, ": "..strText )
  93.  
  94.  
  95.       chat.AddText( unpack( tab ) )
  96.  
  97.  
  98.       return true
  99.  
  100.  
  101.    end )
  102.  
  103.  
  104. 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
Code: [Select]
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?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How does system.GetCountry() work?
« Reply #1 on: October 11, 2016, 06:46:17 pm »
Few things I see quickly;
You're setting a variable (userCountry) on the server.
You're then attempting to use the variable on a client side hook (OnPlayerChat).
There's some more that I can't decipher, but that's a big start.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: How does system.GetCountry() work?
« Reply #2 on: October 11, 2016, 07:01:35 pm »
Derp I can just use PlayerSay can't I since that's a serverside hook that does the same thing? I'll try that out tomorrow..
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print