For 2. I would suggest CHandle<CBasePlayer> It will give you a safe pointer
to the player that will be safe across level changes which is the only case
I can think of where potential issue may arise with stale pointers. It is
always very highly encouraged I think to use a Handle to the object if you
need to store a pointer to it for a relatively longer period of time.
CHandle will be set to NULL pointer when the object it holds is removed from
the EntList.

Chris

-----Original Message-----
From: hlcoders-boun...@list.valvesoftware.com
[mailto:hlcoders-boun...@list.valvesoftware.com] On Behalf Of Andrew
Armstrong
Sent: Friday, February 13, 2009 9:15 PM
To: 'Discussion of Half-Life Programming'
Subject: [hlcoders] Misc questions about how to retrieve certain server
state info

Hi,

I am wondering how to retrieve the following information about the servers
game state:

1) How do I determine the total number of human players in the server per
team, including those players who are currently connecting to the server?
At the moment I have:

        for (int i = 1; i < gpGlobals->maxClients; i++) {
                edict_t *pEdict = PEntityOfEntIndex(i);

                if (pEdict) {
                        IPlayerInfo *playerInfo =
playerinfomanager->GetPlayerInfo( pEdict );

                        if (playerInfo) {
                                if (playerInfo->IsFakeClient())
                                        continue;

                                switch(playerInfo->GetTeamIndex()) {
                                        ...
                                }
                        }
                }
        }

This works fine to count how many human players are on each team, but I
don't know how to get the count of players who are currently joining the
server (and are at the loading screen). I can't distinguish/find a way to
locate the player count (playerInfo is always NULL for when there are no
players, and players that are connecting, it seems).

2) Say I hold on to an edict_t* of a player, and then later on want to
interact with them again. How do I know that its safe to access this pointer
(can the instance ever be deleted from under me?), and also is there a way
to check whether this player has actually changed (ie, is this a pointer to
a server slot, and a new player has joined in their place since I last
accessed the pointer)? I assume this may be the case as they appear to be
re-used, and so I should probably compare the output of
GetPlayerNetworkIDString() between calls on the edict_t*?

3) I noticed in Left 4 Dead that the DIALOG_MSG flag I can use to send a
message via CreateMessage() does not appear on the client; I assume this is
just a client bug. The menu/textbox ones work fine.

4) How can I determine the server's connection address (IP:Port). I can
access the current map via gpGlobals->mapname by the look of it, but I don't
see how I can retrieve the current IP:Port the server is running on.
There is no console variable that has this information, so I can't appear to
use cvar->FindVar() to locate it.

Thanks,
Andrew


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to