Advertisement
lucasgautheron

Untitled

Apr 23rd, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #define ATTR_GET_INT(attribute) itoa(output, attribute);
  2. #define ATTR_GET_FLOAT(attribute) ftoa(output, attribute);
  3. #define ATTR_GET_STR(attribute) copystring(output, attribute);
  4.  
  5. #define ATTR_SET_INT(attribute) if(set) { attribute = atoi(value); }
  6. #define ATTR_SET_FLOAT(attribute) if(set) { attribute = atof(value); }
  7. #define ATTR_SET_STR(attribute) if (set) { copystring(attribute, value); }
  8.  
  9. #define ATTR_INT(name, attribute, readonly) if(!strcmp(attr, name)) { if(!readonly) ATTR_SET_INT(attribute); ATTR_GET_INT(attribute); result(output); return; }
  10. #define ATTR_FLOAT(name, attribute, readonly) if(!strcmp(attr, name)) { if(!readonly) ATTR_SET_FLOAT(attribute); ATTR_GET_FLOAT(attribute) result(output); return; }
  11. #define ATTR_STR(name, attribute, readonly) if(!strcmp(attr, name)) { if(!readonly) ATTR_SET_STR(attribute); ATTR_GET_STR(attribute) result(output); return; }
  12.  
  13. void player(const char *cn, const char *attr, const char *value)
  14. {
  15.     if(!*cn || !cn || !*attr || !attr)
  16.     {
  17.         return;
  18.     }
  19.     int clientnum = atoi(cn); // get player clientnum
  20.     playerent *p = clientnum == player1->clientnum ? player1 : NULL;
  21.     loopv(players) if(players[i] && players[i]->clientnum == clientnum)
  22.     {
  23.         p = players[i];
  24.         break;
  25.     }
  26.     if(!p)
  27.     {
  28.         conoutf("invalid clientnum");
  29.         return;
  30.     }
  31.     bool set = *value && value && p==player1; // do we have to get or set an attribute (valid value, player selected is local client)
  32.     string output = "";
  33.  
  34.     // local player only attributes.
  35.     if(p==player1)
  36.     {
  37.         ATTR_INT("health", p->health, 1);
  38.         ATTR_INT("armour", p->armour, 1);
  39.         ATTR_INT("magcontent", p->weaponsel->mag, 1);
  40.         ATTR_INT("ammo", p->weaponsel->ammo, 1);
  41.         ATTR_INT("nextprimary", p->nextprimary, 0);
  42.     }
  43.     // local player team only attributes
  44.     if(p->team == player1->team || player1->isspectating())
  45.     {
  46.         ATTR_FLOAT("x", p->o.x, 1);
  47.         ATTR_FLOAT("y", p->o.y, 1);
  48.         ATTR_FLOAT("z", p->o.z, 1);
  49.     }
  50.     ATTR_STR("name", p->name, 0);
  51.     ATTR_INT("team", p->team, 1);
  52.     ATTR_INT("primary", p->primary, 1);
  53.     ATTR_INT("frags", p->frags, 1);
  54.     ATTR_INT("flagscore", p->flagscore, 1);
  55.     ATTR_INT("points", p->points, 1);
  56.     ATTR_INT("deaths", p->deaths, 1);
  57.  
  58.  
  59.     // the attribute didn't match with any of the list (invalid attribute OR no permission to get it)
  60.     conoutf("invalid attribute");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement