/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <zombieplague>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Sonic Son'edit"

new g_maxplayers
new const BazookaPluginName[32] = "zp_extra_bazooka.amxx"
const TASK_LEAPGAUGE = 100;
const TASK_DASHGAUGE = 200;

new BOWclass[33]
new SurvivorClass[33]
new BOWclassNext[33]
new SurvivorClassNext[33]
new ModelEnt[33]
new WeaponModelEnt[33]
new BOWUsesDash[33]
new Float: BOWDashCharge[33]

new BOWclassMenu
new SurvivorClassMenu
new SurvivorBowMenu

new SurvivorHPmod[8]
new SurvivorSpeed[8]
new Float: SurvivorGravity[8]
new SurvivorWeapon[8][2][32]
new SurvivorHasRocketLauncer[8]
new SurvivorModel[][] = { "models//zombie_plague//Survivors//Jill.mdl", "models//zombie_plague//Survivors//Wesker.mdl", "models//zombie_plague//Survivors//Leon.mdl", "models//zombie_plague//Survivors//HUNK.mdl", "models//zombie_plague//Survivors//Barry.mdl",  "models//zombie_plague//Survivors//Chris.mdl","models//zombie_plague//Survivors//Carlos.mdl",  "models//zombie_plague//Survivors//Mikhail.mdl" }


new BOWHPmod[2]
new BOWSpeed[2]
new Float: BOWGravity[2]
new BOWHasLeapJump[2]
new Float: BOWLeapJumpAttrib[2][4]
new BOWHasDash[2]
new Float: BOWDashAttrib[2][6]
new BOWHasRocketLauncer[2]
new BOWModel[][] = { "models//zombie_plague//B.O.W.//Nemesis.mdl", "models//zombie_plague//B.O.W.//Tyrant.mdl" }


public plugin_precache()
{
	new strtemp1[100]
	
	for (new i=0;i<8;i++) 
	{
		precache_model(SurvivorModel[i])
		copy(strtemp1,len(SurvivorModel[i])-4,SurvivorModel[i]);
		add(strtemp1,100,"T.mdl",100)
		if (file_exists(strtemp1)) precache_model(strtemp1)
	}
	
	for (new i=0;i<2;i++)
	{
		precache_model(BOWModel[i])
		copy(strtemp1,len(BOWModel[i])-4,BOWModel[i]);
		add(strtemp1,100,"T.mdl",100)
		if (file_exists(strtemp1)) precache_model(strtemp1)
	}
}

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "event_cur_weapon", "b", "1=1")
	
	register_forward(FM_PlayerPreThink, "fw_PlayerPreThink")
	
	register_clcmd("zp_test","clcmd_SurvivorBowMenu");
	
	g_maxplayers = get_maxplayers()
	
	for (new id = 1; id <= g_maxplayers; id++)
	{
		BOWclass[id] = random(2) ;
		SurvivorClass[id] = random(8);
		BOWclassNext[id] = -1;
		SurvivorClassNext[id] = -1;
	}
	
	SurvivorHPmod[0] = 250;
	SurvivorHPmod[1] = 700;
	SurvivorHPmod[2] = 400;
	SurvivorHPmod[3] = 550;
	SurvivorHPmod[4] = 550;
	SurvivorHPmod[5] = 450;
	SurvivorHPmod[6] = 400;
	SurvivorHPmod[7] = 400;
	
	SurvivorSpeed[0] = 280;
	SurvivorSpeed[1] = 270;
	SurvivorSpeed[2] = 260;
	SurvivorSpeed[3] = 260;
	SurvivorSpeed[4] = 250;
	SurvivorSpeed[5] = 260;
	SurvivorSpeed[6] = 250;
	SurvivorSpeed[7] = 230;
	
	SurvivorGravity[0] = 0.8;
	SurvivorGravity[1] = 0.7;
	SurvivorGravity[2] = 0.9;
	SurvivorGravity[3] = 0.9;
	SurvivorGravity[4] = 1.0;
	SurvivorGravity[5] = 0.9;
	SurvivorGravity[6] = 1.0;
	SurvivorGravity[7] = 1.0;
	
	SurvivorWeapon[0][0] = "weapon_mp5navy"
	SurvivorWeapon[0][1] = "weapon_usp"
	SurvivorWeapon[1][0] = "weapon_scout"
	SurvivorWeapon[1][1] = "weapon_glock18"
	SurvivorWeapon[2][0] = "weapon_xm1014"
	SurvivorWeapon[2][1] = "weapon_p228"
	SurvivorWeapon[3][0] = "weapon_tmp"
	SurvivorWeapon[3][1] = "weapon_p228"
	SurvivorWeapon[4][0] = "weapon_m3"
	SurvivorWeapon[4][1] = "weapon_deagle"
	SurvivorWeapon[5][0] = "weapon_mac10"
	SurvivorWeapon[5][1] = "weapon_usp"
	SurvivorWeapon[6][0] = "weapon_m4a1"
	SurvivorWeapon[6][1] = "weapon_fiveseven"
	SurvivorWeapon[7][0] = "weapon_ak47"
	SurvivorWeapon[7][1] = "weapon_deagle"
	
	SurvivorHasRocketLauncer[0] = false;
	SurvivorHasRocketLauncer[1] = false;
	SurvivorHasRocketLauncer[2] = false;
	SurvivorHasRocketLauncer[3] = false;
	SurvivorHasRocketLauncer[4] = false;
	SurvivorHasRocketLauncer[5] = false;
	SurvivorHasRocketLauncer[6] = false;
	SurvivorHasRocketLauncer[7] = true;
	
	BOWHPmod[0] = 1500;
	BOWHPmod[1] = 2200;
	
	BOWSpeed[0] = 260;
	BOWSpeed[1] = 270;
	
	BOWGravity[0] = 0.5;
	BOWGravity[1] = 0.7;
	
	BOWHasLeapJump[0] = false;
	BOWHasLeapJump[1] = true;
	BOWLeapJumpAttrib[1][0] = 700.0;
	BOWLeapJumpAttrib[1][1] = 400.0;
	BOWLeapJumpAttrib[1][2] = 15.0;
	
	BOWHasDash[0] = false;
	BOWHasDash[1] = true;
	BOWDashAttrib[1][0] = 300.0;
	BOWDashAttrib[1][1] = 7.0;
	BOWDashAttrib[1][2] = 1.0;
	BOWDashAttrib[1][3] = 0.2;
	BOWDashAttrib[1][4] = 0.1;

	
	BOWHasRocketLauncer[0] = true;
	BOWHasRocketLauncer[1] = false;
	
	build_menu;
}

