View Single Post
Re: help - radio emulation
Old
  (#19)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: help - radio emulation - 02-11-2005

lol @ the plugin

Anyway. Here's how my bots (RACC) catch radio messages in Counter-Strike. Don't be confused by the syntax, the typedefs and the variable types as this is part of an engine-independent layer.
Code:
void HLEngine_NetworkMessage_TextMsg (void)
{
   // this message tells a client that his player received a radio message, to enable him to
   // play the appropriate radio sound sample file.
   player_t *pPlayer;
   char sound_file[256];
   sound_t *radio_sound;
   int i;
   if (!((message[0].packet_type == PACKET_STRING)
		 && (strcmp (message[0].szValuePassed, "#Game_radio") == 0)))
	  return; // cancel if message is NOT a radio message
   pPlayer = &players[message_header.player_index]; // quick access to player
   // is the player receiving this message a bot AND is it a radio message ?
   if (pPlayer->is_racc_bot)
   {
	  // identify the radio sample and choose the sound file that will be played at the bot's
	  // first radio menu
	  if (strcmp ("#Cover_me", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ct_coverme.wav", sizeof (sound_file)); // 'Cover me' radio message
	  else if (strcmp ("#You_take_the_point", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/takepoint.wav", sizeof (sound_file)); // 'You take the point' radio message
	  else if (strcmp ("#Hold_this_position", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/position.wav", sizeof (sound_file)); // 'Hold this position' radio message
	  else if (strcmp ("#Regroup_team", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/regroup.wav", sizeof (sound_file)); // 'Regroup team' radio message
	  else if (strcmp ("#Follow_me", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/followme.wav", sizeof (sound_file)); // 'Follow me' radio message
	  else if (strcmp ("#Taking_fire", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/fireassis.wav", sizeof (sound_file)); // 'Taking fire, need backup' radio message
	  // second radio menu
	  else if (strcmp ("#Go_go_go", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/com_go.wav", sizeof (sound_file)); // 'Go Go Go' radio message
	  else if (strcmp ("#Team_fall_back", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/fallback.wav", sizeof (sound_file)); // 'Team fall back' radio message
	  else if (strcmp ("#Stick_together_team", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/sticktog.wav", sizeof (sound_file)); // 'Stick together team' radio message
	  else if (strcmp ("#Get_in_position_and_wait", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/com_getinpos.wav", sizeof (sound_file)); // 'Stay in position and wait for my go' radio message
	  else if (strcmp ("#Storm_the_front", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/stormfront.wav", sizeof (sound_file)); // 'Storm The Front' radio message
	  else if (strcmp ("#Report_in_team", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/com_reportin.wav", sizeof (sound_file)); // 'Report In' radio message
	  // third radio menu
	  else if (strcmp ("#Affirmative", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ct_affirm.wav", sizeof (sound_file)); // 'Affirmative' radio message
	  else if (strcmp ("#Enemy_spotted", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ct_enemys.wav", sizeof (sound_file)); // 'Enemy spotted' radio message
	  else if (strcmp ("#Need_backup", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ct_backup.wav", sizeof (sound_file)); // 'Need backup' radio message
	  else if (strcmp ("#Sector_clear", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/clear.wav", sizeof (sound_file)); // 'Sector clear' radio message
	  else if (strcmp ("#In_position", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ct_inpos.wav", sizeof (sound_file)); // 'I'm in position' radio message
	  else if (strcmp ("#Reporting_in", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ct_reportingin.wav", sizeof (sound_file)); // 'Reporting in' radio message
	  else if (strcmp ("#Get_out_of_there", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/blow.wav", sizeof (sound_file)); // 'Get outta here' radio message
	  else if (strcmp ("#Negative", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/negative.wav", sizeof (sound_file)); // 'Negative' radio message
	  else if (strcmp ("#Enemy_down", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/enemydown.wav", sizeof (sound_file)); // 'Negative' radio message
	  // client-side radio messages
	  // I miss "A hostage has been rescued", dunno how to catch it (if you do, lemme know)
	  else if (strcmp ("#Bomb_Planted", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/bombpl.wav", sizeof (sound_file)); // 'Bomb planted' radio message
	  else if (strcmp ("#Bomb_Defused", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/bombdef.wav", sizeof (sound_file)); // 'Bomb defused' radio message
	  else if (strcmp ("#Round_Draw", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/rounddraw.wav", sizeof (sound_file)); // 'Round draw' radio message
	  else if (strcmp ("#Terrorists_Win", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/terwin.wav", sizeof (sound_file)); // 'Terrorists win' radio message
	  else if (strcmp ("#CTs_Win", message[2].szValuePassed) == 0)
		 SAFE_strncpy (sound_file, "radio/ctwin.wav", sizeof (sound_file)); // 'Counter-terrorists win' radio message
	  // find the sound we want in the global list
	  for (i = 0; i < GameConfig.sound_count; i++)
		 if (strcmp (GameConfig.sounds[i].file_path, sound_file) == 0)
			radio_sound = &GameConfig.sounds[i]; // link a pointer to this sound's info slot
	  // have we found the sound we want to play ?
	  if (radio_sound != NULL)
		 BotFeedEar (pPlayer, radio_sound, &pPlayer->pEntity->v_eyeposition, 1.0); // bot will hear this radio sound
   }
   return;
}
Basically all you need to remember is that when a radio message is received by a player, it's under the form of a TextMsg, the first string that is passed (text message type) is '#Game_Radio' and the message string that is passed is a short identifier for the message starting with '#'.

Hook TextMsgs, check for the presence of a Game_Radio message, and determine which type of message it is by strcmp'ing it.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote