Quake3World.com
https://www.quake3world.com/forum/

Replacing text...
https://www.quake3world.com/forum/viewtopic.php?f=16&t=9599
Page 1 of 1

Author:  ensiform [ 09-03-2005 09:03 PM ]
Post subject:  Replacing text...

I'm in need of a little help here:

Edited: out of date code and these warnings fixed (look at post below)

Author:  ensiform [ 09-04-2005 07:54 AM ]
Post subject: 

mmm here's a more structured version:
* i was in the middle of posting this last night and i had to leave so if someone has posted after that i didnt get to see.

Code:
const char *TokenSiegeClass(siegeClass_t siegeclass, gclient_t   *client) {
      if (g_gametype.integer == GT_SIEGE) { // Replace #class with your siege class
         if (client->sess.sessionTeam != TEAM_SPECTATOR)
            return siegeclass.name;
         else
            return "spectator";
      } else {
         return "invalid gametype";
      }

}

const char *TokenPlayerState(playerState_t ps, int type) {
   char   buff[5];
   char   *textBuffer;

   if (type==1){
      itoa(ps.stats[STAT_HEALTH],buff,10);
      textBuffer = buff;
      return textBuffer;   // health
   } else if (type==2) {
      itoa(ps.stats[STAT_ARMOR],buff,10);
      textBuffer = buff;
      return textBuffer;   // shield/armor
   } else if (type==3) {
      itoa(ps.fd.forcePower,buff,10);
      textBuffer = buff;
      return textBuffer;      // force amount
   } else if (type==4) {
      if (ps.fd.forceSide == FORCE_LIGHTSIDE)
         return "^5Light";
      else if (ps.fd.forceSide == FORCE_DARKSIDE)
         return "^1Dark";
      else
         return "";
   } else {
      return "";                  // invalid
   }
}

const char *TokenLocation(gclient_t *client) {
   char location[64];
   char *locMsg = NULL;

   if (Team_GetLocationMsg(&g_entities[client->ps.clientNum], location, sizeof(location))) {
      locMsg = location;
      return locMsg;
   } else {
      return "unknown location";
   }
}

const char *TokenPers(clientPersistant_t pers, int type) {

   if (type==1)
      return pers.netname;         // netname
   else
      return "";                  // invalid
}

const char *TokenTeamName(int team)  {
   if (team==TEAM_RED)
      return "^1Red Team";
   else if (team==TEAM_BLUE)
      return "^4Blue Team";
   else if (team==TEAM_SPECTATOR)
      return "Spectator team";
   return "^3Free Team";
}

const char *TokenTeamColor(int team)  {
   if (team==TEAM_RED)
      return "red";
   else if (team==TEAM_BLUE)
      return "blue";
   else if (team==TEAM_SPECTATOR)
      return "spectator";
   return "free";
}

const char *TokenOtherTeamName(int team) {
   if (team==TEAM_RED)
      return "blue";
   else if (team==TEAM_BLUE)
      return "red";
   else if (team==TEAM_SPECTATOR)
      return "spectator";
   return "free";
}

const char *TokenWeaponName(int weapon) {
   if (weapon==WP_SABER)
      return "Lightsaber";
   else if (weapon==WP_STUN_BATON)
      return "Stun Baton";
   else if (weapon==WP_MELEE)
      return "Melee";
   else if (weapon==WP_BRYAR_OLD)
      return "Bryar Pistol";
   else if (weapon==WP_BRYAR_PISTOL)
      return "DL-44 Heavy Blaster Pistol";
   else if (weapon==WP_BLASTER)
      return "E11-Blaster Rifle";
   else if (weapon==WP_DISRUPTOR)
      return "Tenloss Disruptor Rifle";
   else if (weapon==WP_BOWCASTER)
      return "Wookie Bowcaster";
   else if (weapon==WP_REPEATER)
      return "Imperial Heavy Repeater";
   else if (weapon==WP_DEMP2)
      return "DEMP2";
   else if (weapon==WP_FLECHETTE)
      return "Golan Arms Flechette";
   else if (weapon==WP_ROCKET_LAUNCHER)
      return "Merr-Sonn Missile System";
   else if (weapon==WP_THERMAL)
      return "Thermal Detonator";
   else if (weapon==WP_TRIP_MINE)
      return "Trip Mines";
   else if (weapon==WP_DET_PACK)
      return "Detonation Packs";
   else if (weapon==WP_EMPLACED_GUN)
      return "Emplaced Gun";
   else if (weapon==WP_CONCUSSION)
      return "Stouker Concussion Rifle";
   else if (weapon==WP_NONE)
      return "No Weapon";
   return "Invalid Weapon";
}

