/* AMX Mod X
*   TA Autoknife
*
* (c) Copyright 2005 by VEN
*
* This file is provided as is (no warranties)
*
*     DESCRIPTION:
*       This plugin force player switch to knife if he attacked a teammate.
*       Note: plugin wouldn't work for team attacks with HE grenades.
*
*     REQUIREMENT:
*       Attacker must have a knife. :)
*
*     DEFINES:
*       CVAR_TA_AUTOKNIFE - name of cvar which enables plugin
*       SWITCH_WEAPON_NAME - name of weapon to switch (you can specify any other weapon name if you wish)
*
*     CVARS:
*       amx_ta_autoknife - set to 1 to enable plugin (0: OFF, 1: ON, default: 1)
*
*     VERSIONS:
*       0.1   first release
*/

#include <amxmodx>

#define PLUGIN_NAME "TA Autoknife"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "VEN"

#define CVAR_TA_AUTOKNIFE "amx_ta_autoknife" // name of cvar which enables plugin
#define SWITCH_WEAPON_NAME "weapon_knife" // name of weapon to switch

public plugin_init() {
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR) // register plugin
	register_event("TextMsg", "event_text_msg", "bc", "1=3", "2=#Game_teammate_attack") // "Player attacked a teammate" chat text message event
	register_cvar(CVAR_TA_AUTOKNIFE, "1") // register cvar (plugin enabled by default)
}

public event_text_msg() {
	if (get_cvar_num(CVAR_TA_AUTOKNIFE)) { // if plugin enabled
		new name[32]
		read_data(3, name, 31) // get name of a player who attacks a teammate
		new id = get_user_index(name) // get id of a player who attacks a teammate
		engclient_cmd(id, SWITCH_WEAPON_NAME) // force attacker switch to defined weapon
	}
}

/*
L 11/27/2005 - 17:03:51: [msglogging.amxx] MessageBegin TextMsg(77) Arguments=3 Destination=One(1) Origin={0.000000 0.000000 0.000000} Entity=1 Classname=player Netname=VEN
L 11/27/2005 - 17:03:51: [msglogging.amxx] Arg 1 (Byte): 3
L 11/27/2005 - 17:03:51: [msglogging.amxx] Arg 2 (String): #Game_teammate_attack
L 11/27/2005 - 17:03:51: [msglogging.amxx] Arg 3 (String): VEN
L 11/27/2005 - 17:03:51: [msglogging.amxx] MessageEnd TextMsg(77)
*/
