#library "Tomtefar"
#include "zcommon.acs"
bool PistolStuffSpawned;


// --------------------------------------------------------------------------
//
//	Start stuff
//
// --------------------------------------------------------------------------

script 999 ENTER //Once per player
{
	ACS_Execute(1046,0,0,0,0); //Idle checker
	delay(15);
	if(CheckInventory("bd_sbartype1") < 1)
	{ if(CheckInventory("bd_sbartype2") < 1)
	{ if(CheckInventory("bd_sbartype3") < 1)
	{ if(CheckInventory("bd_sbartype4") < 1)
	{ if(CheckInventory("bd_sbartype5") < 1)
	{ if(CheckInventory("bd_sbartype6") < 1)
	{ if(CheckInventory("bd_sbartype7") < 1)
	{
	ACS_Execute(649,0,0,0,0);
	}}}}}}}
}

script 1000 OPEN //Once per map
{
	PistolStuffSpawned = OFF;
}


// --------------------------------------------------------------------------
//
//	New weapons
//
// --------------------------------------------------------------------------

Script 1001 (int X)
{
	if(X == 1){
	SetResultValue(GetCVar("TE_Weap_Pistol"));
	}else if(X == 2){
	SetResultValue(GetCVar("TE_Weap_Revolver"));
	}else if(X == 3){
	SetResultValue(GetCVar("TE_Weap_AutoShotgun"));
	}else if(X == 4){
	SetResultValue(GetCVar("TE_Weap_Sniper"));
	}else if(X == 5){
	SetResultValue(GetCVar("TE_Weap_Railgun"));
	}else if(X == 6){
	SetResultValue(GetCVar("TE_Weap_C4"));
	}else{
	SetResultValue(0);
	}
}


// --------------------------------------------------------------------------
//
//	BDv21 weapons
//
// --------------------------------------------------------------------------

Script 1010 (int X)
{
	if(X == 0){
	SetResultValue(GetCVar("TE_Weap_SMG"));
	}else if(X == 1){
	SetResultValue(GetCVar("TE_Weap_AA12"));
	}else if(X == 2){
	SetResultValue(GetCVar("TE_Weap_Machinegun"));
	}else if(X == 3){
	SetResultValue(GetCVar("TE_Weap_GrenadeLauncher"));
	}else if(X == 4){
	SetResultValue(GetCVar("TE_Weap_Unmaker"));
	}else if(X == 5){
	SetResultValue(GetCVar("TE_Weap_BFG10k"));
	}else if(X == 6){
	SetResultValue(GetCVar("TE_Weap_Rifle"));
	}else if(X == 7){
	SetResultValue(GetCVar("TE_Weap_Flamer"));
	}else if(X == 8){
	SetResultValue(GetCVar("TE_Weap_HellLauncher"));
	}else if(X == 9){
	SetResultValue(GetCVar("TE_Weap_MP40"));
	}else if(X == 10){
	SetResultValue(GetCVar("TE_Weap_Buzzsaw"));
	}else if(X == 11){
	SetResultValue(GetCVar("TE_Weap_Grenades"));
	}else{
	SetResultValue(0);
	}
}


// --------------------------------------------------------------------------
//
//	Graphics
//
// --------------------------------------------------------------------------

Script 1020 (void)//Check Flashlight graphics
{
	SetResultValue(GetCVar("TE_Flashlight"));
}

Script 1021 (void)//SSG animation
{
	SetResultValue(GetCVar("TE_SSG"));
}

Script 1022 (void)//Check shotgun strap physics
{
	if	(GetCvar("TE_Shotgunstrap") == 1)
	{
		GiveInventory("useshotgunstrap", 1);
	}
}

Script 1025 (int X)//Check weapon sprites
{
	if(X == 0){
	SetResultValue(GetCVar("TE_Sprites_Shotgun"));
	}else if(X == 1){
	SetResultValue(GetCVar("TE_Sprites_Buzzsaw"));
	}else if(X == 2){
	SetResultValue(GetCVar("TE_Sprites_SSG"));
	}else{
	SetResultValue(0);
	}
}

Script 1029 (void)//Enviromental powerup graphics
{
	SetResultValue(GetCVar("TE_Enviro"));
}

// --------------------------------------------------------------------------
//
//	Misc. Options
//
// --------------------------------------------------------------------------

Script 1023 (void)//Check starting weapon
{
	SetResultValue(GetCVar("TE_StartWeapon"));
}

Script 1024 (void)//BFG behaviour
{
	SetResultValue(GetCVar("TE_BFGbehaviour"));
}

Script 1026 (void)//Rocket Launcher alt fire type
{
	SetResultValue(GetCVar("TE_RocketLauncherAltFire"));
}


// --------------------------------------------------------------------------
//
//	Keybinds
//
// --------------------------------------------------------------------------

Script 1031 (void) NET//ThrowC4
{
	if(CheckInventory("C4Weapon"))
	{
		if(CheckInventory("C4Ammo"))
		{
			GiveInventory("GoThrowC4", 1);
			SetWeapon("C4Weapon");
		} else {
			Print(s:"No C-4 Left.");
		}
	} else {
		Print(s:"You don't have a C-4 detonator.");
	}
}

