Advertisement
lucasgautheron

Untitled

May 29th, 2011
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1. // macros for playerinfo() & teaminfo(). Use this to replace pstats_xxx ?
  2. #define ATTR_INT(name, attribute)    if(!strcmp(attr, #name)) { intret(attribute); return; }
  3. #define ATTR_FLOAT(name, attribute)  if(!strcmp(attr, #name)) { floatret(attribute); return; }
  4. #define ATTR_STR(name, attribute)    if(!strcmp(attr, #name)) { result(attribute); return; }
  5.  
  6. void playerinfo(const char *cn, const char *attr)
  7. {
  8.     if(!*cn || !cn || !*attr || !attr) return;
  9.  
  10.     int clientnum = atoi(cn); // get player clientnum
  11.     playerent *p = clientnum == player1->clientnum || clientnum < 0 ? player1 : getclient(clientnum);
  12.     if(!p)
  13.     {
  14.         conoutf("invalid clientnum");
  15.         return;
  16.     }
  17.  
  18.     if(p == player1)
  19.     {
  20.         ATTR_INT(magcontent, p->weaponsel->mag);
  21.         ATTR_INT(ammo, p->weaponsel->ammo);
  22.         ATTR_INT(primary, p->primary);
  23.         ATTR_INT(curweapon, p->weaponsel->type);
  24.         ATTR_INT(nextprimary, p->nextprimary);
  25.     }
  26.     if((p->team == player1->team && m_teammode) || player1->isspectating() || p == player1)
  27.     {
  28.         ATTR_INT(health, p->health);
  29.         ATTR_INT(armour, p->armour);
  30.         ATTR_FLOAT(x, p->o.x);
  31.         ATTR_FLOAT(y, p->o.y);
  32.         ATTR_FLOAT(z, p->o.z);
  33.     }
  34.     ATTR_STR(name, p->name);
  35.     ATTR_INT(team, p->team);
  36.     ATTR_INT(ping, p->ping);
  37.     ATTR_INT(pj, p->plag);
  38.     ATTR_INT(state, p->state);
  39.     ATTR_INT(role, p->clientrole);
  40.     ATTR_INT(frags, p->frags);
  41.     ATTR_INT(flags, p->flagscore);
  42.     ATTR_INT(points, p->points);
  43.     ATTR_INT(deaths, p->deaths);
  44.     ATTR_INT(tks, p->tks);
  45.     ATTR_INT(alive, p->state == CS_ALIVE ? 1 : 0);
  46.     ATTR_INT(spec, p->team == TEAM_SPECT || p->spectatemode == SM_FLY ? 1 : 0);
  47.     ATTR_INT(cn, p->clientnum); // only useful to get player1's client number.
  48.     conoutf("invalid attribute");
  49. }
  50.  
  51. void playerinfolocal(const char *attr)
  52. {
  53.     playerinfo("-1", attr);
  54. }
  55.  
  56. COMMANDN(player, playerinfo, ARG_3STR);
  57. COMMANDN(player1, playerinfolocal, ARG_2STR);
  58.  
  59. void teaminfo(const char *team, const char *attr)
  60. {
  61.     if(!team || !attr) return;
  62.     int t = atoi(team); // get player clientnum
  63.     if(!team_isactive(t))
  64.     {
  65.         conoutf("invalid team");
  66.         return;
  67.     }
  68.     int t_flags = 0;
  69.     int t_frags = 0;
  70.     int t_deaths = 0;
  71.     int t_points = 0;
  72.  
  73.     string teammembers = "";
  74.  
  75.     loopv(players) if(players[i] && players[i]->team == t)
  76.     {
  77.         t_frags += players[i]->frags;
  78.         t_deaths += players[i]->deaths;
  79.         t_points += players[i]->points;
  80.         t_flags += players[i]->flagscore;
  81.         sprintf("%s %d", teammembers, players[i]->clientnum);
  82.     }
  83.  
  84.     loopv(discscores) if(discscores[i].team == t)
  85.     {
  86.         t_frags += discscores[i].frags;
  87.         t_deaths += discscores[i].deaths;
  88.         t_points += discscores[i].points;
  89.         t_flags += discscores[i].flags;
  90.     }
  91.  
  92.     if(player1->team == t)
  93.     {
  94.         t_frags += player1->frags;
  95.         t_deaths += player1->deaths;
  96.         t_points += player1->points;
  97.         t_flags += player1->flagscore;
  98.     }
  99.  
  100.     ATTR_INT(flags, t_flags);
  101.     ATTR_INT(frags, t_frags);
  102.     ATTR_INT(deaths, t_deaths);
  103.     ATTR_INT(points, t_points);
  104.     ATTR_STR(name, newstring(team_string(t)));
  105.     ATTR_STR(players, teammembers);
  106.     conoutf("invalid attribute");
  107. }
  108.  
  109. COMMAND(teaminfo, ARG_2STR);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement