/**
 * Bud-froggy Productions -- April 5th, 2001
 * Knife Arena® -- Beta 4
 * ...here the real skillz are evident :]
 *
 * Place in logd_
 */
 
/**
 * Sepcial thx to yensid for solving my "problem" :)
 *
 */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH]= "v0.4";
 
#define ACCESS_KA 8192
#define ACCESS_CONSOLE 131072
#define TIMER_DELAY 1
 
new X[ MAX_PLAYERS ];
new Y[ MAX_PLAYERS ];
new Z[ MAX_PLAYERS ];
new maxplayers;
 
new Announce[MAX_DATA_LENGTH] = "Knife Arena: knives only baybay!";
 
 
public admin_ka(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	if( strcmp( Data, "1" ) == 0 ) {
		set_vaultdata("logd_ka","1");
		plugin_exec("admin_restartround","15");
		centersay("Knife Arena will begin in 10 seconds.",10, 10, 255, 255);
		plugin_exec("admin_restrict","all");
	} else if( strcmp( Data, "0" ) == 0 ) {
		centersay("*snif* no more knife arena...", 12, 10, 255, 255); //
		set_vaultdata("logd_ka","0");
		plugin_exec("admin_unrestrict","all");
	}
	log_command(User,Command,Data);
	return PLUGIN_HANDLED;
}
 
public logd_knifearena(HLCommand,HLData,HLUserName,UserIndex) {
	new iKA;
	new sKA[3];
 
	new Data[MAX_NAME_LENGTH];
	convert_string(HLData,Data,MAX_NAME_LENGTH);
 
	if( strcmp( "Round_Start", Data ) != 0 )
		return PLUGIN_HANDLED;
 
	if(!get_vaultdata("logd_ka", sKA, 3)) {
		log("[ADMIN] Knife Arena: vault entry doesn't exist, creating entry 'false'.");
		set_vaultdata("logd_ka","0");
		return PLUGIN_HANDLED;
	}
 
	iKA = strtonum(sKA);
	if(!iKA)
		return PLUGIN_HANDLED;
 
	WeaponRemover();
	return PLUGIN_HANDLED;
}
 
public resetPositions(Timer,Repeat,HLName,HLParam) {
	new i;
	new Name[MAX_NAME_LENGTH];
	new tempZ;
 
	for (i=1; i <= maxplayers; i++) {
		if(playerinfo(i,Name,MAX_NAME_LENGTH)==1) {
			tempZ = 10 + Z[ i ]; //make sure they don't clip the ground
			teleport(Name, X[ i ], Y[ i ], tempZ);
		}
	}
	centersay(Announce,13,10,255,255);
}
 
WeaponRemover() {
	new i;
	new Name[MAX_NAME_LENGTH];
	new tempZ;
	maxplayers = maxplayercount();
 
	/* Go through team and drop all weapons...including bomb */
	for (i=1; i <= maxplayers; i++) {
		if(playerinfo(i,Name,MAX_NAME_LENGTH)==1) {
			get_userorigin(Name, X[ i ], Y[ i ], Z[ i ]);
			tempZ = Z[ i ] - 1500;
			teleport(Name, X[ i ], Y[ i ], tempZ);
 
			execclient(Name, "drop");
			execclient(Name, "drop");
			execclient(Name, "drop");
		} //end if(player
	} //end for loop
	set_timer("resetPositions",TIMER_DELAY,1);
}
 
public plugin_init()
{
	plugin_registerinfo("Knife Arena","For playing knife only. To enable, set to 1.",STRING_VERSION);
	plugin_registercmd("admin_ka", "admin_ka", ACCESS_KA, "admin_ka <1 || 0> Play in a knife arena (knife only).");
	plugin_registercmd("logd_knifearena", "logd_knifearena", ACCESS_CONSOLE, "");
 
	exec( "logd_reg 62 admin_command logd_knifearena" );
	return PLUGIN_CONTINUE;
}