Player health/armor values (server code only)

Is it possible to return a player’s health and his armor values by only using functions accessible via the server code?

You could grab the pointer to the clients in code/server/sv_game.c
at G_LOCATE_GAME_DATA

Parameter 3 is the pointer to the beginning of the client list
and parameter 4 is the size of an element.
With those you can calculate the offset the playerstate is supposed to be.
Health and armor are in the playerstate. The following function is an example on how to get the playerstate for a given player number. “gameClients” is the pointer to the client list and “gameClientSize” is the size of an Element, as taken from the function call above.

Code copy pasted from a similar project. Types may differ!

playerState_t *GetPlayerState(int num) {
playerState_t *ps;
ps = (playerState_t *) ((byte *) gameClients + gameClientSize * (num));
return ps;
}

HKay, thanks for your prompt reply. I’ve been mustering through your response and the respective code, albeit as a C novice, to great confusion.

Essentially all that I’ve deduced is that I need to call the function SV_LocateGameData(); and pass 5 parameters to it and then pull the health/armor values from the output?

SV_LocateGameData( VMA(1), args[2], args[3], VMA(4), args[5] );

Would parameter 3 (client list pointer) be: svs.clients?

The function is called automatically when the mod is loaded. The function call is right there. Just also copy the pointer values to some variables right after it is called. They will not change while the mod is running. So you are save to use them to get to the playerstate.

Woops, apparently the server already knows all there is to know.

SV_GameClientNum will get you the playerstate which in turn contains the health and amor in the stats field.
In case of quake3 the stats[STAT_HEALTH] and stats[STAT_ARMOR] contain what you need. But that may differ in other mods. It’s likely to still be there, though.

1 Like

HKay, thank you so much for taking the time out of your day to help me get this working. I really appreciate it. :smile:

It works!

Can you tell me why you were interested in getting ioquake3 player health and armor values a year ago?

I am interested in the same thing for my shock collar integration project (http://community.ioquake.org/t/shock-collar-integration/503) and any hints that you could give would be welcome as I am running short of time.

Cheers,