#include <amxmodx>

#pragma semicolon                1      
    
new g_scTitle[]   = "Last Round";
new g_scVersion[] = "2.0";
new g_scAuthor[]  = "many";
    
new bool:g_lastround = false;
new bool:g_changemap = false;
new Float:g_timelimit = 0.0;
new Float:g_maxspeed;

#define INITIATE_LAST_ROUND_TASK 545454
#define CHANGE_MAP_TASK 545455
#define DISABLE_PLAYERS_TASK 545456

public evRoundStart() {
	if (!get_cvar_num("lastround")) return PLUGIN_CONTINUE;

	// Wanted this in init but never got a value 
	if (g_timelimit == 0.0)
		g_timelimit = get_cvar_float("mp_timelimit");

	if (g_lastround) {
	        set_cvar_float("mp_timelimit", 0.0);
					
		new text[256];
		format(text, 255, "This is the final round");
		doTypesay(text, 5, 255, 255, 255);

		g_changemap = true;
		g_lastround = false;
	} else if (g_changemap) {
		new nextmap[32];
	        get_cvar_string("amx_nextmap", nextmap, 31);
	
		new text[256];
		format(text, 255, "Thank you for playing. Now switching to %s!", nextmap);
		doTypesay(text, 5, 255, 255, 255);

		g_maxspeed = get_cvar_float("sv_maxspeed");
		set_cvar_float("sv_maxspeed", 0.0);

                set_task(0.1, "disablePlayers", DISABLE_PLAYERS_TASK, "", 0, "a", 4);
                set_task(6.0, "changeMap", CHANGE_MAP_TASK);
	}

        return PLUGIN_CONTINUE;
}

public initiateLastRound() {
	if (!get_cvar_num("lastround")) return PLUGIN_CONTINUE;

	remove_task(INITIATE_LAST_ROUND_TASK);

	new text[256];
	format(text, 255, "The final round is coming up");
        doTypesay(text, 5, 255, 255, 255);

	set_cvar_float("mp_timelimit", 0.0);

	g_lastround = true;

	return PLUGIN_CONTINUE;
}

public disablePlayers() {
        server_cmd("mp_friendlyfire 0");
        new players[32], num;
        get_players(players, num, "c");
        for(new i=0;i<num; i++) {
		client_cmd(players[i],"hud_fastswitch 1");
		client_cmd(players[i],"slot1");
		client_cmd(players[i],"drop");
		client_cmd(players[i],"slot2");
		client_cmd(players[i],"drop");
		client_cmd(players[i],"slot5");
		client_cmd(players[i],"drop");
}

	register_clcmd("galil", "cmdBlock");
	register_clcmd("defender", "cmdBlock");
	register_clcmd("ak47", "cmdBlock");
	register_clcmd("cv47", "cmdBlock");
	register_clcmd("scout", "cmdBlock");
	register_clcmd("sg552", "cmdBlock");
	register_clcmd("krieg552", "cmdBlock");
	register_clcmd("awp", "cmdBlock");
	register_clcmd("magnum", "cmdBlock");
	register_clcmd("g3sg1", "cmdBlock");
	register_clcmd("d3au1", "cmdBlock");
	register_clcmd("famas", "cmdBlock");
	register_clcmd("clarion", "cmdBlock");
	register_clcmd("m4a1", "cmdBlock");
	register_clcmd("aug", "cmdBlock");
	register_clcmd("bullpup", "cmdBlock");
	register_clcmd("sg550", "cmdBlock");
	register_clcmd("krieg550", "cmdBlock");
	register_clcmd("glock", "cmdBlock");
	register_clcmd("9x19mm", "cmdBlock");
	register_clcmd("usp", "cmdBlock");
	register_clcmd("km45", "cmdBlock");
	register_clcmd("p228", "cmdBlock");
	register_clcmd("228compact", "cmdBlock");
	register_clcmd("deagle", "cmdBlock");
	register_clcmd("nighthawk", "cmdBlock");
	register_clcmd("elites", "cmdBlock");
	register_clcmd("fn57", "cmdBlock");
	register_clcmd("fiveseven", "cmdBlock");
	register_clcmd("m3", "cmdBlock");
	register_clcmd("12gauge", "cmdBlock");
	register_clcmd("xm1014", "cmdBlock");
	register_clcmd("autoshotgun", "cmdBlock");
	register_clcmd("mac10", "cmdBlock");
	register_clcmd("tmp", "cmdBlock");
	register_clcmd("mp", "cmdBlock");
	register_clcmd("mp5", "cmdBlock");
	register_clcmd("smg", "cmdBlock");
	register_clcmd("ump45", "cmdBlock");
	register_clcmd("p90", "cmdBlock");
	register_clcmd("c90", "cmdBlock");
	register_clcmd("m249", "cmdBlock");
	register_clcmd("primammo", "cmdBlock");
	register_clcmd("secammo", "cmdBlock");
	register_clcmd("vest", "cmdBlock");
	register_clcmd("vesthelm", "cmdBlock");
	register_clcmd("flash", "cmdBlock");
	register_clcmd("hegren", "cmdBlock");
	register_clcmd("sgren", "cmdBlock");
	register_clcmd("nvgs", "cmdBlock");
	register_clcmd("defuser", "cmdBlock");
	register_clcmd("shield", "cmdBlock");
	register_clcmd("buyammo1", "cmdBlock");
	register_clcmd("buyammo2", "cmdBlock");
	register_clcmd("impulse 201", "cmdBlock");
	register_clcmd("jointeam 1", "cmdBlock");
	register_clcmd("chooseteam", "cmdBlock");
	register_clcmd("buy", "cmdBlock");
	register_clcmd("buyammo1", "cmdBlock");
	register_clcmd("buyammo2", "cmdBlock");
	register_clcmd("buyequip", "cmdBlock");
	register_clcmd("cl_autobuy", "cmdBlock");
	register_clcmd("cl_rebuy", "cmdBlock");
	register_clcmd("cl_setautobuy", "cmdBlock");
	register_clcmd("cl_setrebuy", "cmdBlock");
	register_clcmd("fullupdate", "cmdBlock");
	register_clcmd("radio1", "cmdBlock");
	register_clcmd("radio2", "cmdBlock");
	register_clcmd("radio3", "cmdBlock");
	register_clcmd("coverme", "cmdBlock");
	register_clcmd("takepoint", "cmdBlock");
	register_clcmd("holdpos", "cmdBlock");
	register_clcmd("regroup", "cmdBlock");
	register_clcmd("followme", "cmdBlock");
	register_clcmd("takingfire", "cmdBlock");
	register_clcmd("go", "cmdBlock");
	register_clcmd("fallback", "cmdBlock");
	register_clcmd("sticktog", "cmdBlock");
	register_clcmd("getinpos", "cmdBlock");
	register_clcmd("stormfront", "cmdBlock");
	register_clcmd("report", "cmdBlock");
	register_clcmd("roger", "cmdBlock");
	register_clcmd("enemyspot", "cmdBlock");
	register_clcmd("needbackup", "cmdBlock");
	register_clcmd("sectorclear", "cmdBlock");
	register_clcmd("inposition", "cmdBlock");
	register_clcmd("reportingin", "cmdBlock");
	register_clcmd("getout", "cmdBlock");
	register_clcmd("negative", "cmdBlock");
	register_clcmd("enemydown", "cmdBlock");
}

public changeMap() {
	remove_task(CHANGE_MAP_TASK);

        new nextmap[32];
        get_cvar_string("amx_nextmap", nextmap, 31);
        server_cmd("changelevel %s", nextmap);
}

doTypesay(string[], duration, r, g, b) {
        set_hudmessage(r, g, b, 0.05, 0.45, 0, 6.0, float(duration) , 0.5, 0.15, 4);
        show_hudmessage(0, string);
}
					
public plugin_init() {
        register_plugin(g_scTitle, g_scVersion, g_scAuthor);

        register_cvar("lastround", "1");
	register_logevent("evRoundStart", 2, "0=World triggered", "1=Round_Start");

	// Chose 90 seconds not to clash with other events
	set_task(90.0, "initiateLastRound", INITIATE_LAST_ROUND_TASK, "", 0, "d");

	return PLUGIN_CONTINUE;
}

public cmdBlock(id)
{
	if (g_changemap)
		return PLUGIN_HANDLED;

	return PLUGIN_CONTINUE;
}


public plugin_end() {
	set_cvar_float("mp_timelimit", g_timelimit);
	set_cvar_float("sv_maxspeed", g_maxspeed);
	server_cmd("mp_friendlyfire 1");


	remove_task(DISABLE_PLAYERS_TASK);

	return PLUGIN_CONTINUE;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/
