// trak3r@hotmail.com -- http://zeal.dyndns.org
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_CONSOLE 131072
 
#define TERRORISTS 1
#define COUNTER_TERRORISTS 2
 
slay_team( chumps ) {
 
	new i;
	new session;
	new wonid;
	new team;
	new name[ MAX_NAME_LENGTH ];
 
	for( i = 1; i <= MAX_PLAYERS; i++ ) {
		if( 1 == playerinfo( i, name, MAX_NAME_LENGTH, session, wonid, team ) ) {
			if( team == chumps ) {
				slay( name );
			}
		}
	}
	return PLUGIN_CONTINUE;
}
 
new vip;
new suicide = 0;
 
public logd_suicide( HLCommand, HLData, HLUserName, UserIndex ) {
	new i;
	new session;
	new wonid;
	new team;
	new dead;
 
	new parameter[ MAX_DATA_LENGTH ];
	new player[ MAX_DATA_LENGTH ];
	new weapon[ MAX_DATA_LENGTH ];
	new name[ MAX_TEXT_LENGTH ];
	new msg[ MAX_TEXT_LENGTH ];
 
	convert_string( HLData, parameter, MAX_DATA_LENGTH );
 
	strsplit( parameter, " ", player, MAX_DATA_LENGTH, weapon, MAX_DATA_LENGTH );
 
	i = strtonum( player );
 
	if( playerinfo( i, name, MAX_NAME_LENGTH, session, wonid, team, dead ) ) {
		if( i == vip ) {
			snprintf( msg, MAX_TEXT_LENGTH, "%s HAS BEEN KICKED FOR SUICIDING AS VIP.", name );
			say( msg );
 
			kick( name );
			suicide = 1;
		}
	}
}
 
public logd_player_action( HLCommand, HLData, HLUserName, UserIndex ) {
	new i;
	new session;
	new wonid;
	new team;
	new dead;
 
	new parameter[ MAX_DATA_LENGTH ];
	new player[ MAX_DATA_LENGTH ];
	new action[ MAX_DATA_LENGTH ];
	new name[ MAX_TEXT_LENGTH ];
	new msg[ MAX_TEXT_LENGTH ];
 
	convert_string( HLData, parameter, MAX_DATA_LENGTH );
 
	strsplit( parameter, " ", player, MAX_DATA_LENGTH, action, MAX_DATA_LENGTH );
 
	i = strtonum( player );
 
	if( 0 == strcmp( action, "Killed_A_Hostage" ) ) {
		if( playerinfo( i, name, MAX_NAME_LENGTH, session, wonid, team, dead ) ) {
			snprintf( msg, MAX_TEXT_LENGTH, "%s HAS BEEN SLAIN FOR EXECUTING A HOSTAGE.", name );
			say( msg );
			slay( name );
		}
	}
	else if( 0 == strcmp( action, "Dropped_The_Bomb" ) ) {
		if( playerinfo( i, name, MAX_NAME_LENGTH, session, wonid, team, dead ) ) {
			if( ! dead ) {
				snprintf( msg, MAX_TEXT_LENGTH, "%s HAS BEEN SLAIN FOR INTENTIONALLY DROPPING THE BOMB.", name );
				say( msg );
				slay( name );
			}
		}
	}
	else if( 0 == strcmp( action, "Became_VIP" ) ) {
		vip = i;
		suicide = 0;
	}
}
 
public logd_team_action( HLCommand, HLData, HLUserName, UserIndex ) {
 
	new parameter[ MAX_DATA_LENGTH ];
	new team[ MAX_DATA_LENGTH ];
	new action[ MAX_DATA_LENGTH ];
 
	convert_string( HLData, parameter, MAX_DATA_LENGTH );
 
	strsplit( parameter, " ", team, MAX_DATA_LENGTH, action, MAX_DATA_LENGTH );
 
	if( 0 == strcmp( action, "Bomb_Defused" ) ) {
		slay_team( TERRORISTS );
	}
	else if( 0 == strcmp( action, "Target_Saved" ) ) {
		slay_team( TERRORISTS );
	}
	else if( 0 == strcmp( action, "All_Hostages_Rescued" ) ) {
		slay_team( TERRORISTS );
	}
	else if( 0 == strcmp( action, "VIP_Escaped" ) ) {
		slay_team( TERRORISTS );
	}
	else if( 0 == strcmp( action, "Target_Bombed" ) ) {
		slay_team( COUNTER_TERRORISTS );
	}
	else if( 0 == strcmp( action, "VIP_Assassinated" ) ) {
		if( suicide ) {
			// no punishment
		}
		else {
			slay_team( COUNTER_TERRORISTS );
		}
	}
	else if( 0 == strcmp( action, "VIP_Not_Escaped" ) ) {
		slay_team( COUNTER_TERRORISTS );
	}
	else if( 0 == strcmp( action, "Hostages_Not_Rescued" ) ) {
		slay_team( COUNTER_TERRORISTS );
	}
 
	return PLUGIN_CONTINUE;
}
 
public plugin_init() {
	plugin_registerinfo( "Plugin_LogD_Team_Goals", "Teams achieve their goals or everyone dies.", "0.9" );
 
	plugin_registercmd( "logd_team_action", "logd_team_action", ACCESS_CONSOLE, "" );
	plugin_registercmd( "logd_player_action", "logd_player_action", ACCESS_CONSOLE, "" );
	plugin_registercmd( "logd_suicide", "logd_suicide", ACCESS_CONSOLE, "" );
 
	exec( "logd_reg 61 admin_command logd_team_action" );
	exec( "logd_reg 60 admin_command logd_player_action" );
	exec( "logd_reg 53 admin_command logd_suicide" );
 
	return PLUGIN_CONTINUE;
}