SphereCommunity
In-game clients - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: In-game clients (/Thread-In-game-clients)



In-game clients - Leonidas - 12-20-2016 06:43 PM

So I've noticed that when using %CLIENTS% on spherestatusbase.htm it returns the value of every connection to the server, including people just looking at the server status page on their browser. So I made a little command that runs every world save and checks if the player has a UID or not. It seems to work fine, but I don't know if this is the right way to do it? I'm assuming this may bog down the server at a high playerbase?


Code:
[FUNCTION F_ONLINECLIENTS]
serv.var.onlineclients=0
FORCLIENTS 6144
IF <uid> =
return 1
else
var.onlineclients= (<VAR.ONLINECLIENTS>+1)
endif
endfor


[FUNCTION GETCLIENTS]
Return <EVAL (<VAR.ONLINECLIENTS>)>



RE: In-game clients - rastrero - 12-20-2016 06:46 PM

If I were you, I would disable the sphere web status, and do another one by mysql


RE: In-game clients - Leonidas - 12-20-2016 06:48 PM

I plan on doing that later on down the road, just wanted to get one going for a bit.


RE: In-game clients - Kanibal - 12-20-2016 08:27 PM

Do you need only number of connected players or they names etc.? Whatever you can use LISTS. Try something like this:
Code:
[FUNCTION f_player_online]
if (<isplayer>)
  serv.list.onlineplayers.add <name>
endif
return 0
Then go to sphere_serv_triggers.scp and use this code
Code:
[FUNCTION f_onserver_timer] // [FUNCTION f_onserver_save]
serv.list.onlineplayers.clear
serv.allclients f_player_online
return 0

The number of players will be <serv.list.onlineplayers.count> and you can simple get each player name from this list
Code:
[FUNCTION f_get_players_list]
for i 0 <eval <serv.list.onlineplayers.count>>-1  // LISTS are zero based?
  serv.log <serv.list.onlineplayers.<dlocal.i>>
endfor
return 0
or just show list
Code:
[FUNCTION f_show_list]
serv.log <serv.list.onlineplayers>
return 0



RE: In-game clients - rastrero - 12-20-2016 09:08 PM

As u want.


RE: In-game clients - Coruja - 12-21-2016 11:04 AM

you can use LIST engine as Kanibal said, but I think webpages can't read info from LIST's, so this code can be useful to show online player list ingame on some dialog/function/etc, but not on webpages

if you just want get the online players without count connections without chars connected ingame, you can use an simple function like this
Code:
[FUNCTION UpdateOnlineClientsVar]
VAR.OnlineClients=0
IF (<SERV.CLIENTS>)
  FOR 0 <eval <SERV.CLIENTS>-1>
    IF (<SERV.CLIENT.<LOCAL._FOR>.UID>)
      VAR.OnlineClients ++
    ENDIF
  ENDFOR
ENDIF
this will update VAR.OnlineClients so you just need to read this VAR.OnlineClients value on your webpage


RE: In-game clients - Kanibal - 12-21-2016 01:51 PM

(12-21-2016 11:04 AM)Coruja Wrote:  you can use LIST engine as Kanibal said, but I think webpages can't read info from LIST's, so this code can be useful to show online player list ingame on some dialog/function/etc, but not on webpages

Woot

or use madskillz (Click to View)


P.S. I did not test this thing so try it yourself


RE: In-game clients - Leonidas - 12-27-2016 03:45 PM

Code:
[FUNCTION UpdateOnlineClientsVar]
VAR.OnlineClients=0
IF (<SERV.CLIENTS>)
  FOR 0 <eval <SERV.CLIENTS>-1>
    IF (<SERV.CLIENT.<LOCAL._FOR>.UID>)
      VAR.OnlineClients ++
    ENDIF
  ENDFOR
ENDIF

How can I make this check if the player has a tag or not? Trying to make it so staff can use a command to hide and have this not add them to the client count.


RE: In-game clients - Coruja - 12-27-2016 05:46 PM

you can check using char UID
Code:
[FUNCTION UpdateOnlineClientsVar]
VAR.OnlineClients=0
IF (<SERV.CLIENTS>)
  FOR 0 <eval <SERV.CLIENTS>-1>
    REF1=<SERV.CLIENT.<LOCAL._FOR>.UID>
    IF (<REF1>)
      IF (<REF1.ACCOUNT.PLEVEL> < 2)  //or (<REF1.TAG0.AAA>), etc
        VAR.OnlineClients ++
      ENDIF
    ENDIF
  ENDFOR
ENDIF



RE: In-game clients - Leonidas - 12-28-2016 10:06 AM

Exactly what I needed, thanks alot!