The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In-game clients
Author Message
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #1
In-game clients
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>)>
(This post was last modified: 12-20-2016 06:44 PM by Leonidas.)
12-20-2016 06:43 PM
Find all posts by this user Like Post Quote this message in a reply
rastrero
Master
**

Posts: 250
Likes Given: 41
Likes Received: 28 in 24 posts
Joined: Jan 2016
Reputation: 3



Post: #2
RE: In-game clients
If I were you, I would disable the sphere web status, and do another one by mysql
12-20-2016 06:46 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes rastrero's post
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #3
RE: In-game clients
I plan on doing that later on down the road, just wanted to get one going for a bit.
12-20-2016 06:48 PM
Find all posts by this user Like Post Quote this message in a reply
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #4
RE: In-game clients
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

Grandmaster Localhost Admin
(This post was last modified: 12-20-2016 08:38 PM by Kanibal.)
12-20-2016 08:27 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
rastrero
Master
**

Posts: 250
Likes Given: 41
Likes Received: 28 in 24 posts
Joined: Jan 2016
Reputation: 3



Post: #5
RE: In-game clients
As u want.
12-20-2016 09:08 PM
Find all posts by this user Like Post Quote this message in a reply
Coruja
Sphere Developer
*****

Posts: 987
Likes Given: 5
Likes Received: 226 in 187 posts
Joined: Jul 2012
Reputation: 7

Dimension Shard

Post: #6
RE: In-game clients
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
12-21-2016 11:04 AM
Find all posts by this user Like Post Quote this message in a reply
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #7
RE: In-game clients
(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

Grandmaster Localhost Admin
(This post was last modified: 12-21-2016 01:55 PM by Kanibal.)
12-21-2016 01:51 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #8
RE: In-game clients
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.
(This post was last modified: 12-27-2016 03:45 PM by Leonidas.)
12-27-2016 03:45 PM
Find all posts by this user Like Post Quote this message in a reply
Coruja
Sphere Developer
*****

Posts: 987
Likes Given: 5
Likes Received: 226 in 187 posts
Joined: Jul 2012
Reputation: 7

Dimension Shard

Post: #9
RE: In-game clients
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
12-27-2016 05:46 PM
Find all posts by this user Like Post Quote this message in a reply
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #10
RE: In-game clients
Exactly what I needed, thanks alot!
12-28-2016 10:06 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 2 Guest(s)