Add get_entity to util.c

With checks to make sure entity is correct
Remove is_alive check from valid_client

Fixes 41e6b012d9
This commit is contained in:
8dcc 2023-07-23 22:22:36 +02:00
parent 02ba15ba3f
commit a257317f58
2 changed files with 14 additions and 1 deletions

View File

@ -21,6 +21,7 @@ typedef struct {
/*----------------------------------------------------------------------------*/
cl_entity_t* get_entity(int ent_idx);
bool is_alive(cl_entity_t* ent);
bool valid_client(cl_entity_t* ent);
char* get_name(int ent_idx);

View File

@ -7,12 +7,24 @@
#include <math.h>
#include <GL/gl.h>
cl_entity_t* get_entity(int ent_idx) {
if (ent_idx < 0 || ent_idx > 32)
return NULL;
cl_entity_t* ent = i_engine->GetEntityByIndex(ent_idx);
if (ent->curstate.messagenum < localplayer->curstate.messagenum)
return NULL;
return ent;
}
bool is_alive(cl_entity_t* ent) {
return ent && ent->curstate.movetype != 6 && ent->curstate.movetype != 0;
}
bool valid_client(cl_entity_t* ent) {
return is_alive(ent) && ent->index != localplayer->index;
return ent && ent->index != localplayer->index;
}
char* get_name(int ent_idx) {