#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

public Plugin myinfo = 
{
	name = "Fun Super Admin",
	author = "Moltard / LightningZLaser",
	description = "Admin Plugin with fun commands",
	version = "0.1",
	url = "https://steamcommunity.com/id/0123456789ABC/"
};

Menu g_MainMenu = null;
Menu g_BuryMenu = null;
Menu g_UnburyMenu = null;
Menu g_GodMenu = null;
Menu g_InvisMenu = null;
Menu g_JetpackMenu = null;
Menu g_RegenMenu = null;
Menu g_RocketMenu = null;

int GodStatus[MAXPLAYERS + 1] = 0; // List of players that have god mode
int InvisStatus[MAXPLAYERS + 1] = 0; // List of players that have invisibility
int JetpackStatus[MAXPLAYERS + 1] = 0; // List of players that have a jetpack
int RegenStatus[MAXPLAYERS + 1] = 0; // List of players that have regen mode
int RocketStatus[MAXPLAYERS + 1] = 0; // List of players that are in rocket mode

bool bl_RegenInit = false; // Prevent the timer from looking at each player until the command is used once

ConVar g_RocketMode;
ConVar g_RocketKill;
ConVar g_RocketSpeed;
bool bl_RocketMode_1 = false;
bool bl_RocketMode_2 = false;
bool bl_RocketInit = false; // Prevent the timer from executing until the command is used once
new rocketSprite[MAXPLAYERS + 1]; // Will contain the env_spritetrail created

int g_RocketPosition[MAXPLAYERS + 1] = 1; // To alternate between Origin Z1 and Origin Z2
float g_Rocket_Vec1[MAXPLAYERS + 1][3];
float g_Rocket_Vec2[MAXPLAYERS + 1][3];
float g_Rocket_Z1[MAXPLAYERS + 1] = 0.0;
float g_Rocket_Z2[MAXPLAYERS + 1] = 1.0;

