Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // macros for playerinfo() & teaminfo(). Use this to replace pstats_xxx ?
- #define ATTR_INT(name, attribute) if(!strcmp(attr, #name)) { intret(attribute); return; }
- #define ATTR_FLOAT(name, attribute) if(!strcmp(attr, #name)) { floatret(attribute); return; }
- #define ATTR_STR(name, attribute) if(!strcmp(attr, #name)) { result(attribute); return; }
- void playerinfo(const char *cn, const char *attr)
- {
- if(!*cn || !cn || !*attr || !attr) return;
- int clientnum = atoi(cn); // get player clientnum
- playerent *p = clientnum == player1->clientnum || clientnum < 0 ? player1 : getclient(clientnum);
- if(!p)
- {
- conoutf("invalid clientnum");
- return;
- }
- if(p == player1)
- {
- ATTR_INT(magcontent, p->weaponsel->mag);
- ATTR_INT(ammo, p->weaponsel->ammo);
- ATTR_INT(primary, p->primary);
- ATTR_INT(curweapon, p->weaponsel->type);
- ATTR_INT(nextprimary, p->nextprimary);
- }
- if((p->team == player1->team && m_teammode) || player1->isspectating() || p == player1)
- {
- ATTR_INT(health, p->health);
- ATTR_INT(armour, p->armour);
- ATTR_FLOAT(x, p->o.x);
- ATTR_FLOAT(y, p->o.y);
- ATTR_FLOAT(z, p->o.z);
- }
- ATTR_STR(name, p->name);
- ATTR_INT(team, p->team);
- ATTR_INT(ping, p->ping);
- ATTR_INT(pj, p->plag);
- ATTR_INT(state, p->state);
- ATTR_INT(role, p->clientrole);
- ATTR_INT(frags, p->frags);
- ATTR_INT(flags, p->flagscore);
- ATTR_INT(points, p->points);
- ATTR_INT(deaths, p->deaths);
- ATTR_INT(tks, p->tks);
- ATTR_INT(alive, p->state == CS_ALIVE ? 1 : 0);
- ATTR_INT(spec, p->team == TEAM_SPECT || p->spectatemode == SM_FLY ? 1 : 0);
- ATTR_INT(cn, p->clientnum); // only useful to get player1's client number.
- conoutf("invalid attribute");
- }
- void playerinfolocal(const char *attr)
- {
- playerinfo("-1", attr);
- }
- COMMANDN(player, playerinfo, ARG_3STR);
- COMMANDN(player1, playerinfolocal, ARG_2STR);
- void teaminfo(const char *team, const char *attr)
- {
- if(!team || !attr) return;
- int t = atoi(team); // get player clientnum
- if(!team_isactive(t))
- {
- conoutf("invalid team");
- return;
- }
- int t_flags = 0;
- int t_frags = 0;
- int t_deaths = 0;
- int t_points = 0;
- string teammembers = "";
- loopv(players) if(players[i] && players[i]->team == t)
- {
- t_frags += players[i]->frags;
- t_deaths += players[i]->deaths;
- t_points += players[i]->points;
- t_flags += players[i]->flagscore;
- sprintf("%s %d", teammembers, players[i]->clientnum);
- }
- loopv(discscores) if(discscores[i].team == t)
- {
- t_frags += discscores[i].frags;
- t_deaths += discscores[i].deaths;
- t_points += discscores[i].points;
- t_flags += discscores[i].flags;
- }
- if(player1->team == t)
- {
- t_frags += player1->frags;
- t_deaths += player1->deaths;
- t_points += player1->points;
- t_flags += player1->flagscore;
- }
- ATTR_INT(flags, t_flags);
- ATTR_INT(frags, t_frags);
- ATTR_INT(deaths, t_deaths);
- ATTR_INT(points, t_points);
- ATTR_STR(name, newstring(team_string(t)));
- ATTR_STR(players, teammembers);
- conoutf("invalid attribute");
- }
- COMMAND(teaminfo, ARG_2STR);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement