ULX

Author Topic: Show player count on server in advert  (Read 6350 times)

0 Members and 2 Guests are viewing this topic.

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Show player count on server in advert
« on: August 09, 2014, 01:00:31 PM »
How would you code an advert for ULX to show how many players are on another server? I know they have %host% and stuff like that and I was wondering what to do to get an advert to look like this? [Join our DarkRP server! Type !darkrp | Players 15/22]

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Show player count on server in advert
« Reply #1 on: August 09, 2014, 07:33:20 PM »
You need to code an html parser to read pages fetched from gametracker. Alternatively, you can do this with PHP.
http://wiki.garrysmod.com/page/http/Fetch

Use this url to get gametracker info for a server:
Code: [Select]
Format( "http://www.gametracker.com/server_info/%s:%s", ip, port )
You can probably find parsing regexes on facepunch.

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Re: Show player count on server in advert
« Reply #2 on: August 10, 2014, 05:12:41 AM »
I'm sorry but I don't really understand can you please post the code? I need so it can look like this? [Join our DarkRP server! Type !darkrp | Players 15/22]

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Show player count on server in advert
« Reply #3 on: August 10, 2014, 08:03:01 PM »
you originally didn't ask "Can someone please do my work for me?"
You asked "How can I do it?"
Those two questions are totally separate.
In the future, please ask the question you intend up front.

What you are wanting, data from another server, is not "easy" in Gmod.
Not impossible mind you, but would take any dev several lines of code to parse the data.
And easily broken anytime the host changes its data format method.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Show player count on server in advert
« Reply #4 on: August 10, 2014, 08:10:02 PM »
Take a look at Cobalt's Portal addon. It's on his github profile.
Has a little to do with getting data from gametracker.
Out of the Garry's Mod business.

Offline Lolomat

  • Newbie
  • *
  • Posts: 24
  • Karma: 0
Re: Show player count on server in advert
« Reply #5 on: August 12, 2014, 11:15:13 AM »
Hey,

how is the addon called wich allows to use a command like !darkrp to join on another server?

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Re: Show player count on server in advert
« Reply #6 on: August 12, 2014, 12:08:50 PM »
What do you mean Lolomat? Are you asking how a ! command makes you join another server?

Offline Lolomat

  • Newbie
  • *
  • Posts: 24
  • Karma: 0
Re: Show player count on server in advert
« Reply #7 on: August 12, 2014, 12:24:38 PM »
@UnderYouFive

yeah :)

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Re: Show player count on server in advert
« Reply #8 on: August 12, 2014, 02:43:16 PM »
Code: [Select]
function darkrpCommand( pl, text, teamonly )
    if (text == "!darkrp") then
    pl:SendLua( [[ LocalPlayer():ConCommand( 'connect Your IP here' ) ]] )
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined darkrp your server name via !darkrp" )

end
end
end
hook.Add( "PlayerSay", "Chat", darkrpCommand )


Enjoy :)

Offline Lolomat

  • Newbie
  • *
  • Posts: 24
  • Karma: 0
Re: Show player count on server in advert
« Reply #9 on: August 12, 2014, 03:10:59 PM »
@UnderYouFive

thanks, but how do i add it to my server.
I tried it putting in garrysmod/addons/ulx/lua/ulx/modules/sh/joinotherserver.lua like this:

Code: [Select]
CATEGORY_NAME = "Join other server"
function tttCommand( pl, text, teamonly )
    if (text == "!ttt2") then
    pl:SendLua( [[ LocalPlayer():ConCommand( 'ttt2.fickschnitzel.cf' ) ]] )
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " ist nun auf Fickschnitzel TTT Server #2 via !ttt2" )

end
end
end
hook.Add( "PlayerSay", "User", tttcomand )

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Re: Show player count on server in advert
« Reply #10 on: August 12, 2014, 04:43:29 PM »
Oh sorry, I forgot to tell you haha. You need to put it in your "garry'smod/lua/autorun" folder.

Offline Lolomat

  • Newbie
  • *
  • Posts: 24
  • Karma: 0
Re: Show player count on server in advert
« Reply #11 on: August 13, 2014, 07:19:19 AM »
In garrysmod/lua/autorun/client/joinotherserver.lua or garrysmod/lua/autorun/server/joinotherserver.lua ?

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Re: Show player count on server in advert
« Reply #12 on: August 13, 2014, 08:18:56 AM »
No just put it in the autorun folder  "garry'smod/lua/autorun"

Offline Lolomat

  • Newbie
  • *
  • Posts: 24
  • Karma: 0
Re: Show player count on server in advert
« Reply #13 on: August 13, 2014, 09:13:02 AM »
I dropped it in garrysmod/lua/autorun/server/joinotherserver.lua
 It is looking like this:
Code: [Select]
function tttCommand( pl, text, teamonly )
    if (text == "!ttt2") then
    pl:SendLua( [[ LocalPlayer():ConCommand( 'connect ttt2.fickschnitzel.cf' ) ]] )
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Spieler " .. pl:Nick() .. " ist nun auf Fickschnitzel TTT Server #2 via !ttt2" )

end
end
end
hook.Add( "PlayerSay", "User", tttCommand )

This is how i made it work for me. :)
Thanks for the code.

Offline UnderYouFive

  • Newbie
  • *
  • Posts: 28
  • Karma: -5
Re: Show player count on server in advert
« Reply #14 on: August 13, 2014, 09:57:33 AM »
So does it work when you use !ttt2? Do you join the server?