public void OnPluginStart()
{
	LoadTranslations("common.phrases");
	
	HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
	HookEvent("player_death", OnPlayerDie, EventHookMode_PostNoCopy);
	
	RegAdminCmd("sm_fsa", Command_MainMenu, ADMFLAG_CHANGEMAP); // g
	RegAdminCmd("sm_bury", Command_Bury, ADMFLAG_CHANGEMAP);
	RegAdminCmd("sm_unbury", Command_Unbury, ADMFLAG_CHANGEMAP);
	
	RegAdminCmd("sm_god", Command_God, ADMFLAG_CHANGEMAP);
	RegAdminCmd("sm_godmode", Command_God, ADMFLAG_CHANGEMAP);
	
//	RegAdminCmd("sm_alpha", Command_Alpha, ADMFLAG_CHANGEMAP);
	RegAdminCmd("sm_invis", Command_Invis, ADMFLAG_CHANGEMAP);
	RegAdminCmd("sm_invisible", Command_Invis, ADMFLAG_CHANGEMAP);
	
	RegAdminCmd("sm_jet", Command_Jetpack, ADMFLAG_CHANGEMAP);
	RegAdminCmd("sm_jetpack", Command_Jetpack, ADMFLAG_CHANGEMAP);
	
	RegAdminCmd("sm_regen", Command_Regen, ADMFLAG_CHANGEMAP);
	CreateTimer(1.5, Timer_Regeneration, _, TIMER_REPEAT);
	
	RegAdminCmd("sm_stealcookies", Command_Cookies, ADMFLAG_CHANGEMAP);
	RegAdminCmd("sm_givecookies", Command_Cookies2, ADMFLAG_CHANGEMAP);
	
	RegAdminCmd("sm_rocket", Command_Rocket, ADMFLAG_CHANGEMAP);
	CreateTimer(0.1, Timer_Rocket, _, TIMER_REPEAT);
	
	CreateConVar("fsa_rocket_type", "2", "Rocket type 1 does not work in Zombie: Reloaded while rocket type 2 does", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	g_RocketMode = FindConVar("fsa_rocket_type");
	if (g_RocketMode != null)
	{
		g_RocketMode.AddChangeHook(OnRocketModeChange);
	}
	
	CreateConVar("fsa_rocket_will_kill", "0", "Set to 1 so that players will die when rocketted", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	g_RocketKill = FindConVar("fsa_rocket_will_kill");
	if (g_RocketKill != null)
	{
		g_RocketKill.AddChangeHook(OnRocketKillChange);
	}
	
	CreateConVar("fsa_rocket_speed", "20.0", "Sets rocket speed. Important note: Must be higher than 5 (6 at least)", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	g_RocketSpeed = FindConVar("fsa_rocket_speed");
	if (g_RocketSpeed != null)
	{
		g_RocketSpeed.AddChangeHook(OnRocketSpeedChange);
	}
}

public void OnRocketModeChange(ConVar convar, char[] oldValue, char[] newValue)
{
	if (StringToInt(newValue) == 1)
	{
		convar.IntValue = 1;
		bl_RocketMode_1 = true;
		bl_RocketMode_2 = false;
	}
	else if (StringToInt(newValue) == 2){
		convar.IntValue = 2;
		bl_RocketMode_1 = false;
		bl_RocketMode_2 = true;
	}
	else{
		convar.IntValue = StringToInt(oldValue);
	}
}

public void OnRocketSpeedChange(ConVar convar, char[] oldValue, char[] newValue)
{
	if (StringToFloat(newValue) != 0)
	{
		if (StringToFloat(newValue) >= 6){
			convar.FloatValue = StringToFloat(newValue);
		}
		else{
			convar.FloatValue = 6.0;
		}
	}
	else{
		convar.FloatValue = StringToFloat(oldValue);
	}
}

public void OnRocketKillChange(ConVar convar, char[] oldValue, char[] newValue)
{
	if (StringToInt(newValue) == 0)
	{
		convar.IntValue = 0;
	}
	else if(StringToInt(newValue) == 1){
		convar.IntValue = 1;
	}
	else{
		convar.IntValue = StringToInt(oldValue);
	}
}

public void OnMapStart()
{
	g_MainMenu = BuildMainMenu();
	g_BuryMenu = InitAllPlayersMenu("bury");
	g_UnburyMenu = InitAllPlayersMenu("unbury");
	g_GodMenu = InitAllPlayersMenu("god");
	g_InvisMenu = InitAllPlayersMenu("invis");
	g_JetpackMenu = InitAllPlayersMenu("jetpack");
	g_RegenMenu = InitAllPlayersMenu("regen");
	g_RocketMenu = InitAllPlayersMenu("rocket");
	
	if (g_RocketMode != null)
	{
		if(g_RocketMode.IntValue == 1){
			bl_RocketMode_1 = true;
			bl_RocketMode_2 = false;
		}
		else{
			bl_RocketMode_1 = false;
			bl_RocketMode_2 = true;
		}
	}
	// Precache for rocket 
	PrecacheModel("sprites/sprite_fire01.vmt", false);
	PrecacheSound("weapons/rpg/rocketfire1.wav", false);
	PrecacheSound("weapons/rpg/rocket1.wav", false);
	PrecacheSound("weapons/explode3.wav", false);
	
}

public void OnMapEnd()
{
	if (g_MainMenu != null)
	{
		delete(g_MainMenu);
		g_MainMenu = null;
	}
	if (g_BuryMenu != null)
	{
		delete(g_BuryMenu);
		g_BuryMenu = null;
	}
	if (g_UnburyMenu != null)
	{
		delete(g_UnburyMenu);
		g_UnburyMenu = null;
	}
	if (g_GodMenu != null)
	{
		delete(g_GodMenu);
		g_GodMenu = null;
	}
	if (g_InvisMenu != null)
	{
		delete(g_InvisMenu);
		g_InvisMenu = null;
	}
	if (g_JetpackMenu != null)
	{
		delete(g_JetpackMenu);
		g_JetpackMenu = null;
	}
	if (g_RegenMenu != null)
	{
		delete(g_RegenMenu);
		g_RegenMenu = null;
	}
	if (g_RocketMenu != null)
	{
		delete(g_RocketMenu);
		g_RocketMenu = null;
	}
	
}

public OnRoundStart(Handle event, const String:name[], bool dontBroadcast) 
{ 
	bl_RegenInit = false;
	bl_RocketInit = false;
	for(int i = 1; i <= (GetMaxClients()); i++){
		if(IsValidEntity(i)){
			GodStatus[i] = 0;
			InvisStatus[i] = 0;
			JetpackStatus[i] = 0;
			RegenStatus[i] = 0;
			RocketStatus[i] = 0;
			SetEntityGravity(i, 1.0);
			
			if((IsClientInGame(i)) && (IsPlayerAlive(i))){
				SetEntityRenderMode(i, RENDER_NORMAL);
			}
		}
	}
}

public OnPlayerDie(Handle event, const String:name[], bool dontBroadcast)
{
	int idClient = GetClientOfUserId(GetEventInt(event, "userid")); // Get Player's userid
	if(IsValidEntity(idClient)){
		GodStatus[idClient] = 0;
		InvisStatus[idClient] = 0;
		JetpackStatus[idClient] = 0;
		RegenStatus[idClient] = 0;
		RocketStatus[idClient] = 0;
		SetEntityGravity(idClient, 1.0);
	}
}  

public void OnClientDisconnect(int client){
	GodStatus[client] = 0;
	JetpackStatus[client] = 0;
	RegenStatus[client] = 0;
	RocketStatus[client] = 0;
}

/* ----------------------------------- */

Menu BuildMainMenu(){
	Menu menu = new Menu(MainMenuHandler);
	menu.SetTitle("Fun Super Admin");
	menu.AddItem("menu_rocket_debug", "Fix Rocket Spam");
	menu.AddItem("menu_rocket", "Rocket");
	menu.AddItem("menu_bury", "Bury");
	menu.AddItem("menu_unbury", "Unbury");
	menu.AddItem("menu_god", "Godmode");
	menu.AddItem("menu_invisible", "Invisible");
	menu.AddItem("menu_jetpack", "Jetpack");
	menu.AddItem("menu_regen", "Regeneration");
	
	menu.ExitBackButton = true;
	return menu;
}

void displayMainMenu(client){
	g_MainMenu.Display(client, MENU_TIME_FOREVER);
}

public Action Command_MainMenu(int client, int args)
{
	displayMainMenu(client);
	return Plugin_Handled;
}

public MainMenuHandler(Menu menu, MenuAction action, int client, int param2)
{
	char info[32];
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			if(StrEqual(info, "menu_bury")){
				BuildPlayerMenu("bury");
				g_BuryMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_unbury")){
				BuildPlayerMenu("unbury");
				g_UnburyMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_god")){
				BuildPlayerMenu("god");
				g_GodMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_invisible")){
				BuildPlayerMenu("invis");
				g_InvisMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_jetpack")){
				BuildPlayerMenu("jetpack");
				g_JetpackMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_regen")){
				BuildPlayerMenu("regen");
				g_RegenMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_rocket")){
				BuildPlayerMenu("rocket");
				g_RocketMenu.Display(client, MENU_TIME_FOREVER);
			}
			else if(StrEqual(info, "menu_rocket_debug")){
				StopAllRocketSound();
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}

/* ----------------------------------- */

Menu InitAllPlayersMenu(char[] menuType){
	Menu menu = null;
	if(StrEqual(menuType, "bury"))
	{
		menu = new Menu(BuryHandle);
		menu.SetTitle("Select Player to Bury");
	}
	else if(StrEqual(menuType, "unbury"))
	{
		menu = new Menu(UnburyHandle);
		menu.SetTitle("Select Player to Unbury");
	}
	else if(StrEqual(menuType, "god"))
	{
		menu = new Menu(GodHandle);
		menu.SetTitle("Select Player for Godmode");
	}
	else if(StrEqual(menuType, "invis"))
	{
		menu = new Menu(InvisHandle);
		menu.SetTitle("Select Player for Invisibility");
	}
	else if(StrEqual(menuType, "jetpack"))
	{
		menu = new Menu(JetpackHandle);
		menu.SetTitle("Select Player to Give/Remove Jetpack");
	}
	else if(StrEqual(menuType, "regen"))
	{
		menu = new Menu(RegenHandle);
		menu.SetTitle("Select Player to Give/Remove Regeneration");
	}
	else if(StrEqual(menuType, "rocket"))
	{
		menu = new Menu(RocketHandle);
		menu.SetTitle("Select Player to turn into a Rocket");
	}
	menu.ExitBackButton = true;
	menu.ExitButton = true;
	return menu;
}


void BuildPlayerMenu(char[] menuType){

	if(StrEqual(menuType, "bury"))
	{
		g_BuryMenu.RemoveAllItems();
	}
	else if(StrEqual(menuType, "unbury"))
	{
		g_UnburyMenu.RemoveAllItems();
	}
	else if(StrEqual(menuType, "god"))
	{
		g_GodMenu.RemoveAllItems();
	}
	else if(StrEqual(menuType, "invis"))
	{
		g_InvisMenu.RemoveAllItems();
	}
	else if(StrEqual(menuType, "jetpack"))
	{
		g_JetpackMenu.RemoveAllItems();
	}
	else if(StrEqual(menuType, "regen"))
	{
		g_RegenMenu.RemoveAllItems();
	}
	else if(StrEqual(menuType, "rocket"))
	{
		g_RocketMenu.RemoveAllItems();
	}
	for (int i = 1; i <= GetMaxClients(); i++)
	{
		if ((IsClientInGame(i)) && IsPlayerAlive(i))
		{
			char sIndex[11]; 
			IntToString(GetClientSerial(i),sIndex, sizeof(sIndex)); // Serial of the player
			
			char playerName[64]; char labelName[64];
			GetClientName(i, playerName, sizeof(playerName));
			
			if (GodStatus[i] == 1 && StrEqual(menuType, "god"))
			{
				Format(labelName,sizeof(labelName),"[GOD] %s",playerName); // [GOD] Name
			}
			else if (InvisStatus[i] == 1 && StrEqual(menuType, "invis"))
			{
				Format(labelName,sizeof(labelName),"[INVISIBLE] %s",playerName); // [JETPACK] Name
			}
			else if (JetpackStatus[i] == 1 && StrEqual(menuType, "jetpack"))
			{
				Format(labelName,sizeof(labelName),"[JETPACK] %s",playerName); // [JETPACK] Name
			}
			else if (RegenStatus[i] == 1 && StrEqual(menuType, "regen"))
			{
				Format(labelName,sizeof(labelName),"[REGEN] %s",playerName); // [REGEN] Name
			}
			else if (RocketStatus[i] == 1 && StrEqual(menuType, "rocket"))
			{
				Format(labelName,sizeof(labelName),"[ROCKET] %s",playerName); // [ROCKET] Name
			}
			else
			{
				labelName = playerName; // Name
			}
			
			if(StrEqual(menuType, "bury"))
			{
				g_BuryMenu.AddItem(sIndex,labelName);
			}
			else if(StrEqual(menuType, "unbury"))
			{
				g_UnburyMenu.AddItem(sIndex,labelName);
			}
			else if(StrEqual(menuType, "god"))
			{
				g_GodMenu.AddItem(sIndex,labelName);
			}
			else if(StrEqual(menuType, "invis"))
			{
				g_InvisMenu.AddItem(sIndex,labelName);
			}
			else if(StrEqual(menuType, "jetpack"))
			{
				g_JetpackMenu.AddItem(sIndex,labelName);
			}
			else if(StrEqual(menuType, "regen"))
			{
				g_RegenMenu.AddItem(sIndex,labelName);
			}
			else if(StrEqual(menuType, "rocket"))
			{
				g_RocketMenu.AddItem(sIndex,labelName);
			}
		}
	}
}



/* ----------------------------------- */

public Action Command_Bury(int client, int args)
{
	if(args < 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_bury [#userid|name]");
		BuildPlayerMenu("bury");
		g_BuryMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 1)
	{
		char sArgs[64];
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}

		for(int i = 0; i < iTargetCount; i++)
		{
			float buryOrigin[3];
			GetClientAbsOrigin(iTargets[i], buryOrigin);
			buryOrigin[2] = buryOrigin[2] - 50;
			TeleportEntity(iTargets[i], buryOrigin, NULL_VECTOR, NULL_VECTOR);
		}
		ShowActivity2(client, "\x01[SM] \x04", "\x01Buried \x04%s\x01.", sTargetName);
		if(iTargetCount > 1)
			LogAction(client, -1, "\"%L\" buried \"%s\".", client, sTargetName);
		else
			LogAction(client, iTargets[0], "\"%L\" buried \"%L\".", client, iTargets[0]);

		return Plugin_Handled;
	}
	else // args > 1
	{
		ReplyToCommand(client, "[SM] Usage: sm_bury [#userid|name]");
		return Plugin_Handled;
	}
}

public Action Command_Unbury(int client, int args)
{
	if(args < 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_unbury [#userid|name]");
		BuildPlayerMenu("unbury");
		g_UnburyMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 1)
	{
		char sArgs[64];
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}

		for(int i = 0; i < iTargetCount; i++)
		{
			float buryOrigin[3];
			GetClientAbsOrigin(iTargets[i], buryOrigin);
			buryOrigin[2] = buryOrigin[2] + 50;
			TeleportEntity(iTargets[i], buryOrigin, NULL_VECTOR, NULL_VECTOR);
		}
		ShowActivity2(client, "\x01[SM] \x04", "\x01Unburied \x04%s\x01.", sTargetName);
		if(iTargetCount > 1)
			LogAction(client, -1, "\"%L\" unburied \"%s\".", client, sTargetName);
		else
			LogAction(client, iTargets[0], "\"%L\" unburied \"%L\".", client, iTargets[0]);

		return Plugin_Handled;
	}
	else // args > 1
	{
		ReplyToCommand(client, "[SM] Usage: sm_unbury [#userid|name]");
		return Plugin_Handled;
	}
}

public BuryHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			int serialId = StringToInt(info);
			int playerId = GetClientFromSerial(serialId); // 0 if invalid
			if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
				
				float buryOrigin[3];
				GetClientAbsOrigin(playerId, buryOrigin);
				buryOrigin[2] = buryOrigin[2] - 50;
				TeleportEntity(playerId, buryOrigin, NULL_VECTOR, NULL_VECTOR);
				
				ShowActivity2(client, "\x01[SM] \x04", "\x01Buried \x04%N\x01.", playerId);
				LogAction(client, playerId, "\"%L\" buried \"%L\".", client,playerId);
			}
			BuildPlayerMenu("bury");
			g_BuryMenu.Display(client, MENU_TIME_FOREVER); // Display again the player menu 
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}

public UnburyHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			int serialId = StringToInt(info);
			int playerId = GetClientFromSerial(serialId); // 0 if invalid
			if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
				
				float buryOrigin[3];
				GetClientAbsOrigin(playerId, buryOrigin);
				buryOrigin[2] = buryOrigin[2] + 50;
				TeleportEntity(playerId, buryOrigin, NULL_VECTOR, NULL_VECTOR);
				
				ShowActivity2(client, "\x01[SM] \x04", "\x01Unburied \x04%N\x01.", playerId);
				LogAction(client, playerId, "\"%L\" unburied \"%L\".", client,playerId);
			}
			BuildPlayerMenu("unbury");
			g_UnburyMenu.Display(client, MENU_TIME_FOREVER); // Display again the player menu 
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}

/* ----------------------------------- */

public Action Command_God(int client, int args)
{
	if(args < 2)
	{
		ReplyToCommand(client, "[SM] Usage: sm_god [#userid|name] [0/1]");
		BuildPlayerMenu("god");
		g_GodMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 2)
	{
		char sArgs[64];
		char sValueGod[11];
		int iValueGod;
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		GetCmdArg(2, sValueGod, sizeof(sValueGod));
		iValueGod = StringToInt(sValueGod);
		if(iValueGod != 0){ // If the value is anything but 0, we set 1
			iValueGod = 1;
		}
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		
		if(iValueGod == 1){ // Add GodMode
			for(int i = 0; i < iTargetCount; i++)
			{
				GodStatus[iTargets[i]] = 1;
				SetEntProp(iTargets[i], Prop_Data, "m_takedamage", 0, 1);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Gave Godmode to \x04%s\x01.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" gave Godmode to \"%s\".", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" gave Godmode to \"%L\".", client, iTargets[0]);
		}
		else{ // Remove GodMode
			for(int i = 0; i < iTargetCount; i++)
			{
				GodStatus[iTargets[i]] = 0;
				SetEntProp(iTargets[i], Prop_Data, "m_takedamage", 2, 1);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%s\x01's Godmode.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" removed \"%s\"'s Godmode.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" removed \"%L\"'s Godmode.", client, iTargets[0]);
		}
		return Plugin_Handled;
	}
	else // args > 2
	{
		ReplyToCommand(client, "[SM] Usage: sm_god [#userid|name] [0/1]");
		return Plugin_Handled;
	}
}


public GodHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			int serialId = StringToInt(info);
			int playerId = GetClientFromSerial(serialId); // 0 if invalid
			if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
				
				if(GodStatus[playerId] == 0){ // Player doesnt have god mode 
					GodStatus[playerId] = 1;
					SetEntProp(playerId, Prop_Data, "m_takedamage", 0, 1);
					ShowActivity2(client, "\x01[SM] \x04", "\x01Gave Godmode to \x04%N\x01.", playerId);
					LogAction(client, playerId, "\"%L\" gave Godmode to \"%L\".", client, playerId);
				}
				else{ // Player already has god mode
					GodStatus[playerId] = 0;
					SetEntProp(playerId, Prop_Data, "m_takedamage", 2, 1);
					ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%N\x01's Godmode.", playerId);
					LogAction(client, playerId, "\"%L\" removed \"%L\"'s Godmode.", client, playerId);
				}
			}
			BuildPlayerMenu("god");
			g_GodMenu.Display(client, MENU_TIME_FOREVER); 
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}


/* ----------------------------------- */


public Action Command_Invis(int client, int args)
{
	if(args < 2)
	{
		ReplyToCommand(client, "[SM] Usage: sm_invis [#userid|name] [0/1]");
		BuildPlayerMenu("invis");
		g_InvisMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 2)
	{
		char sArgs[64];
		char sValueInvis[11];
		int iValueInvis;
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		GetCmdArg(2, sValueInvis, sizeof(sValueInvis));
		iValueInvis = StringToInt(sValueInvis);
		if(iValueInvis != 0){ // If the value is anything but 0, we set 1
			iValueInvis = 1;
		}
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		
		if(iValueInvis == 1){ // Set Invisibility
			for(int i = 0; i < iTargetCount; i++)
			{
				InvisStatus[iTargets[i]] = 1;
				SetEntityRenderMode(iTargets[i], RENDER_NONE);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Turned \x04%s\x01 invisible.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" turned \"%s\" invisible.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" turned \"%L\" invisible.", client, iTargets[0]);
		}
		else{ // Remove Invisibility
			for(int i = 0; i < iTargetCount; i++)
			{
				InvisStatus[iTargets[i]] = 0;
				SetEntityRenderMode(iTargets[i], RENDER_NORMAL);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Made \x04%s\x01 visible.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" made \"%s\" visible.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" made \"%L\" visible.", client, iTargets[0]);
		}
		return Plugin_Handled;
	}
	else // args > 2
	{
		ReplyToCommand(client, "[SM] Usage: sm_invis [#userid|name] [0/1]");
		return Plugin_Handled;
	}
}


public InvisHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			int serialId = StringToInt(info);
			int playerId = GetClientFromSerial(serialId); // 0 if invalid
			if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
				
				if(InvisStatus[playerId] == 0){ // Player isnt invisible
					InvisStatus[playerId] = 1;
					SetEntityRenderMode(playerId, RENDER_NONE);
					ShowActivity2(client, "\x01[SM] \x04", "\x01Turned \x04%N\x01 invisible.", playerId);
					LogAction(client, playerId, "\"%L\" turned \"%L\" invisible.", client, playerId);
				}
				else{ // Player is invisible
					InvisStatus[playerId] = 0;
					SetEntityRenderMode(playerId, RENDER_NORMAL);
					ShowActivity2(client, "\x01[SM] \x04", "\x01Made \x04%N\x01 visible.", playerId);
					LogAction(client, playerId, "\"%L\" made \"%L\" visible.", client, playerId);
				}
			}
			BuildPlayerMenu("invis");
			g_InvisMenu.Display(client, MENU_TIME_FOREVER); 
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}

/* ----------------------------------- */

public Action Command_Jetpack(int client, int args)
{
	if(args < 2)
	{
		ReplyToCommand(client, "[SM] Usage: sm_jetpack [#userid|name] [0/1]");
		BuildPlayerMenu("jetpack");
		g_JetpackMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 2)
	{
		char sArgs[64];
		char sValueJet[11];
		int iValueJet;
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		GetCmdArg(2, sValueJet, sizeof(sValueJet));
		iValueJet = StringToInt(sValueJet);
		if(iValueJet != 0){ // If the value is anything but 0, we set 1
			iValueJet = 1;
		}
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		
		if(iValueJet == 1){ // Set Jetpack
			for(int i = 0; i < iTargetCount; i++)
			{
				JetpackStatus[iTargets[i]] = 1;
				SetEntityMoveType(iTargets[i], MOVETYPE_FLY);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Gave Jetpack to \x04%s\x01.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" gave Jetpack to \"%s\".", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" gave Jetpack to \"%L\".", client, iTargets[0]);
		}
		else{ // Remove Jetpack
			for(int i = 0; i < iTargetCount; i++)
			{
				JetpackStatus[iTargets[i]] = 0;
				SetEntityMoveType(iTargets[i], MOVETYPE_WALK);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%s\x01's Jetpack.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" removed \"%s\"'s Jetpack.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" removed \"%L\"'s Jetpack.", client, iTargets[0]);
		}
		return Plugin_Handled;
	}
	else // args > 2
	{
		ReplyToCommand(client, "[SM] Usage: sm_jetpack [#userid|name] [0/1]");
		return Plugin_Handled;
	}
}


public JetpackHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			int serialId = StringToInt(info);
			int playerId = GetClientFromSerial(serialId); // 0 if invalid
			if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
				
				if(JetpackStatus[playerId] == 0){ // Player has no jetpack
					JetpackStatus[playerId] = 1;
					SetEntityMoveType(playerId, MOVETYPE_FLY);
					ShowActivity2(client, "\x01[SM] \x04", "\x01Gave Jetpack to \x04%N\x01.", playerId);
					LogAction(client, playerId, "\"%L\" gave Jetpack to \"%L\".", client, playerId);
				}
				else{ // Player has a jetpack 
					JetpackStatus[playerId] = 0;
					SetEntityMoveType(playerId, MOVETYPE_WALK);
					ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%N\x01's Jetpack.", playerId);
					LogAction(client, playerId, "\"%L\" removed \"%L\"'s Jetpack.", client, playerId);
				}
			}
			BuildPlayerMenu("jetpack");
			g_JetpackMenu.Display(client, MENU_TIME_FOREVER); 
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}

/* ----------------------------------- */

public Action Command_Regen(int client, int args)
{
	if(args < 2)
	{
		ReplyToCommand(client, "[SM] Usage: sm_regen [#userid|name] [0/1]");
		BuildPlayerMenu("regen");
		g_RegenMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 2)
	{
		char sArgs[64];
		char sValueRegen[11];
		int iValueRegen;
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		GetCmdArg(2, sValueRegen, sizeof(sValueRegen));
		iValueRegen = StringToInt(sValueRegen);
		if(iValueRegen != 0){ // If the value is anything but 0, we set 1
			iValueRegen = 1;
		}
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		bl_RegenInit = true;
		if(iValueRegen == 1){ // Add Regeneration
			for(int i = 0; i < iTargetCount; i++)
			{
				RegenStatus[iTargets[i]] = 1;
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Gave regeneration to \x04%s\x01.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" gave regeneration to \"%s\".", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" gave regeneration to \"%L\".", client, iTargets[0]);
		}
		else{ // Remove Regeneration
			for(int i = 0; i < iTargetCount; i++)
			{
				RegenStatus[iTargets[i]] = 0;
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%s\x01's regeneration.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" removed \"%s\"'s regeneration.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" removed \"%L\"'s regeneration.", client, iTargets[0]);
		}
		return Plugin_Handled;
	}
	else // args > 2
	{
		ReplyToCommand(client, "[SM] Usage: sm_regen [#userid|name] [0/1]");
		return Plugin_Handled;
	}
}

public RegenHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{ 
			bl_RegenInit = true;
			int serialId = StringToInt(info);
			int playerId = GetClientFromSerial(serialId); // 0 if invalid
			if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
				
				if(RegenStatus[playerId] == 0){ // Player has no regeneration
					RegenStatus[playerId] = 1;
					ShowActivity2(client, "\x01[SM] \x04", "\x01Gave regeneration to \x04%N\x01.", playerId);
					LogAction(client, playerId, "\"%L\" gave regeneration to \"%L\".", client, playerId);
				}
				else{ // Player has regeneration
					RegenStatus[playerId] = 0;
					ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%N\x01's regeneration.", playerId);
					LogAction(client, playerId, "\"%L\" removed \"%L\"'s regeneration.", client, playerId);
				}
			}
			BuildPlayerMenu("regen");
			g_RegenMenu.Display(client, MENU_TIME_FOREVER); 
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}

public Action Timer_Regeneration(Handle timer)
{
	if(bl_RegenInit){ // If the regen command was not used, the timer doesnt iterate
		bool bl_RegenUsed = false;
		for (int i = 1; i <= GetMaxClients(); i++)
		{
			if (IsClientInGame(i) && IsPlayerAlive(i))
			{
				if(RegenStatus[i] == 1){
					bl_RegenUsed = true;
					int clientHP = GetClientHealth(i);
					if(clientHP < 100){
						int newHP = clientHP + 10;
						if(newHP > 100)
							newHP = 100;
						SetEntityHealth(i, newHP);
					}
				}
			}
		}
		if(!bl_RegenUsed){ // If nobody had the regen mode, we stop the timer
			bl_RegenInit = false;
		}
	}
}



/* ----------------------------------- */

