/* AMX Mod X
*   Real Radio
*
* (c) Copyright 2005 by VEN
*
* This file is provided as is (no warranties)
*
*     DESCRIPTION
*       Plugin allow hear radio commands over certain distance.
*
*     FEATURES
*       - configurable sound parameters (attenuation, volume etc)
*       - "Fun Radio" plugin support
*
*     CONFIGURATION
*       CHAN - channel (default: CHAN_VOICE)
*       VOL - volume (default: VOL_NORM)
*       ATTN - attenuation (default: ATTN_STATIC)
*       FLAGS - flags (default: 0)
*       PITCH - pitch (default: PITCH_NORM)
*       CVAR_FUNRADIO - "Fun Radio" plugin play speed CVAR (default: "amx_funradio_playspeed")
*       CMDS - number of radio commands (default: 23)
*       TEXT - radio chat text list
*       AUDIO - radio sound files
*
*     CVARS
*       amx_real_radio (0: OFF, 1: ON, default: 1) - diablses/enables the plugin
*
*     VERSIONS
*       0.2   SendAudio changed to emit_sound to be more realistic
*       0.1   first release
*
*     THANKS
*       obbin - for initial idea
*       Damaged Soul - for useful "Message Logging" plugin
*/

/* *************************************************** Init **************************************************** */

#include <amxmodx>

#define CHAN CHAN_VOICE
#define VOL VOL_NORM
#define ATTN ATTN_STATIC
#define FLAGS 0
#define PITCH PITCH_NORM

#define CVAR_FUNRADIO "amx_funradio_playspeed"

#define CMDS 23
new const TEXT[CMDS][] = {
	"Cover_me",
	"You_take_the_point",
	"Hold_this_position",
	"Regroup_team",
	"Follow_me",
	"Taking_fire",
	"Go_go_go",
	"Team_fall_back",
	"Stick_together_team",
	"Get_in_position_and_wait",
	"Storm_the_front",
	"Report_in_team",
	"Affirmative",
	"Roger_that",
	"Enemy_spotted",
	"Need_backup",
	"Sector_clear",
	"In_position",
	"Reporting_in",
	"Get_out_of_there",
	"Negative",
	"Enemy_down",
	"Fire_in_the_hole"
}

new const AUDIO[CMDS][] = {
	"radio/ct_coverme.wav",
	"radio/takepoint.wav",
	"radio/position.wav",
	"radio/regroup.wav",
	"radio/followme.wav",
	"radio/fireassis.wav",
	"radio/com_go.wav",
	"radio/fallback.wav",
	"radio/sticktog.wav",
	"radio/com_getinpos.wav",
	"radio/stormfront.wav",
	"radio/com_reportin.wav",
	"radio/ct_affirm.wav",
	"radio/roger.wav",
	"radio/ct_enemys.wav",
	"radio/ct_backup.wav",
	"radio/clear.wav",
	"radio/ct_inpos.wav",
	"radio/ct_reportingin.wav",
	"radio/blow.wav",
	"radio/negative.wav",
	"radio/enemydown.wav",
	"radio/ct_fireinhole.wav"
}

public plugin_precache() {
	for (new i = 0; i < CMDS; ++i)
		precache_sound(AUDIO[i])
}

new g_msgid_send_audio

public plugin_init() {
	register_plugin("Real Radio", "0.2", "VEN")
	register_event("TextMsg", "event_radio", "bc", "3=#Game_radio")
	register_cvar("amx_real_radio", "1")
	g_msgid_send_audio = get_user_msgid("SendAudio")
}

/* *************************************************** Base **************************************************** */

public event_radio() {
	if (!get_cvar_num("amx_real_radio"))
		return

	new id = read_data(2)
	new command[32], i
	read_data(5, command, 31)
	for (i = 0; i < CMDS; ++i) {
		if (equal(command[1], TEXT[i]))
			break
	}

	if (i == CMDS)
		return

	radio_off(id)
	emit_sound(id, CHAN, AUDIO[i], VOL, ATTN, FLAGS, cvar_exists(CVAR_FUNRADIO) ? get_cvar_num(CVAR_FUNRADIO) : PITCH)
}

/* ************************************************** Stocks *************************************************** */

stock radio_off(id) {
	message_begin(MSG_ONE, g_msgid_send_audio, {0, 0, 0}, id)
	write_byte(0)
	write_string("%!MRAD_")
	write_short(32767)
	message_end()
}

/* ********************************************** Captured Events ********************************************** */

/*
// Radio chat text message
L 12/26/2005 - 15:24:48: [msglogging.amxx] MessageBegin TextMsg(77) Arguments=5 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
L 12/26/2005 - 15:24:48: [msglogging.amxx] Arg 1 (Byte): 5
L 12/26/2005 - 15:24:48: [msglogging.amxx] Arg 2 (String): 1
L 12/26/2005 - 15:24:48: [msglogging.amxx] Arg 3 (String): #Game_radio
L 12/26/2005 - 15:24:48: [msglogging.amxx] Arg 4 (String): VEN
L 12/26/2005 - 15:24:48: [msglogging.amxx] Arg 5 (String): #Cover_me
L 12/26/2005 - 15:24:48: [msglogging.amxx] MessageEnd TextMsg(77)
*/

/* **************************************************** EOF **************************************************** */