qboolean G_TokenText(char *text, char *tokenstr, gclient_t *client)
{
           qboolean foundToken = qfalse, lastTokenFound = qfalse;
           int token = 0;
           char *textPos = text;
           while (*textPos) {
                   lastTokenFound = qfalse;
                   token = 0;
                   while (token < MAX_SAY_TEXT && *textPos) {
                           if(!Q_stricmpn(textPos, tokenstr, strlen(tokenstr))) {
                                   foundToken = qtrue;
                                   if (token == MAX_SAY_TEXT-1) {
                                           lastTokenFound = qtrue;
                                   }
                                   {
                                           int i;
                                           for (i = 0;
                                               i < strlen(tokenstr);
                                               i++) {
                                       // health
                                       if (!Q_stricmp(tokenstr,"$h"))
                                          *textPos++ = *TokenPlayerState(client->ps,1);   //1=health
                                       // shield/armor
                                       if (!Q_stricmp(tokenstr,"$a"))
                                          *textPos++ = *TokenPlayerState(client->ps,2);   //2=shield/armor
                                       // force
                                       if (!Q_stricmp(tokenstr,"$f"))
                                          *textPos++ = *TokenPlayerState(client->ps,3);   // 3=force
                                       // force
                                       if (!Q_stricmp(tokenstr,"$s"))
                                          *textPos++ = *TokenPlayerState(client->ps,4);   // 4=force-side
                                       // name
                                       if (!Q_stricmp(tokenstr,"$n"))
                                          *textPos++ = *TokenPers(client->pers,1);   // 1=netname
                                       // class
                                       if (!Q_stricmp(tokenstr,"#class"))
                                          *textPos++ = *TokenSiegeClass(bgSiegeClasses[client->siegeClass]);
                                       // Team Name with color code
                                       if (!Q_stricmp(tokenstr,"$t"))
                                          *textPos++ = *TokenTeamName(client->sess.sessionTeam);
                                       // other team color
                                       if (!Q_stricmp(tokenstr,"$e"))
                                          *textPos++ = *TokenOtherTeamName(client->sess.sessionTeam);
                                       // team color
                                       if (!Q_stricmp(tokenstr,"$c"))
                                          *textPos++ = *TokenTeamColor(client->sess.sessionTeam);
                                       // weapon
                                       if (!Q_stricmp(tokenstr,"$w"))
                                          *textPos++ = *TokenWeaponName(client->ps.weapon);
                                       // location
                                       if (!Q_stricmp(tokenstr,"$l"))
                                          *textPos++ = *TokenLocation(client);
                                                                                      }
                                   }
                           }
                           token++;
                   }
                   // If it's the last token, it will already be incremented
             if (!lastTokenFound)
                           textPos++;
           }
           return foundToken;
}



with this i have now noticed it replaces the token characters with the first character that its supposed to replace with ie: if health is 100 $h would be 11.

Edit: i got it working with the first character.

Author:  ensiform [ 09-04-2005 09:16 AM ]
Post subject: 

somewhere at the top of G_Say...

Code:
char              tokenText[MAX_SAY_TEXT];


somewhere down below...

Code:
   if (g_chattokens.integer)
   {
      SanitizeString3(text, tokenText, qtrue);
      if (G_TokenText(tokenText,"$h", ent->client)) {// health
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$a", ent->client)) { // armor
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$f", ent->client)) { // force
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$n", ent->client)) { // name
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"#class", ent->client)) { // siege class
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$t", ent->client)) { // team name w/color codes (first letter is upper)
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$c", ent->client)) { // team color (lower-case)
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$s", ent->client)) { // force side
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$e", ent->client)) { // enemy team color (lower-case)
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
      if (G_TokenText(tokenText,"$w", ent->client)) { // weapon
         Q_strncpyz( text, tokenText, sizeof(text) );
      }
   }

Author:  ensiform [ 09-04-2005 12:55 PM ]
Post subject: 

im kind of assuming this isnt working because it was meant to only replace character(s) with an * for censor.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/