public Action Command_Cookies(int client, int args)
{
	if(args < 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_stealcookies [#userid|name]");
		return Plugin_Handled;
	}
	else if(args == 1)
	{
		char sArgs[64];
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, 0, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		
		ShowActivity2(client, "\x01[SM] \x04", "\x01Stole \x04%s\x01's cookies.", sTargetName);
		if(iTargetCount > 1)
			LogAction(client, -1, "\"%L\" stole \"%s\"'s cookies.", client, sTargetName);
		else
			LogAction(client, iTargets[0], "\"%L\" stole \"%L\"'s cookies.", client, iTargets[0]);
		
		for(int i = 0; i < iTargetCount; i++)
		{
			char sCookieMessage[64]; 
			getCookiesMessage(sCookieMessage, sizeof(sCookieMessage));
			PrintToChat(iTargets[0], sCookieMessage);
		}
		return Plugin_Handled;
	}
	else // args > 1
	{
		ReplyToCommand(client, "[SM] Usage: sm_stealcookies [#userid|name]");
		return Plugin_Handled;
	}
}

void getCookiesMessage(char[] getCookiesMessage, int length){
	int randNumber = GetRandomInt(0, 5);
	char tempMessage[64] = "";
	switch(randNumber){
		case (0):
		{
			tempMessage = "\x01[SM]\x04 \x01Oh no! You lost a cookie!";
		}
		case (1):
		{
			tempMessage = "\x01[SM]\x04 \x01Somebody stole your cookie!";
		}
		case (2):
		{
			tempMessage = "\x01[SM]\x04 \x01Somebody stole your whole tin of cookies!";
		}
		case (3):
		{
			tempMessage = "\x01[SM]\x04 \x01Get that cookie thief!";
		}
		case (4):
		{
			tempMessage = "\x01[SM]\x04 \x01Aww, you lost a cookie!";
		}
		case (5):
		{
			tempMessage = "\x01[SM]\x04 \x01Somebody stole all your cookies!";
		}
		default:
		{
			tempMessage = "\x01[SM]\x04 \x01Somebody gave you some cookies!";
		}
	}
	strcopy(getCookiesMessage, length, tempMessage);
}

public Action Command_Cookies2(int client, int args)
{
	if(args < 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_givecookies [#userid|name]");
		return Plugin_Handled;
	}
	else if(args == 1)
	{
		char sArgs[64];
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, 0, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		
		char sCookieMessage[64];
		Format(sCookieMessage,sizeof(sCookieMessage),"\x01[SM]\x04 %N\x01 gave you some cookies!",client);
		
		ShowActivity2(client, "\x01[SM] \x04", "\x01Gave cookies to \x04%s\x01.", sTargetName);
		if(iTargetCount > 1)
			LogAction(client, -1, "\"%L\" gave \"%s\" cookies.", client, sTargetName);
		else
			LogAction(client, iTargets[0], "\"%L\" gave \"%L\" cookies.", client, iTargets[0]);
		
		for(int i = 0; i < iTargetCount; i++)
		{
			PrintToChat(iTargets[i], sCookieMessage);
		}
		return Plugin_Handled;
	}
	else // args > 1
	{
		ReplyToCommand(client, "[SM] Usage: sm_givecookies [#userid|name]");
		return Plugin_Handled;
	}
}

/* ----------------------------------- */

public Action Command_Rocket(int client, int args)
{
	if(args < 2)
	{
		ReplyToCommand(client, "[SM] Usage: sm_rocket [#userid|name] [0/1]");
		BuildPlayerMenu("rocket");
		g_RocketMenu.Display(client, MENU_TIME_FOREVER);
		return Plugin_Handled;
	}
	else if(args == 2)
	{
		char sArgs[64];
		char sValueRocket[11];
		int iValueRocket;
		
		char sTargetName[MAX_TARGET_LENGTH];
		int iTargets[MAXPLAYERS];
		int iTargetCount;
		bool bIsML;

		GetCmdArg(1, sArgs, sizeof(sArgs));
		GetCmdArg(2, sValueRocket, sizeof(sValueRocket));
		iValueRocket = StringToInt(sValueRocket);
		if(iValueRocket != 0){ // If the value is anything but 0, we set 1
			iValueRocket = 1;
		}
		
		if((iTargetCount = ProcessTargetString(sArgs, client, iTargets, MAXPLAYERS, COMMAND_FILTER_ALIVE, sTargetName, sizeof(sTargetName), bIsML)) <= 0)
		{
			ReplyToTargetError(client, iTargetCount);
			return Plugin_Handled;
		}
		bl_RocketInit = true;
		if(iValueRocket == 1){ // Add Rocket
			for(int i = 0; i < iTargetCount; i++)
			{
				RocketStatus[iTargets[i]] = 1;
				createNewRocketPlayer(iTargets[i]);
				createNewRocketTrail(iTargets[i]);
				EmitSoundToAll("weapons/rpg/rocketfire1.wav", .channel=SNDCHAN_STATIC, .volume=1.0);
				CreateTimer(0.25, Timer_StartRocketSound);
//				CreateTimer(0.25, Timer_StartRocketSound, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Turned \x04%s\x01 into a rocket.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" turned \"%s\" into a rocket.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" turned \"%L\" into a rocket.", client, iTargets[0]);
		}
		else{ // Remove Rocket
			for(int i = 0; i < iTargetCount; i++)
			{
				RocketStatus[iTargets[i]] = 0;
				RocketStatus[iTargets[i]] = 0;
				SetEntityGravity(iTargets[i], 1.0);
				SetEntityMoveType(iTargets[i], MOVETYPE_WALK);
				StopAllRocketSound();
				AcceptEntityInput(rocketSprite[iTargets[i]], "Kill", -1, -1, 0);
			}
			ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%s\x01's rocket transformation.", sTargetName);
			if(iTargetCount > 1)
				LogAction(client, -1, "\"%L\" removed \"%s\"'s rocket transformation.", client, sTargetName);
			else
				LogAction(client, iTargets[0], "\"%L\" removed \"%L\"'s rocket transformation.", client, iTargets[0]);
		}
		return Plugin_Handled;
	}
	else // args > 2
	{
		ReplyToCommand(client, "[SM] Usage: sm_rocket [#userid|name] [0/1]");
		return Plugin_Handled;
	}
}

void createNewRocketPlayer(int playerId){
	if (bl_RocketMode_1) 
	{
		SetEntityGravity(playerId, -0.1);
		float originPlayer[3];
		GetClientAbsOrigin(playerId, originPlayer);
		originPlayer[2] = originPlayer[2] + 5;
		TeleportEntity(playerId, originPlayer, NULL_VECTOR, NULL_VECTOR);
	}
	else if (bl_RocketMode_2)
	{
		SetEntityMoveType(playerId, MOVETYPE_NONE);
	}
}

void createNewRocketTrail(int playerId){

	rocketSprite[playerId] = CreateEntityByName("env_spritetrail");
	char rocketName[32];
	Format(rocketName,sizeof(rocketName),"fsa_rocket_%d",playerId);
	
	float spriteorigin[3];
	GetClientAbsOrigin(playerId, spriteorigin);
	DispatchKeyValue(rocketSprite[playerId], "targetname", rocketName);
	DispatchKeyValue(rocketSprite[playerId], "model", "sprites/sprite_fire01.vmt");
	DispatchKeyValue(rocketSprite[playerId], "endwidth", "2.0");
	DispatchKeyValue(rocketSprite[playerId], "lifetime", "2.0");
	DispatchKeyValue(rocketSprite[playerId], "startwidth", "16.0");
	DispatchKeyValue(rocketSprite[playerId], "renderamt", "255");
	DispatchKeyValue(rocketSprite[playerId], "rendercolor", "255 255 255");
	DispatchKeyValue(rocketSprite[playerId], "rendermode", "5");
	DispatchKeyValue(rocketSprite[playerId], "parentname", rocketName);
	DispatchSpawn(rocketSprite[playerId]);
	TeleportEntity(rocketSprite[playerId], spriteorigin, NULL_VECTOR, NULL_VECTOR);
	SetVariantString(rocketName);
	AcceptEntityInput(rocketSprite[playerId], "SetParent");
}

public RocketHandle(Menu menu, MenuAction action, int client, int param2)
{
	char info[32]; // serial id of the player 
	menu.GetItem(param2, info, sizeof(info)); // Get the string of the picked option
	switch(action) { 
		case(MenuAction_Select): 
		{
			if(bl_RocketMode_1 || bl_RocketMode_2){
				bl_RocketInit = true;
				int serialId = StringToInt(info);
				int playerId = GetClientFromSerial(serialId); // 0 if invalid
				if ((IsClientInGame(playerId)) && (IsPlayerAlive(playerId)) && playerId != 0){
					
					if(RocketStatus[playerId] == 0){ // Player has no rocket
						RocketStatus[playerId] = 1;
						createNewRocketPlayer(playerId);
						createNewRocketTrail(playerId);
						EmitSoundToAll("weapons/rpg/rocketfire1.wav", .channel=SNDCHAN_STATIC, .volume=1.0);
						CreateTimer(0.25, Timer_StartRocketSound);
//						CreateTimer(0.25, Timer_StartRocketSound, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
						
						ShowActivity2(client, "\x01[SM] \x04", "\x01Turned \x04%N\x01 into a rocket.", playerId);
						LogAction(client, playerId, "\"%L\" turned \"%L\" into a rocket.", client, playerId);
					}
					else{ // Player has rocket
						RocketStatus[playerId] = 0;
						SetEntityMoveType(playerId, MOVETYPE_WALK);
						SetEntityGravity(playerId, 1.0);
						StopAllRocketSound();
						CreateTimer(2.0, Timer_StopRocketSound);
						AcceptEntityInput(rocketSprite[playerId], "Kill", -1, -1, 0);
						ShowActivity2(client, "\x01[SM] \x04", "\x01Removed \x04%N\x01's rocket transformation.", playerId);
						LogAction(client, playerId, "\"%L\" removed \"%L\"'s rocket transformation.", client, playerId);
					}
				}
				BuildPlayerMenu("rocket");
				g_RocketMenu.Display(client, MENU_TIME_FOREVER); 
			}
			
		}
		case(MenuAction_Cancel): 
		{ 
			if(param2 == MenuCancel_ExitBack) { 
				g_MainMenu.Display(client, MENU_TIME_FOREVER);
			}
		}
	}
}


void StopAllRocketSound(){
	for (int i = 1; i <= (GetMaxClients()); i++)
	{
		StopSound(i, SNDCHAN_STATIC, "weapons/rpg/rocket1.wav");
	}
}

public Action Timer_StartRocketSound(Handle timer)
{
	EmitSoundToAll("weapons/rpg/rocket1.wav", .channel=SNDCHAN_STATIC, .volume=1.0);
	if(!bl_RocketInit) // If there is no rocket guy
		return Plugin_Stop;
	return Plugin_Continue;
}

public Action Timer_StopRocketSound(Handle timer)
{
	StopAllRocketSound();
	if(bl_RocketInit) // If there is a rocket guy
		return Plugin_Stop;
	return Plugin_Continue;
}


public Action Timer_Rocket(Handle timer)
{
	if(bl_RocketMode_1){ // If the cvar mode is on 1
		if(bl_RocketInit){ // If the rocket command was not used, the timer doesnt iterate
			bool bl_RocketUsed = false;
			for (int i = 1; i <= GetMaxClients(); i++)
			{
				if (IsClientInGame(i) && IsPlayerAlive(i))
				{
					if(RocketStatus[i] == 1){ // If the player is a rocket 
						bl_RocketUsed = true;
						if(g_RocketPosition[i] == 1){ // We save the player origin 
							GetClientAbsOrigin(i, g_Rocket_Vec1[i]);
							g_Rocket_Z1[i] = g_Rocket_Vec1[i][2];
							g_RocketPosition[i] = 0;
						}
						else{ // with 0.1 sec interval, in 2 different array
							GetClientAbsOrigin(i, g_Rocket_Vec2[i]);
							g_Rocket_Z2[i] = g_Rocket_Vec2[i][2];
							g_RocketPosition[i] = 1;
						}
						if (g_Rocket_Z1[i] == g_Rocket_Z2[i]){ // To compare the current origin with the previous
							SetEntityGravity(i, 1.0);
							if (g_RocketKill.IntValue == 1){
								ForcePlayerSuicide(i);
							}
							StopAllRocketSound();
							CreateTimer(2.0, Timer_StopRocketSound);
							AcceptEntityInput(rocketSprite[i], "Kill", -1, -1, 0);
							EmitSoundToAll("weapons/explode3.wav", .channel=SNDCHAN_STATIC, .volume=1.0);
							RocketStatus[i] = 0;
						}
					}
				}
			}
			if(!bl_RocketUsed){ // If nobody had the rocket mode, we stop the timer
				bl_RocketInit = false;
			}
		}
	}
	else if(bl_RocketMode_2){ // If the cvar mode is on 2
		if(bl_RocketInit){ // If the rocket command was not used, the timer doesnt iterate
			bool bl_RocketUsed = false;
			for (int i = 1; i <= GetMaxClients(); i++)
			{
				if (IsClientInGame(i) && IsPlayerAlive(i))
				{
					if(RocketStatus[i] == 1){
						bl_RocketUsed = true;
						float RocketAbsOrigin[3];
						float RocketEndOrigin[3];
						GetClientEyePosition(i, RocketAbsOrigin);
						float AbsAngle[3];
						AbsAngle[0] = -90.0; AbsAngle[1] = 0.0; AbsAngle[2] = 0.0;
						TR_TraceRayFilter(RocketAbsOrigin, AbsAngle, MASK_SOLID, RayType_Infinite, TraceEntityFilter_FilterCaller);
						TR_GetEndPosition(RocketEndOrigin);
						float DistanceBetween = RocketEndOrigin[2] - RocketAbsOrigin[2];
						if (DistanceBetween <= (g_RocketSpeed.FloatValue + 0.1))
						{
							if (g_RocketKill.IntValue == 1)
							{
								ForcePlayerSuicide(i);
							}
							StopAllRocketSound();
							CreateTimer(2.0, Timer_StopRocketSound);
							AcceptEntityInput(rocketSprite[i], "Kill", -1, -1, 0);
							EmitSoundToAll("weapons/explode3.wav", .channel=SNDCHAN_STATIC, .volume=1.0);
							if (IsPlayerAlive(i))
							{
								RocketStatus[i] = 0;
								SetEntityMoveType(i, MOVETYPE_WALK);
								float ClientOrigin[3];
								GetClientAbsOrigin(i, ClientOrigin);
								ClientOrigin[2] = ClientOrigin[2] - (g_RocketSpeed.FloatValue + 0.1);
								TeleportEntity(i, ClientOrigin, NULL_VECTOR, NULL_VECTOR);
							}
						}
						else if (DistanceBetween >= (g_RocketSpeed.FloatValue + 0.1))
						{
							float ClientOrigin[3];
							GetClientAbsOrigin(i, ClientOrigin);
							ClientOrigin[2] = ClientOrigin[2] + g_RocketSpeed.FloatValue;
							TeleportEntity(i, ClientOrigin, NULL_VECTOR, NULL_VECTOR);
						}
					}
				}
			}
			if(!bl_RocketUsed){ // If nobody had the rocket mode, we stop the timer
				bl_RocketInit = false;
			}
		}
	}
}

bool TraceEntityFilter_FilterCaller(int entity, int contentsMask, int client)
{
	return entity != client;
}