build_menu()
{
	SurvivorBowMenu = menu_create("Survivor & B.O.W. menu","SurvivorBowMenuHandle")
	menu_additem(SurvivorBowMenu, "Choose Survivor Class", "display_Survivor_menu");
	menu_additem(SurvivorBowMenu, "Choose B.O.W. Class", "display_BOW_menu");	
	
	BOWclassMenu = menu_create("B.O.W. class menu","BOWclassMenuHandle")
	menu_additem(BOWclassMenu, "Nemesis^n\yHPmod: 1500, Speed: 260, Graviry: 50%^nweapon: Rocket Launcher (damage:500 30 sec reload), hands (damage:250)^n", "0");
	menu_additem(BOWclassMenu, "Tyrant T-002^n\yHPmod: 2200, Speed: 270, Graviry: 70%^nweapon: hands (damage:250/750), Leap Jump (15 sec delay), Dash (15 sec delay)^n", "1");
	menu_setprop(BOWclassMenu, MPROP_PERPAGE, 4); 
	
	SurvivorClassMenu = menu_create("Survivor class menu","SurvivorClassMenuHandle")	
	menu_additem(SurvivorClassMenu, "Jill Valentine^n\yHPmod: 250, Speed: 280, Graviry: 80%^nweapon: K&M Sub-Machine Gun, K&M .45 Tactical^n", "0");
	menu_additem(SurvivorClassMenu, "Albert Wesker^n\yHPmod: 700, Speed: 270, Graviry: 70%^nweapon: Schmidt Scout, 9X19mm Sidearm^n", "1");
	menu_additem(SurvivorClassMenu, "Leon S. Kennedy^n\yHPmod: 400, Speed: 260, Graviry: 90%^nweapon: Leone YG1265 Auto Shotgun, 228 Compact^n", "2");
	menu_additem(SurvivorClassMenu, "HUNK^n\yHPmod: 550, Speed: 260, Graviry: 90%^nweapon: Schmidt Machine Pistol, 228 Compact^n", "3");
	menu_additem(SurvivorClassMenu, "Barry Burton^n\yHPmod: 550, Speed: 250, Graviry: 100%^nweapon: Leone 12 Gauge Super, Night Hawk .50C^n", "4");
	menu_additem(SurvivorClassMenu, "Chris Redfield^n\yHPmod: 450, Speed: 260, Graviry: 90%^nweapon: Ingram MAC-10, K&M .45 Tactical^n", "5");
	menu_additem(SurvivorClassMenu, "Carlos Oliveira^n\yHPmod: 400, Speed: 250, Graviry: 100%^nweapon: Maverick M4A1 Carbine, ES Five-Seven^n", "6");
	menu_additem(SurvivorClassMenu, "Mikhail Victor^n\yHPmod: 400, Speed: 230, Graviry: 100%^nweapon: AK-47, Night Hawk .50C, Rocket Launcher^n", "7");
	menu_setprop(SurvivorClassMenu, MPROP_PERPAGE, 4); 
}

