From 760256c99e85416fcd8414a999f20c5eff790bc1 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 29 Dec 2021 21:21:08 +0900 Subject: [PATCH] [qw] Add SV_ClientNumber builtin This is a quick way to find the client number for an entity. It returns -1 if the entity is not a valid client (either outside the client block, or not currently in use by a client). --- qw/source/sv_pr_cmds.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index 563e74591..36498b8bd 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -1829,6 +1829,21 @@ PF_sv_cvar (progs_t *pr) } } +// int () SV_ClientNumber +// returns -1 if the entity is not a client (either not in the client range +// or the entity is not in use by a client) +static void +PF_SV_ClientNumber (progs_t *pr) +{ + int entnum = P_EDICTNUM (pr, 0); + client_t *cl = svs.clients + entnum - 1; + + if (entnum < 1 || entnum > MAX_CLIENTS || cl->state != cs_server) { + entnum = 0; // nil entity + } + R_INT (pr) = entnum - 1; +} + // entity () SV_AllocClient static void PF_SV_AllocClient (progs_t *pr) @@ -2017,6 +2032,7 @@ static builtin_t builtins[] = { {"cfeof", PF_cfeof, QF 107}, {"cfquota", PF_cfquota, QF 108}, + {"SV_ClientNumber", PF_SV_ClientNumber, -1}, {"SV_AllocClient", PF_SV_AllocClient, -1}, {"SV_FreeClient", PF_SV_FreeClient, -1}, {"SV_SetUserinfo", PF_SV_SetUserinfo, -1},