Script 1032 (void) NET//WeapSpecial
{
	GiveInventory("WeapSpecial", 1);
}

Script 309 (void) NET//Ammo dropper
{
	SetWeapon("U_AmmoDropper");
}


// --------------------------------------------------------------------------
//
//	Gameplay stuff
//
// --------------------------------------------------------------------------

Script 1042 (void)//Pistol stuff spawned?
{
	if (PistolStuffSpawned == ON)
	{
		SetResultValue(1);
	} else {
		PistolStuffSpawned = ON;
		SetResultValue(0);
	}
}

Script 1043 (void)//Ammo drop counters.
{
	while (CheckWeapon("U_AmmoDropper"))
	{
		int ammo1 = CheckInventory("9mmMagazine");
		HudMessage(d:ammo1; HUDMSG_PLAIN, 0, CR_WHITE, 0.160, 0.605, 0.2, 2.0);
		int ammo2 = CheckInventory("Clip2");
		HudMessage(d:ammo2; HUDMSG_PLAIN, 0, CR_WHITE, 0.235, 0.605, 0.2, 2.0);
		int ammo3 = CheckInventory("AmmoShell");
		HudMessage(d:ammo3; HUDMSG_PLAIN, 0, CR_WHITE, 0.310, 0.605, 0.2, 2.0);
		int ammo4 = CheckInventory("GreenShell");
		HudMessage(d:ammo4; HUDMSG_PLAIN, 0, CR_WHITE, 0.385, 0.605, 0.2, 2.0);
		int ammo5 = CheckInventory("RevolverBullets");
		HudMessage(d:ammo5; HUDMSG_PLAIN, 0, CR_WHITE, 0.460, 0.605, 0.2, 2.0);
		int ammo6 = CheckInventory("AmmoRocket");
		HudMessage(d:ammo6; HUDMSG_PLAIN, 0, CR_WHITE, 0.535, 0.605, 0.2, 2.0);
		int ammo7 = CheckInventory("AmmoCell");
		HudMessage(d:ammo7; HUDMSG_PLAIN, 0, CR_WHITE, 0.610, 0.605, 0.2, 2.0);
		int ammo8 = CheckInventory("RailCore");
		HudMessage(d:ammo8; HUDMSG_PLAIN, 0, CR_WHITE, 0.685, 0.605, 0.2, 2.0);
		int ammo9 = CheckInventory("Gasoline");
		HudMessage(d:ammo9; HUDMSG_PLAIN, 0, CR_WHITE, 0.760, 0.605, 0.2, 2.0);
		int ammo10 = CheckInventory("GrenadeAmmo");
		HudMessage(d:ammo10; HUDMSG_PLAIN, 0, CR_WHITE, 0.835, 0.605, 0.2, 2.0);
		delay(6);
	}
}

script 1044 (void)
{
	int X = GetCVar("TE_MGX");
	int Y = GetCVar("TE_MGY");
	while (CheckWeapon("U_Machinegun"))
	{
		if(CheckInventory("FiredGrenade"))
		{
			SetFont("NoRocket");
			HudMessage(s:"A"; HUDMSG_PLAIN, 0, 0, (X*0.01), (Y*0.01), 0.2);
		} else {
			SetFont("Rocket");
			HudMessage(s:"A"; HUDMSG_PLAIN, 0, 0, (X*0.01), (Y*0.01), 0.2);
		}
		delay(6);
	}
}

script 1045 (void)//Check if on a liquid surface.
// 1 = water
// 2 = nukage
// 3 = blood
// 4 = lava
// 5 = slime
// 0 = default
{
	if (CheckActorFloorTexture(0, "FWATER1")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "FWATER2")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "FWATER3")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "FWATER4")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "NUKAGE1")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "NUKAGE2")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "NUKAGE3")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "NUKAGE4")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "BLOOD1")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "BLOOD2")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "BLOOD3")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "BLOOD4")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "LAVA1")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "LAVA2")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "LAVA3")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "LAVA4")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "SLIME01")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME02")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME03")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME04")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME05")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME06")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME07")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME08")){SetResultValue(5);}
	else {SetResultValue(0);}
}

Script 1046 (VOID)//Idle checker.
{
	int x, y, z, speed;
	while (TRUE)
	{
		x = GetActorVelX(0);
		y = GetActorVelY(0);
		z = GetActorVelZ(0);
		speed = x + y + z;
		
		if (speed != 0)
		{
			TakeInventory("IdleCounter", 200);
		} else {
			GiveInventory("IdleCounter", 1);
		}
		GiveInventory("U_SoulAmmo", 1);
		delay(50);
	}
}

Script 1047 (void)//Check current gametype and if calling player is a bot.
// 0 = Single player
// 1 = Death Match, player is not a bot
// 2 = Death Match, player is a bot
{
	if (GameType () == GAME_NET_DEATHMATCH)
	{
		if (PlayerIsBot(PlayerNumber()))
		{
			SetResultValue(2);
		} else {
			SetResultValue(1);
		}
	} else {
		SetResultValue(0);
	}
}

Script 1048 (void)//Blow C-4 charges.
{
	SetActorState(1999,"explode");
}