public SurvivorBowMenuHandle(id, menu, item)
{
	new action[32], access, callback;
	menu_item_getinfo(menu, item, access, action,32,_,_, callback);
	set_task(0.1,action,id);
}

public clcmd_SurvivorBowMenu(id)
{
	menu_display(id,SurvivorBowMenu);
}

public display_BOW_menu(id)
{
	menu_display(id,BOWclassMenu,0)
}

public display_Survivor_menu(id)
{
	menu_display(id,SurvivorClassMenu,0)
}

public zp_round_started(gamemode, id)
{
	for (id = 1; id <= g_maxplayers; id++)
	{			
		
		if (zp_get_user_nemesis(id)) 
		{
			if (BOWclassNext[id] < 0)
				set_task(0.1,"display_BOW_menu",id)
			else
				BOWclass[id]  = BOWclassNext[id] ;
			
			new BOWHP = BOWHPmod[BOWclass[id]];
			for (new i = 1; i < g_maxplayers; i++)
				if ((zp_get_user_zombie(i))||(zp_get_user_nemesis(i)))
					BOWHP += BOWHPmod[BOWclass[id]];		
					
			entity_set_float(id,EV_FL_health,float(BOWHP));
			entity_set_float(id,EV_FL_gravity,BOWGravity[BOWclass[id]]);	
			
			ModelEnt[id] = create_entity("info_target");
			entity_set_string(ModelEnt[id], EV_SZ_classname, "Player_Model")
			entity_set_int(ModelEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
			entity_set_edict(ModelEnt[id], EV_ENT_aiment, id)
			entity_set_edict(ModelEnt[id], EV_ENT_owner, id)		
			set_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 0)
			entity_set_model(ModelEnt[id],BOWModel[BOWclass[id]])
			
			WeaponModelEnt[id] = create_entity("info_target");
			entity_set_string(WeaponModelEnt[id], EV_SZ_classname, "Weapon_Model")
			entity_set_int(WeaponModelEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
			entity_set_edict(WeaponModelEnt[id], EV_ENT_aiment, id)
			entity_set_edict(WeaponModelEnt[id], EV_ENT_owner, id)		
			
			if (BOWHasRocketLauncer[BOWclass[id]])	
			{
				for (new i=0; i<99; i++)
				{
					if (callfunc_begin("zp_extra_item_selected",BazookaPluginName) < 1) return PLUGIN_HANDLED; //function name is same everywhere, so todo = extra item plugin name.
					callfunc_push_int(id);
					callfunc_push_int(i);
					callfunc_end;		
				}
				entity_set_model(WeaponModelEnt[id],"models/p_rpg.mdl")
			}
			
			if ((BOWHasLeapJump[BOWclass[id]])&&(BOWLeapJumpAttrib[BOWclass[id]][2]>0.0)) set_task(0.5,"BowLeapGauge",id+TASK_LEAPGAUGE,_,_,"b")
			
			if (BOWHasDash[BOWclass[id]]) set_task(0.5,"BowDashGauge",id+TASK_DASHGAUGE,_,_,"b")
		}
		
		if (zp_get_user_survivor(id))
		{
			if (SurvivorClassNext[id] < 0) 
				set_task(0.1,"display_Survivor_menu",id)
			else
				SurvivorClass[id] = SurvivorClassNext[id] ;

			new SurvivorHP = SurvivorHPmod[SurvivorClass[id]];
			for (new i = 1; i < g_maxplayers; i++)
				if ((zp_get_user_zombie(i))||(zp_get_user_nemesis(i)))
					SurvivorHP += SurvivorHPmod[SurvivorClass[id]];				
					
			entity_set_float(id,EV_FL_health,float(SurvivorHP));
			entity_set_float(id,EV_FL_gravity,SurvivorGravity[SurvivorClass[id]]);
			
			new tempent;
			tempent = create_entity("player_weaponstrip")
			DispatchSpawn(tempent)
			force_use(id, tempent)
			remove_entity(tempent)
			
			tempent = create_entity(SurvivorWeapon[SurvivorClass[id]][0])
			entity_set_int(tempent, EV_INT_spawnflags, entity_get_int(tempent, EV_INT_spawnflags) | SF_NORESPAWN)
			DispatchSpawn(tempent)
			fake_touch(tempent, id)
						
			tempent = create_entity(SurvivorWeapon[SurvivorClass[id]][1])
			entity_set_int(tempent, EV_INT_spawnflags, entity_get_int(tempent, EV_INT_spawnflags) | SF_NORESPAWN)
			DispatchSpawn(tempent)
			fake_touch(tempent, id)
			
			if (SurvivorHasRocketLauncer[SurvivorClass[id]])
			{
				tempent = create_entity("weapon_knife")
				entity_set_int(tempent, EV_INT_spawnflags, entity_get_int(tempent, EV_INT_spawnflags) | SF_NORESPAWN)
				DispatchSpawn(tempent)
				fake_touch(tempent, id)
				
				for (new i=0; i<99; i++)
				{
					if (callfunc_begin("zp_extra_item_selected",BazookaPluginName) < 1) return PLUGIN_HANDLED; //function name is same everywhere, so todo = extra item plugin name.
					callfunc_push_int(id);
					callfunc_push_int(i);
					callfunc_end;		
				}	
			}		
			
			ModelEnt[id] = create_entity("info_target");
			entity_set_string(ModelEnt[id], EV_SZ_classname, "Player_Model")
			entity_set_int(ModelEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
			entity_set_edict(ModelEnt[id], EV_ENT_aiment, id)
			entity_set_edict(ModelEnt[id], EV_ENT_owner, id)		
			set_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 0)
			entity_set_model(ModelEnt[id],SurvivorModel[SurvivorClass[id]])
			
			WeaponModelEnt[id] = create_entity("info_target");
			entity_set_string(WeaponModelEnt[id], EV_SZ_classname, "Weapon_Model")
			entity_set_int(WeaponModelEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
			entity_set_edict(WeaponModelEnt[id], EV_ENT_aiment, id)
			entity_set_edict(WeaponModelEnt[id], EV_ENT_owner, id)		
			update_weaponmodel(id)
		}
	}
	return PLUGIN_HANDLED;
}

public update_weaponmodel(id)
{
	new strtemp1[100]
	entity_get_string(id, EV_SZ_weaponmodel, strtemp1, sizeof strtemp1 - 1)
	entity_set_model(WeaponModelEnt[id],strtemp1)
}

public event_cur_weapon(id)
{
	if ((!is_user_alive(id))|| (!zp_get_user_survivor(id)))	return;
	
	new strtemp1[100], strtemp2[100]
	entity_get_string(id, EV_SZ_weaponmodel, strtemp1, sizeof strtemp1 - 1)
	entity_get_string(WeaponModelEnt[id], EV_SZ_model, strtemp2, sizeof strtemp2 - 1)
	
	if (!equal(strtemp1,strtemp2)) update_weaponmodel(id)

}

public zp_round_ended(winteam)
{
	for (new id = 1; id <= g_maxplayers; id++)
	{
		if ((zp_get_user_survivor(id))||(zp_get_user_nemesis(id))) set_task(5.0,"remove_tempent",id)
	}
}

public remove_tempent(id)
{
	remove_entity(ModelEnt[id]);
	remove_entity(WeaponModelEnt[id]);
	set_rendering(id)
	
	if (zp_get_user_nemesis(id))
	{
		if ((BOWHasLeapJump[BOWclass[id]])&&(BOWLeapJumpAttrib[BOWclass[id]][2]>0.0)) remove_task(id+TASK_LEAPGAUGE)
		if (BOWHasDash[BOWclass[id]]) remove_task(id+TASK_DASHGAUGE)
	}
}

public BOWclassMenuHandle(id, menu, item)
{
	new cmd[32];
	new access, callback;
	menu_item_getinfo(menu, item, access, cmd,2,_,_, callback);
	BOWclassNext[id] = str_to_num(cmd); 
}

public SurvivorClassMenuHandle(id, menu, item)
{
	new cmd[32];
	new access, callback;
	menu_item_getinfo(menu, item, access, cmd,2,_,_, callback);
	SurvivorClassNext[id] = str_to_num(cmd)
}

public fw_PlayerPreThink(id)
{
	if (!is_user_alive(id)) return;
	
		
	if (zp_get_user_survivor(id)) entity_set_float(id,EV_FL_maxspeed,float(SurvivorSpeed[SurvivorClass[id]]));

	if (zp_get_user_nemesis(id))
	{
		if (!BOWUsesDash[id]) entity_set_float(id,EV_FL_maxspeed,float(BOWSpeed[BOWclass[id]]));
		new buttons = pev(id, pev_button)
			
		if ((BOWHasLeapJump[BOWclass[id]])&&(get_gametime()-BOWLeapJumpAttrib[BOWclass[id]][3] > BOWLeapJumpAttrib[BOWclass[id]][2])&&(buttons & IN_JUMP)&&(buttons & IN_DUCK)&&!(pev(id, pev_flags) & FL_ONGROUND))
		{
			new Float: velocity[3]
			velocity_by_aim(id, floatround(BOWLeapJumpAttrib[id][0]), velocity)
			velocity[2] = BOWLeapJumpAttrib[id][1];
			set_pev(id,pev_velocity, velocity)
			BOWLeapJumpAttrib[id][3] = get_gametime()
		}
		
		if ((BOWHasDash[id])&&(BOWDashCharge[id]>0.1)&&(buttons & IN_ATTACK2))
		{
			if (!BOWUsesDash[id]) BOWDashCharge[id]-=BOWDashAttrib[BOWclass[id]][2];
			entity_set_float(id,EV_FL_maxspeed, BOWDashAttrib[BOWclass[id]][0]);
			entity_set_float(id,EV_FL_speed, BOWDashAttrib[BOWclass[id]][0]);
			BOWUsesDash[id]=true;
		}
		else
			BOWUsesDash[id]=false;
	}
}

public BowLeapGauge(id)
{
	id-=TASK_LEAPGAUGE;
	new strtemp1[11] = "----------";
	new temp1 = floatround(((get_gametime()-BOWLeapJumpAttrib[BOWclass[id]][3])/BOWLeapJumpAttrib[BOWclass[id]][2])*10.0);
	if (temp1 > 10) temp1 = 10;
	for (new i = 0; i<temp1;i++) strtemp1[i] = '=';
	set_hudmessage(100, 100, 100, 0.56, 0.965, 0, 6.0, 0.5,0.0,0.0,-1)
	show_hudmessage(id, "LeapJump: [%s]", strtemp1)	
}

public BowDashGauge(id)
{
	id-=TASK_DASHGAUGE;
	
	if (BOWUsesDash[id]) 
		BOWDashCharge[id]-=BOWDashAttrib[BOWclass[id]][3];
	else
		if (BOWDashCharge[id]<BOWDashAttrib[BOWclass[id]][1])
			BOWDashCharge[id]+=BOWDashAttrib[BOWclass[id]][4];
	
	if (BOWDashCharge[id] == 0.0) BOWDashCharge[id] = 0.01;
		
	new strtemp1[11] = "----------";
	new temp1 = floatround((BOWDashCharge[id]/BOWDashAttrib[BOWclass[id]][1])*10.0);
	if (temp1 > 10) temp1 = 10;
	for (new i = 0; i<temp1;i++) strtemp1[i] = '=';
	set_hudmessage(100, 100, 100, 0.73, 0.965, 0, 6.0, 0.5,0.0,0.0,-1)
	show_hudmessage(id, "Dash: [%s]", strtemp1)	
}

public len(const string[])
{
	new i
	
	for (i = 0; i<255;i++)
		if (string[i] == 0) 
			return i;
	
	return i;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/
