#library "COMMONAC"
#include "zcommon.acs"

//Please excuse a lot of the dogshit code in here, tried my best to clean up stuff 
//I wrote in 2016 but a mortal man can only do so much lmfao

//global variables

int difficulty = 1;
int dtimer;
int hellonearthspeed;
int hellonearthdelay;
int supplytimerequired, supplytimer, supplylocation;

bool supplytimerset;

int anomalytimerequired, anomalytimer, anomalylocation;

bool anomalytimerset;
str sourceport;
int numplayers;

int p1healthregen, p2healthregen, p3healthregen, p4healthregen;
int p1armorregen, p2armorregen, p3armorregen, p4armorregen;
int p1health, p2health, p3health, p4health;
int p1maxhealth, p2maxhealth, p3maxhealth, p4maxhealth;
int p1revive, p2revive, p3revive, p4revive;
int p1revivesprice = 30, p2revivesprice = 30, p3revivesprice = 30, p4revivesprice = 30;
int p1respawn = 30, p2respawn = 30, p3respawn = 30, p4respawn = 30;
int p1dead = false, p2dead = false, p3dead = false, p4dead = false;
int score;

int armorregenerationperk;

int supplylocationlist[7] = {25,26,27,28,29,30,31};
int anomalylocationlist[4] = {40,41,42,43};

int weaponsbought, buystage;

/*int fabricatorlist[40] = {11,139,140,141,75,142,12,143,144,22,68,69,133,25,132,135,136,138,137,134,152,23,24
,32,27,33,28,29,30,31,600,651,652,653,654,655,656,657,659,777};

int fabricateditem;
*/ //Now actor classes are being used instead of arrays 'n' shit.

function int isZandronum(void)
{
	return GetCVar("CL_TicsPerUpdate");// 3=default for zandronum, 0=gzdoom (not defined)
}

function void getSourceport (void)
{
	if(isZandronum() == 3)
	{
		SourcePort = "Zandronum";
	}
	else
	{
		SourcePort = "ZDoom";
	}
}

function void setPlayerNumber (void) //kinda ugly but it works
{
	if(PlayerNumber() == 0)
    {
		Thing_ChangeTid(0,888);
	}
	else if(PlayerNumber() == 1)
    {
		Thing_ChangeTid(0,889);
	}
	else if(PlayerNumber() == 2)
    {
		Thing_ChangeTid(0,890);
	}
	else if(PlayerNumber() == 3)
    {
		Thing_ChangeTid(0,891);
	}
}

function void ClearWeaponHeld (void)
{
	TakeInventory("HoldingFist",1);
	TakeInventory("HoldingPistol",1);
	TakeInventory("HoldingShotgun",1);
	TakeInventory("HoldingSuperShotgun",1);
	TakeInventory("HoldingChaingun",1);
	TakeInventory("HoldingRocketLauncher",1);
	TakeInventory("HoldingPlasmaRifle",1);
	TakeInventory("HoldingBFG",1);
	TakeInventory("HoldingChainsaw",1);
	TakeInventory("HoldingAutoRifle",1);
	TakeInventory("HoldingAutoShotgun",1);
	TakeInventory("HoldingGrenadeLauncher",1);
}

function void HealthVariables (void)
{
	getSourceport();
	if(sourceport == "ZDoom")
	{
		p1health = GetActorProperty(888, APROP_Health); //this prevents 1 extra health from being added when purchased.
		p1maxhealth = GetActorProperty(888, APROP_SpawnHealth);
		p2health = GetActorProperty(889, APROP_Health);
		p2maxhealth = GetActorProperty(889, APROP_SpawnHealth);
		p3health = GetActorProperty(890, APROP_Health); 
		p3maxhealth = GetActorProperty(890, APROP_SpawnHealth);
		p4health = GetActorProperty(891, APROP_Health); 
		p4maxhealth = GetActorProperty(891, APROP_SpawnHealth);
	}
	else if(sourceport == "Zandronum")
	{
		SetActivator(888);
		p1health = PlayerHealth(); 
		p1maxhealth = 100;
		SetActivator(889);
		p2health = PlayerHealth();
		p2maxhealth = 100;
		SetActivator(890);
		p3health = PlayerHealth(); 
		p3maxhealth = 100;
		SetActivator(891);
		p4health = PlayerHealth();
		p4maxhealth = 100;
	}
}

function void BuyStageItems(void)
{ //bunch of ifs instead of a switch statement so each previous item is also added
	If(buystage >= 2) GiveInventory("Chaingun",1);
	If(buystage >= 4) GiveInventory("Shotgun",1);
	If(buystage >= 6) GiveInventory("Credits",5);
	If(buystage >= 8) GiveInventory("SuperShotgun",1);
	If(buystage >= 10) GiveInventory("GreenArmor",1);
	If(buystage >= 12) GiveInventory("RocketLauncher",1);
	If(buystage >= 14) GiveInventory("Credits",5);
	If(buystage >= 16) GiveInventory("PlasmaRifle",1);
	If(buystage >= 18) GiveInventory("Backpack",1);
	If(buystage >= 20) GiveInventory("BFG9000",1);
	If(buystage >= 22) GiveInventory("Credits",5);
	If(buystage >= 24) GiveInventory("Backpack",1);
	If(buystage >= 26) GiveInventory("Credits",5);
	If(buystage >= 28) GiveInventory("Backpack",1);
	If(buystage >= 30) GiveInventory("BlueArmor",1);
	If(buystage >= 32) GiveInventory("Backpack",1);
	If(buystage >= 34) GiveInventory("Credits",5);
	If(buystage >= 36) GiveInventory("Backpack",1);
	If(buystage >= 38) GiveInventory("Backpack",1);
	If(buystage >= 40) GiveInventory("Backpack",1);
	If(buystage >= 42) GiveInventory("Credits",5);
	If(buystage >= 44) GiveInventory("MegaSphere",1);
	If(buystage >= 46) GiveInventory("Backpack",1);
	If(buystage >= 48) GiveInventory("Credits",5);
	If(buystage >= 50) GiveInventory("Backpack",1);
	If(buystage >= 52) GiveInventory("Credits",5);
	If(buystage >= 54) GiveInventory("Backpack",1);
	If(buystage >= 56) GiveInventory("Backpack",1);
	If(buystage >= 58) GiveInventory("Credits",5);
	If(buystage >= 60) GiveInventory("Backpack",1);
	If(buystage >= 62) GiveInventory("Backpack",1);
	If(buystage >= 64) GiveInventory("Backpack",1);
	If(buystage >= 66) GiveInventory("Backpack",1);
	If(buystage >= 68) GiveInventory("Credits",5);
	If(buystage >= 70) GiveInventory("Backpack",1);
	If(buystage >= 72) GiveInventory("Backpack",1);
	If(buystage >= 74) GiveInventory("Backpack",1);
	If(buystage >= 76) GiveInventory("Backpack",1);
	If(buystage >= 78) GiveInventory("Credits",5);
	If(buystage >= 80) GiveInventory("Backpack",1);
	If(buystage >= 82) GiveInventory("Backpack",1);
	If(buystage >= 84) GiveInventory("Backpack",1);
	If(buystage >= 86) GiveInventory("Backpack",1);
	If(buystage >= 88) GiveInventory("Credits",5);
	If(buystage >= 90) GiveInventory("Backpack",1);
}

Script "difficulty15" (void)
{	
	difficulty = 15;
	hellonearthdelay = 5;
	print(s:"Debug: Hell on Earth 5 (Difficulty 15)");
}

Script "Debug" (void)
{
	HudMessageBold(s:"p1dead: ",d:p1dead;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 156, "Blue", 0.10, 0.45, 99999);
	HudMessageBold(s:"p1respawn: ",d:p1respawn;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 157, "Blue", 0.10, 0.50, 99999);
	HudMessageBold(s:"p2dead: ",d:p2dead;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 158, "Green", 0.10, 0.55, 99999);
	HudMessageBold(s:"p2respawn: ",d:p2respawn;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 159, "Green", 0.10, 0.60, 99999);
		
		HudMessageBold(s:"p1revivecost: ",d:p1revivesprice;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 161, "Blue", 0.10, 0.65, 99999);
		SetActivator(888);
		str weapon = GetWeapon();
		HudMessageBold(s:"p1weapon: ",s:weapon;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 162, "Blue", 0.10, 0.70, 99999);
		
	
		if(isZandronum() == 3)
		{
			HudMessageBold(s:"Source Port: Zandronum";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 163, "Red", 0.10, 0.80, 99999);
		}
		else
		{
			HudMessageBold(s:"Source Port: ZDoom";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 163, "Red", 0.10, 0.80, 99999);
		}
		
		HudMessageBold(s:"anomalytimer: ",d:anomalytimer;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 164, "Black", 0.80, 0.05, 99999);
		HudMessageBold(s:"anomalytimerequired: ",d:anomalytimerequired;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 165, "Black", 0.80, 0.10, 99999);
		
		HudMessageBold(s:"players: ",d:numplayers;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 166, "Red", 0.80, 0.15, 99999);
		Delay(5);
		Restart;
}

script 999 ENTER //Respawn room textures
{
	Thing_ChangeTID (0, 888+PlayerNumber()); //Player 1 = 888, 2 = 889

	SetCameraToTexture(777,"CAM1",90);
	SetCameraToTexture(778,"CAM2",90);
	SetCameraToTexture(779,"CAM3",90);
	SetCameraToTexture(780,"CAM4",90);
	SetCameraToTexture(781,"CAM5",90);
	SetCameraToTexture(782,"CAM6",90);
}

Script "StartUp" OPEN //this never actually happened lololol
{	
	Delay(5);
	AmbientSound("a4prepar",127); //Everyone hears the SFX
}

Script 1 ENTER //Reset inventory
{
	setPlayerNumber(); //Make sure players entering are given a TID
	ClearInventory();
	GiveInventory("Fist", 1);
	GiveInventory("Pistol",1);
	GiveInventory("Clip",30);
	GiveInventory("Medikit",100); //Full Heal, required in Zandronum for some reason.
}
Script "Respawn" RESPAWN
{
	setPlayerNumber(); //make sure their TID is still set

	//Move Dead Players
	if(PlayerNumber() == 0 && p1respawn > 0)
    {
		Thing_ChangeTid(888,0);
		Thing_ChangeTid(0,888);
        Thing_Move(888,999,1);
		//SetActorProperty(888, TRUE, PROP_TOTALLYFROZEN);
		p1dead = true;
		ClearInventory();
    }
	else if(PlayerNumber() == 1 && p2respawn > 0)
    {
		Thing_ChangeTid(889,0);
		Thing_ChangeTid(0,889);
		Thing_Move(889,999,1);
		//SetActorProperty(889, TRUE, PROP_TOTALLYFROZEN);
		p2dead = true;
		ClearInventory();
    }
	else if(PlayerNumber() == 2 && p3respawn > 0)
    {
		Thing_ChangeTid(890,0);
		Thing_ChangeTid(0,890);
		Thing_Move(890,999,1);
		//SetActorProperty(890, TRUE, PROP_TOTALLYFROZEN);
		p3dead = true;
		ClearInventory();
    }
	else if(PlayerNumber() == 3 && p4respawn > 0)
    {
		Thing_ChangeTid(891,0);
		Thing_ChangeTid(0,891);
        Thing_Move(891,999,1);
		//SetActorProperty(891, TRUE, PROP_TOTALLYFROZEN);
		p4dead = true;
		ClearInventory();
    }

       else if(PlayerNumber() == 0 && p1respawn <= 0)
        {//Player 1
            Thing_ChangeTid(888,0);
            Thing_ChangeTid(0,888);
			RespawnP1();
        }
		else if(PlayerNumber() == 1 && p2respawn <= 0)
        {//Player 2
            Thing_ChangeTid(889,0);
            Thing_ChangeTid(0,889);
			RespawnP2();
        }
		else if(PlayerNumber() == 2 && p3respawn <= 0)
		{//Player 3
            Thing_ChangeTid(890,0);
            Thing_ChangeTid(0,890);
			RespawnP3();
        }
		else if(PlayerNumber() == 3 && p4respawn <= 0)
		{//Player 4
            Thing_ChangeTid(891,0);
            Thing_ChangeTid(0,891);
			RespawnP4();
        }

	ClearInventory();
	GiveInventory("Fist", 1);
	GiveInventory("Pistol",1);
	GiveInventory("Clip",30);
	GiveInventory("Medikit",100); //Full Heal, required in Zandronum for some reason.
	if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
	{
		GiveInventory("Chaingun",1);
		GiveInventory("Shotgun",1);
	}
}

Script 2 OPEN //Alert Enemies. Sloppy but it works lmfao
{
if (p1dead == false)
{
	Thing_Hate(666,888,0);
	Delay(275);
}
else if (p2dead == false)
{
	Thing_Hate(666,889,0);
	Delay(275);
}
else if (p3dead == false)
{
	Thing_Hate(666,890,0);
	Delay(275);
}
else if (p4dead == false)
{
	Thing_Hate(666,891,0);
	Delay(275);
}
Delay(35);
Restart;
}

//Item called scripts
Script "CreditsAll" (void) //Give all players 1 credit if they are "alive"
{
	GiveActorInventory(888,"Credits",1);
	GiveActorInventory(889,"Credits",1);
	GiveActorInventory(890,"Credits",1);
	GiveActorInventory(891,"Credits",1);
}
Script "2CreditsAll" (void)
{
	if(numplayers >= 3) //If 3 or more players, get 1 instead of 2.
	{
		GiveActorInventory(888,"Credits",1);
		GiveActorInventory(889,"Credits",1);
		GiveActorInventory(890,"Credits",1);
		GiveActorInventory(891,"Credits",1);
	}
	else
	{
		GiveActorInventory(888,"Credits",2);
		GiveActorInventory(889,"Credits",2);
		GiveActorInventory(890,"Credits",2);
		GiveActorInventory(891,"Credits",2);
	}
}
Script "3CreditsAll" (void)
{
	if(numplayers >= 4) //If 4 players, get 1 instead of 3.
	{
		GiveActorInventory(888,"Credits",1);
		GiveActorInventory(889,"Credits",1);
		GiveActorInventory(890,"Credits",1);
		GiveActorInventory(891,"Credits",1);
	}
	else
	{
		GiveActorInventory(888,"Credits",3);
		GiveActorInventory(889,"Credits",3);
		GiveActorInventory(890,"Credits",3);
		GiveActorInventory(891,"Credits",3);
	}
}
Script "5CreditsAll" (void)
{
	if(numplayers >= 4) //If 4 players, get 2 instead of 5.
	{
		GiveActorInventory(888,"Credits",2);
		GiveActorInventory(889,"Credits",2);
		GiveActorInventory(890,"Credits",2);
		GiveActorInventory(891,"Credits",2);
	}
	else if(numplayers >= 2 && numplayers <= 3) //If 2-3 players, get 3 instead of 5.
	{
		GiveActorInventory(888,"Credits",3);
		GiveActorInventory(889,"Credits",3);
		GiveActorInventory(890,"Credits",3);
		GiveActorInventory(891,"Credits",3);
	}
	else
	{
		GiveActorInventory(888,"Credits",5);
		GiveActorInventory(889,"Credits",5);
		GiveActorInventory(890,"Credits",5);
		GiveActorInventory(891,"Credits",5);
	}
}

Script "PowerupInvis" (void) //Give all players invisibility
{
	GiveActorInventory(888,"BlurSphere",1);
	GiveActorInventory(889,"BlurSphere",1);
	GiveActorInventory(890,"BlurSphere",1);
	GiveActorInventory(891,"BlurSphere",1);

	AmbientSound("Inv1",127); //Everyone hears the SFX

	HudMessageBold(s:"Partial Invisibility!\n        60 seconds"; HUDMSG_FADEOUT | HUDMSG_COLORSTRING, 4, "GOLD", 0.50, 0.15, 300000);
}

Script "PowerupMaxAmmo" (void) //Give all players max ammo
{
		GiveActorInventory(888,"ClipBox",400);
		GiveActorInventory(888,"ShellBox",100);
		GiveActorInventory(888,"RocketBox",100);
		GiveActorInventory(888,"CellPack",600);
		
		GiveActorInventory(889,"ClipBox",400);
		GiveActorInventory(889,"ShellBox",100);
		GiveActorInventory(889,"RocketBox",100);
		GiveActorInventory(889,"CellPack",600);
		
		GiveActorInventory(890,"ClipBox",400);
		GiveActorInventory(890,"ShellBox",100);
		GiveActorInventory(890,"RocketBox",100);
		GiveActorInventory(890,"CellPack",600);
		
		GiveActorInventory(891,"ClipBox",400);
		GiveActorInventory(891,"ShellBox",100);
		GiveActorInventory(891,"RocketBox",100);
		GiveActorInventory(891,"CellPack",600);

	AmbientSound("Protect",127); //Everyone hears the SFX
	HudMessageBold(s:"Max Ammo!"; HUDMSG_FADEOUT | HUDMSG_COLORSTRING, 4, "GOLD", 0.50, 0.15, 300000);
}

Script "PowerupQuad" (void) //Give all players quad damage
{
	GiveActorInventory(888,"QuadDamage",1);
	GiveActorInventory(889,"QuadDamage",1);
	GiveActorInventory(890,"QuadDamage",1);
	GiveActorInventory(891,"QuadDamage",1);

	AmbientSound("Damage",127); //Everyone hears the SFX

	HudMessageBold(s:"Quad Damage!\n  30 seconds"; HUDMSG_FADEOUT | HUDMSG_COLORSTRING, 4, "GOLD", 0.50, 0.15, 300000);
}

Script "PowerupMegaSphere" (void) //Give all "alive" players a megasphere
{
	//Player 1, Give red armor if they already have it, otherwise give blue armor.
	SetActivator(888);
	if(GetArmorType("RedArmor",PlayerNumber())) GiveActorInventory(888,"RedArmorMegasphere",1);
	else GiveActorInventory(888,"Megasphere",1);
	//Player 2
	SetActivator(889);
	if(GetArmorType("RedArmor",PlayerNumber())) GiveActorInventory(889,"RedArmorMegasphere",1);
	else GiveActorInventory(889,"Megasphere",1);
	//Player 3
	SetActivator(890);
	if(GetArmorType("RedArmor",PlayerNumber())) GiveActorInventory(890,"RedArmorMegasphere",1);
	else GiveActorInventory(890,"Megasphere",1);
	//Player 4
	SetActivator(891);
	if(GetArmorType("RedArmor",PlayerNumber())) GiveActorInventory(891,"RedArmorMegasphere",1);
	else GiveActorInventory(891,"Megasphere",1);

	AmbientSound("Biosuit",127); //Everyone hears the SFX

	HudMessageBold(s:"         Megasphere!\nFull health and armor!"; HUDMSG_FADEOUT | HUDMSG_COLORSTRING, 4, "GOLD", 0.50, 0.15, 300000);
}

Script "PowerupInvuln" (void) //Give all "alive" players invulnerability
{
	GiveActorInventory(888,"InvulnerabilitySphere",1);
	GiveActorInventory(889,"InvulnerabilitySphere",1);
	GiveActorInventory(890,"InvulnerabilitySphere",1);
	GiveActorInventory(891,"InvulnerabilitySphere",1);

	AmbientSound("Runekey",127); //Everyone hears the SFX

	HudMessageBold(s:"   Invulnerability!\n        30 seconds"; HUDMSG_FADEOUT | HUDMSG_COLORSTRING, 4, "GOLD", 0.50, 0.15, 300000);
}

Script "PowerupTimeFreeze" (void) //Give all "alive" players time freeze
{
	GiveActorInventory(888,"TimeFreezeSphere",1);
	GiveActorInventory(889,"TimeFreezeSphere",1);
	GiveActorInventory(890,"TimeFreezeSphere",1);
	GiveActorInventory(891,"TimeFreezeSphere",1);

	AmbientSound("Protect",127); //Everyone hears the SFX

	HudMessageBold(s:"Time Freeze!\n  15 seconds"; HUDMSG_FADEOUT | HUDMSG_COLORSTRING, 4, "GOLD", 0.50, 0.15, 300000);
}

Function Void RespawnP1(void)
{
	SetActivator(888);
	SetActorProperty(888, FALSE, PROP_TOTALLYFROZEN);
	p1dead = false;
	Thing_Move(888,1000); //Move back to play area
	//Reset inventory
	GiveInventory("Fist", 1);
	GiveInventory("Pistol",1);
	GiveInventory("Clip",30);
	GiveInventory("Medikit",100); //Full Heal, required in Zandronum for some reason.
	GiveInventory("ExtraLifeInvuln",1); //15 seconds of Invuln
	//Respawn
	buystage = weaponsbought + difficulty;
	BuyStageItems();
	//
	if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //If Citadel, give the extra weapons
	{
		GiveInventory("Chaingun",1);
		GiveInventory("Shotgun",1);
	}
	SetActorProperty(888,APROP_Health,100);
	p1respawn = 30;
	ClearDisplay();
}
Function Void RespawnP2(void)
{
	SetActivator(889);
	SetActorProperty(889, FALSE, PROP_TOTALLYFROZEN);
	p2dead = false;
	Thing_Move(889,1000); //Move back to play area
	//Reset inventory
	GiveInventory("Fist", 1);
	GiveInventory("Pistol",1);
	GiveInventory("Clip",30);
	GiveInventory("Medikit",100); //Full Heal, required in Zandronum for some reason.
	GiveInventory("ExtraLifeInvuln",1); //15 seconds of Invuln
	//Respawn
	buystage = weaponsbought + difficulty;
	BuyStageItems();
	//
	if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
	{
		GiveInventory("Chaingun",1);
		GiveInventory("Shotgun",1);
	}
	SetActorProperty(889,APROP_Health,100);
	p2respawn = 30;
	ClearDisplay();
}
Function Void RespawnP3(void)
{
	SetActivator(890);
	SetActorProperty(890, FALSE, PROP_TOTALLYFROZEN);
	p3dead = false;
	Thing_Move(890,1000); //Move back to play area
	//Reset inventory
	GiveInventory("Fist", 1);
	GiveInventory("Pistol",1);
	GiveInventory("Clip",30);
	GiveInventory("Medikit",100); //Full Heal, required in Zandronum for some reason.
	GiveInventory("ExtraLifeInvuln",1); //15 seconds of Invuln
	//Respawn
	buystage = weaponsbought + difficulty;
	BuyStageItems();
	//
	if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
	{
		GiveInventory("Chaingun",1);
		GiveInventory("Shotgun",1);
	}
	SetActorProperty(890,APROP_Health,100);
	p3respawn = 30;
	ClearDisplay();
}
Function Void RespawnP4(void)
{
	SetActivator(891);
	SetActorProperty(891, FALSE, PROP_TOTALLYFROZEN);
	p4dead = false;
	Thing_Move(891,1000); //Move back to play area
	//Reset inventory
	GiveInventory("Fist", 1);
	GiveInventory("Pistol",1);
	GiveInventory("Clip",30);
	GiveInventory("Medikit",100); //Full Heal, required in Zandronum for some reason.
	GiveInventory("ExtraLifeInvuln",1); //15 seconds of Invuln
	//Respawn
	buystage = weaponsbought + difficulty;
	BuyStageItems();
	//
	if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
	{
		GiveInventory("Chaingun",1);
		GiveInventory("Shotgun",1);
	}
	SetActorProperty(891,APROP_Health,100);
	p4respawn = 30;
	ClearDisplay();
}

script 4 DEATH
{
	Print(s:"You Died! Left click to respawn or things break!"); //If they don't respawn before timer is up, TID is never assigned
	
	//Boolean Control
		if (GetActorProperty(888,APROP_Health) <= 0 && PlayerCount() >= 1) p1dead = true;
		if (GetActorProperty(889,APROP_Health) <= 0 && PlayerCount() >= 2) p2dead = true;
		if (GetActorProperty(890,APROP_Health) <= 0 && PlayerCount() >= 3) p3dead = true;
		if (GetActorProperty(891,APROP_Health) <= 0 && PlayerCount() >= 4) p4dead = true;

    //Everyone is dead, restart the game
	if(PlayerCount() == 1 && p1dead == true)
    {
        HudMessageBold(s:"ALL PLAYERS DEAD!\n      GAME OVER"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 4, "RED", 0.50, 0.3, 1);
		HudMessageBold(s:"Score: ",d:score; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 789, "GREEN", 0.50, 0.4, 1);
        Delay(500);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			ChangeLevel ("MAP01", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			ChangeLevel ("MAP02", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			ChangeLevel ("MAP03", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			ChangeLevel ("MAP04", 0, 0, -1);
		}
    }
	if(PlayerCount() == 2 && p1dead == true && p2dead == true)
    {
        HudMessageBold(s:"ALL PLAYERS DEAD!\n      GAME OVER"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 4, "RED", 0.50, 0.3, 1);
		HudMessageBold(s:"Score: ",d:score; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 789, "GREEN", 0.50, 0.4, 1);
        Delay(500);
        if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			ChangeLevel ("MAP01", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			ChangeLevel ("MAP02", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			ChangeLevel ("MAP03", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			ChangeLevel ("MAP04", 0, 0, -1);
		}
    }
	if(PlayerCount() == 3 && p1dead == true && p2dead == true && p3dead == true)
    {
        HudMessageBold(s:"ALL PLAYERS DEAD!\n      GAME OVER"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 4, "RED", 0.50, 0.3, 1);
		HudMessageBold(s:"Score: ",d:score; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 789, "GREEN", 0.50, 0.4, 1);
        Delay(500);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			ChangeLevel ("MAP01", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			ChangeLevel ("MAP02", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			ChangeLevel ("MAP03", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			ChangeLevel ("MAP04", 0, 0, -1);
		}
	}
	if(PlayerCount() == 4 && p1dead == true && p2dead == true && p3dead == true && p4dead == true)
    {
        HudMessageBold(s:"ALL PLAYERS DEAD!\n      GAME OVER"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 4, "RED", 0.50, 0.3, 1);
		HudMessageBold(s:"Score: ",d:score; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 789, "GREEN", 0.50, 0.4, 1);
        Delay(500);
        if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			ChangeLevel ("MAP01", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			ChangeLevel ("MAP02", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			ChangeLevel ("MAP03", 0, 0, -1);
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			ChangeLevel ("MAP04", 0, 0, -1);
		}
    }
}

Script 5 OPEN //1 Second Logic
{
	Delay(1);		
	//Respawn Decrements & Display
	if (p1dead == true && p1respawn > 0)
	{
		p1respawn--;
		SetActivator(888);
		HudMessage(s:"Respawn in ",d:p1respawn;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 155, "Red", 0.50, 0.15, 999999);
	}
	if (p2dead == true && p2respawn > 0)
	{
		p2respawn--;
		SetActivator(889);
		HudMessage(s:"Respawn in ",d:p2respawn;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 255, "Red", 0.50, 0.15, 999999);
	}
	if (p3dead == true && p3respawn > 0)
	{
		p3respawn--;
		SetActivator(890);
		HudMessage(s:"Respawn in ",d:p3respawn;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 355, "Red", 0.50, 0.15, 999999);
	}
	if (p4dead == true && p4respawn > 0)
	{
		p4respawn--;
		SetActivator(891);
		HudMessage(s:"Respawn in ",d:p4respawn;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 455, "Red", 0.50, 0.15, 999999);
	}

	//If someones timer has decremented enough, let them respawn.
	if (p1dead == true && p1respawn <= 0)
	{
		SetActivator(888);
		HudMessage(s:"Ready to Respawn";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 155, "Red", 0.50, 0.15, 999999);
	}
	if (p2dead == true && p2respawn <= 0)
	{
		SetActivator(889);
		HudMessage(s:"Ready to Respawn";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 255, "Red", 0.50, 0.15, 999999);
	}
	if (p3dead == true && p3respawn <= 0)
	{
		SetActivator(890);
		HudMessage(s:"Ready to Respawn";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 355, "Red", 0.50, 0.15, 999999);
	}
	if (p4dead == true && p4respawn <= 0)
	{
		SetActivator(891);
		HudMessage(s:"Ready to Respawn";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 455, "Red", 0.50, 0.15, 999999);
	}

	//Move to play area if already respawned and timer is down
		if(GetActorProperty(888,APROP_Health) > 0 && p1dead == true && p1respawn <= 0)
        {//Player 1
			RespawnP1();
        }
		if(GetActorProperty(889,APROP_Health) > 0 && p2dead == true && p2respawn <= 0)
        {//Player 2
			RespawnP2();
        }
		if(GetActorProperty(890,APROP_Health) > 0 && p3dead == true && p3respawn <= 0)
		{//Player 3
			RespawnP3();
        }
		if(GetActorProperty(891,APROP_Health) > 0 && p4dead == true && p4respawn <= 0)
		{//Player 4
			RespawnP4();
        }

	Score++; //Add 1 to score every second.

	//Loop every second
	Delay(34);
	Restart;
}

Script 6 OPEN
{
	ACS_Execute(5,1); //Restart the 1 second logic script if it dies
	Delay(35);
	Restart;
}

Script 100 OPEN //Monster Spawning Behavior - This should really be a switch statement
{
	numplayers = PlayerCount();
	
	Switch(GetLevelInfo(LEVELINFO_LEVELNUM))
	{
		Case(1): //Facility
		{
			if(difficulty == 1)
			{
				Thing_SpawnFacing(100, 200, 1, 666);
				Thing_SpawnFacing(101, 200, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 200, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 200, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 200, 1, 666);
				Delay(105);
			}

			if(difficulty == 2)
			{
				Thing_SpawnFacing(100, 201, 1, 666);
				Thing_SpawnFacing(101, 201, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 201, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 201, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 201, 1, 666);
				Delay(100);
			}

			if(difficulty == 3)
			{
				Thing_SpawnFacing(100, 202, 1, 666);
				Thing_SpawnFacing(101, 202, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 202, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 202, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 202, 1, 666);
				Delay(95);
			}

			if(difficulty == 4)
			{
				Thing_SpawnFacing(100, 203, 1, 666);
				Thing_SpawnFacing(101, 203, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 203, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 203, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 203, 1, 666);
				Delay(90);
			}

			if(difficulty == 5)
			{
				Thing_SpawnFacing(100, 204, 1, 666);
				Thing_SpawnFacing(101, 204, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 204, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 204, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 204, 1, 666);
				Delay(85);
			}

			if(difficulty == 6)
			{
				Thing_SpawnFacing(100, 205, 1, 666);
				Thing_SpawnFacing(101, 205, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 205, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 205, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 205, 1, 666);
				Delay(80);
			}

			if(difficulty == 7)
			{
				Thing_SpawnFacing(100, 206, 1, 666);
				Thing_SpawnFacing(101, 206, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 206, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 206, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 206, 1, 666);
				Delay(80);
			}

			if(difficulty == 8)
			{
				Thing_SpawnFacing(100, 207, 1, 666);
				Thing_SpawnFacing(101, 207, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 207, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 207, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 207, 1, 666);
				Delay(80);
			}

			if(difficulty == 9)
			{
				Thing_SpawnFacing(100, 208, 1, 666);
				Thing_SpawnFacing(101, 208, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 208, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 208, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 208, 1, 666);
				Delay(80);
			}

			if(difficulty == 10)
			{
				Thing_SpawnFacing(100, 209, 1, 666);
				Thing_SpawnFacing(101, 209, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 209, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 209, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 209, 1, 666);

				hellonearthspeed = 79 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty == 11)
			{
				Thing_SpawnFacing(100, 210, 1, 666);
				Thing_SpawnFacing(101, 210, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 210, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 210, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 210, 1, 666);

				hellonearthspeed = 78 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty == 12)
			{
				Thing_SpawnFacing(100, 215, 1, 666);
				Thing_SpawnFacing(101, 215, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 215, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 215, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 215, 1, 666);

				hellonearthspeed = 77 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty == 13)
			{
				Thing_SpawnFacing(100, 216, 1, 666);
				Thing_SpawnFacing(101, 216, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 216, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 216, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 216, 1, 666);

				hellonearthspeed = 76 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty == 14)
			{
				Thing_SpawnFacing(100, 217, 1, 666);
				Thing_SpawnFacing(101, 217, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 217, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 217, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 217, 1, 666);

				hellonearthspeed = 75 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty == 15)
			{
				Thing_SpawnFacing(100, 218, 1, 666);
				Thing_SpawnFacing(101, 218, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 218, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 218, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 218, 1, 666);

				hellonearthspeed = 74 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty == 16)
			{
				Thing_SpawnFacing(100, 219, 1, 666);
				Thing_SpawnFacing(101, 219, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 219, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 219, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 219, 1, 666);

				hellonearthspeed = 73 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty >= 17)
			{
				Thing_SpawnFacing(100, 240, 1, 666);
				Thing_SpawnFacing(101, 240, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 240, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 240, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 240, 1, 666);

				hellonearthspeed = 72 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty >= 18)
			{
				Thing_SpawnFacing(100, 241, 1, 666);
				Thing_SpawnFacing(101, 241, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 241, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 241, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 241, 1, 666);

				hellonearthspeed = 71 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty >= 19)
			{
				Thing_SpawnFacing(100, 242, 1, 666);
				Thing_SpawnFacing(101, 242, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 242, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 242, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 242, 1, 666);

				hellonearthspeed = 70 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			if(difficulty >= 20)
			{
				Thing_SpawnFacing(100, 243, 1, 666);
				Thing_SpawnFacing(101, 243, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 243, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 243, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 243, 1, 666);

				hellonearthspeed = 69 - hellonearthdelay;
				Delay(hellonearthspeed);
			}
			Delay(1);
			Restart;
			Break;
			}
			
			Case(2): //Citadel
			{
				if(difficulty == 1) //Very Easy
				{
					Thing_SpawnFacing(100, 220, 1, 666);
					Thing_SpawnFacing(101, 220, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 220, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 220, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 220, 1, 666);
					Delay(240); //6 second delay on very easy
				}

				if(difficulty == 2) //Easy
				{
					Thing_SpawnFacing(100, 221, 1, 666);
					Thing_SpawnFacing(101, 221, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 221, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 221, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 221, 1, 666);
					Delay(210); //5 second instead of 3 delay between spawns
				}

				if(difficulty == 3) //Medium
				{
					Thing_SpawnFacing(100, 222, 1, 666);
					Thing_SpawnFacing(101, 222, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 222, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 222, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 222, 1, 666);
					Delay(210);
				}

				if(difficulty == 4) //Hard
				{
					Thing_SpawnFacing(100, 223, 1, 666);
					Thing_SpawnFacing(101, 223, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 223, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 223, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 223, 1, 666);
					Delay(210);
				}

				if(difficulty == 5) //Very Hard
				{
					Thing_SpawnFacing(100, 224, 1, 666);
					Thing_SpawnFacing(101, 224, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 224, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 224, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 224, 1, 666);
					Delay(210);
				}

				if(difficulty == 6) //Insane
				{
					Thing_SpawnFacing(100, 225, 1, 666);
					Thing_SpawnFacing(101, 225, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 225, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 225, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 225, 1, 666);
					Delay(210);
				}

				if(difficulty == 7) //Impossible
				{
					Thing_SpawnFacing(100, 226, 1, 666);
					Thing_SpawnFacing(101, 226, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 226, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 226, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 226, 1, 666);
					Delay(210);
				}

				if(difficulty == 8) //Agony
				{
					Thing_SpawnFacing(100, 227, 1, 666);
					Thing_SpawnFacing(101, 227, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 227, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 227, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 227, 1, 666);
					Delay(210);
				}

				if(difficulty == 9) //Torment
				{
					Thing_SpawnFacing(100, 228, 1, 666);
					Thing_SpawnFacing(101, 228, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 228, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 228, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 228, 1, 666);
					Delay(210);
				}

				if(difficulty == 10) //Hell on Earth 1
				{
					Thing_SpawnFacing(100, 229, 1, 666);
					Thing_SpawnFacing(101, 229, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 229, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 229, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 229, 1, 666);

					hellonearthspeed = 209 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 11) //Hell on Earth 2
				{
					Thing_SpawnFacing(100, 230, 1, 666);
					Thing_SpawnFacing(101, 230, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 230, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 230, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 230, 1, 666);

					hellonearthspeed = 208 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 12) //Hell on Earth 3
				{
					Thing_SpawnFacing(100, 231, 1, 666);
					Thing_SpawnFacing(101, 231, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 231, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 231, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 231, 1, 666);

					hellonearthspeed = 207 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 13) //Hell on Earth 4
				{
					Thing_SpawnFacing(100, 232, 1, 666);
					Thing_SpawnFacing(101, 232, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 232, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 232, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 232, 1, 666);

					hellonearthspeed = 206 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 14) //Hell on Earth 5
				{
					Thing_SpawnFacing(100, 233, 1, 666);
					Thing_SpawnFacing(101, 233, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 233, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 233, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 233, 1, 666);

					hellonearthspeed = 205 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 15) //Hell on Earth 6
				{
					Thing_SpawnFacing(100, 234, 1, 666);
					Thing_SpawnFacing(101, 234, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 234, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 234, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 234, 1, 666);

					hellonearthspeed = 204 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 16) //Hell on Earth 7
				{
					Thing_SpawnFacing(100, 235, 1, 666);
					Thing_SpawnFacing(101, 235, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 235, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 235, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 235, 1, 666);

					hellonearthspeed = 203 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 17) //Hell on Earth 8
				{
					Thing_SpawnFacing(100, 236, 1, 666);
					Thing_SpawnFacing(101, 236, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 236, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 236, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 236, 1, 666);

					hellonearthspeed = 202 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 18) //Hell on Earth 9
				{
					Thing_SpawnFacing(100, 237, 1, 666);
					Thing_SpawnFacing(101, 237, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 237, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 237, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 237, 1, 666);

					hellonearthspeed = 201 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty == 19) //Hell on Earth 10
				{
					Thing_SpawnFacing(100, 238, 1, 666);
					Thing_SpawnFacing(101, 238, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 238, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 238, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 238, 1, 666);

					hellonearthspeed = 200 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
				if(difficulty >= 20) //Hell on Earth 11
				{
					Thing_SpawnFacing(100, 239, 1, 666);
					Thing_SpawnFacing(101, 239, 1, 666);
					if(numplayers >= 2) Thing_SpawnFacing(102, 239, 1, 666);
					if(numplayers >= 3) Thing_SpawnFacing(103, 239, 1, 666);
					if(numplayers >= 4) Thing_SpawnFacing(104, 239, 1, 666);

					hellonearthspeed = 199 - hellonearthdelay;
					Delay(hellonearthspeed);
				}
			Delay(1);
			Restart;
			Break;
			}
			
			Case(3): //Corrupt//////////////////////////////////////
			{
			if(difficulty == 1)
			{
				Thing_SpawnFacing(100, 180, 1, 666);
				Thing_SpawnFacing(101, 180, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 180, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 180, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 180, 1, 666);
				Delay(175);
			}
			if(difficulty == 2)
			{
				Thing_SpawnFacing(100, 181, 1, 666);
				Thing_SpawnFacing(101, 181, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 181, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 181, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 181, 1, 666);
				Delay(140);
			}
			if(difficulty == 3)
			{
				Thing_SpawnFacing(100, 182, 1, 666);
				Thing_SpawnFacing(101, 182, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 182, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 182, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 182, 1, 666);
				Delay(140);
			}
			if(difficulty == 4)
			{
				Thing_SpawnFacing(100, 183, 1, 666);
				Thing_SpawnFacing(101, 183, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 183, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 183, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 183, 1, 666);
				Delay(140);
			}
			if(difficulty == 5)
			{
				Thing_SpawnFacing(100, 184, 1, 666);
				Thing_SpawnFacing(101, 184, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 184, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 184, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 184, 1, 666);
				Delay(140);
			}
			if(difficulty == 6)
			{
				Thing_SpawnFacing(100, 185, 1, 666);
				Thing_SpawnFacing(101, 185, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 185, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 185, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 185, 1, 666);
				Delay(140);
			}
			if(difficulty == 7)
			{
				Thing_SpawnFacing(100, 186, 1, 666);
				Thing_SpawnFacing(101, 186, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 186, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 186, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 186, 1, 666);
				Delay(140);
			}
			if(difficulty == 8)
			{
				Thing_SpawnFacing(100, 187, 1, 666);
				Thing_SpawnFacing(101, 187, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 187, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 187, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 187, 1, 666);
				Delay(140);
			}
			if(difficulty == 9)
			{
				Thing_SpawnFacing(100, 188, 1, 666);
				Thing_SpawnFacing(101, 188, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 188, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 188, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 188, 1, 666);
				Delay(140);
			}
			if(difficulty == 10)
			{
				Thing_SpawnFacing(100, 189, 1, 666);
				Thing_SpawnFacing(101, 189, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 189, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 189, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 189, 1, 666);
				Delay(140);
			}
			if(difficulty == 11)
			{
				Thing_SpawnFacing(100, 190, 1, 666);
				Thing_SpawnFacing(101, 190, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 190, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 190, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 190, 1, 666);
				Delay(140);
			}
			if(difficulty == 12)
			{
				Thing_SpawnFacing(100, 191, 1, 666);
				Thing_SpawnFacing(101, 191, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 191, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 191, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 191, 1, 666);
				Delay(140);
			}
			if(difficulty == 13)
			{
				Thing_SpawnFacing(100, 192, 1, 666);
				Thing_SpawnFacing(101, 192, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 192, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 192, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 192, 1, 666);
				Delay(140);
			}
			if(difficulty == 14)
			{
				Thing_SpawnFacing(100, 193, 1, 666);
				Thing_SpawnFacing(101, 193, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 193, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 193, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 193, 1, 666);
				Delay(140);
			}
			if(difficulty == 15)
			{
				Thing_SpawnFacing(100, 194, 1, 666);
				Thing_SpawnFacing(101, 194, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 194, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 194, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 194, 1, 666);
				Delay(140);
			}
			if(difficulty == 16)
			{
				Thing_SpawnFacing(100, 195, 1, 666);
				Thing_SpawnFacing(101, 195, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 195, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 195, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 195, 1, 666);
				Delay(140);
			}
			if(difficulty == 17)
			{
				Thing_SpawnFacing(100, 196, 1, 666);
				Thing_SpawnFacing(101, 196, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 196, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 196, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 196, 1, 666);
				Delay(140);
			}
			if(difficulty == 18)
			{
				Thing_SpawnFacing(100, 197, 1, 666);
				Thing_SpawnFacing(101, 197, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 197, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 197, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 197, 1, 666);
				Delay(140);
			}
			if(difficulty == 19)
			{
				Thing_SpawnFacing(100, 198, 1, 666);
				Thing_SpawnFacing(101, 198, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 198, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 198, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 198, 1, 666);
				Delay(140);
			}
			if(difficulty >= 20)
			{
				Thing_SpawnFacing(100, 199, 1, 666);
				Thing_SpawnFacing(101, 199, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 199, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 199, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 199, 1, 666);
				Delay(140);
			}
		Delay(1);
		Restart;
		Break;
		}
		
		Case(4): //Abyss//////////////////////////////////////
			{
			if(difficulty == 1)
			{
				Thing_SpawnFacing(100, 180, 1, 666);
				Thing_SpawnFacing(101, 180, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 180, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 180, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 180, 1, 666);
				Delay(175);
			}
			if(difficulty == 2)
			{
				Thing_SpawnFacing(100, 181, 1, 666);
				Thing_SpawnFacing(101, 181, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 181, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 181, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 181, 1, 666);
				Delay(140);
			}
			if(difficulty == 3)
			{
				Thing_SpawnFacing(100, 182, 1, 666);
				Thing_SpawnFacing(101, 182, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 182, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 182, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 182, 1, 666);
				Delay(140);
			}
			if(difficulty == 4)
			{
				Thing_SpawnFacing(100, 183, 1, 666);
				Thing_SpawnFacing(101, 183, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 183, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 183, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 183, 1, 666);
				Delay(140);
			}
			if(difficulty == 5)
			{
				Thing_SpawnFacing(100, 184, 1, 666);
				Thing_SpawnFacing(101, 184, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 184, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 184, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 184, 1, 666);
				Delay(140);
			}
			if(difficulty == 6)
			{
				Thing_SpawnFacing(100, 185, 1, 666);
				Thing_SpawnFacing(101, 185, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 185, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 185, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 185, 1, 666);
				Delay(140);
			}
			if(difficulty == 7)
			{
				Thing_SpawnFacing(100, 186, 1, 666);
				Thing_SpawnFacing(101, 186, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 186, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 186, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 186, 1, 666);
				Delay(140);
			}
			if(difficulty == 8)
			{
				Thing_SpawnFacing(100, 187, 1, 666);
				Thing_SpawnFacing(101, 187, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 187, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 187, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 187, 1, 666);
				Delay(140);
			}
			if(difficulty == 9)
			{
				Thing_SpawnFacing(100, 188, 1, 666);
				Thing_SpawnFacing(101, 188, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 188, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 188, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 188, 1, 666);
				Delay(140);
			}
			if(difficulty == 10)
			{
				Thing_SpawnFacing(100, 189, 1, 666);
				Thing_SpawnFacing(101, 189, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 189, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 189, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 189, 1, 666);
				Delay(140);
			}
			if(difficulty == 11)
			{
				Thing_SpawnFacing(100, 190, 1, 666);
				Thing_SpawnFacing(101, 190, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 190, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 190, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 190, 1, 666);
				Delay(140);
			}
			if(difficulty == 12)
			{
				Thing_SpawnFacing(100, 191, 1, 666);
				Thing_SpawnFacing(101, 191, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 191, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 191, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 191, 1, 666);
				Delay(140);
			}
			if(difficulty == 13)
			{
				Thing_SpawnFacing(100, 192, 1, 666);
				Thing_SpawnFacing(101, 192, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 192, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 192, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 192, 1, 666);
				Delay(140);
			}
			if(difficulty == 14)
			{
				Thing_SpawnFacing(100, 193, 1, 666);
				Thing_SpawnFacing(101, 193, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 193, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 193, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 193, 1, 666);
				Delay(140);
			}
			if(difficulty == 15)
			{
				Thing_SpawnFacing(100, 194, 1, 666);
				Thing_SpawnFacing(101, 194, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 194, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 194, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 194, 1, 666);
				Delay(140);
			}
			if(difficulty == 16)
			{
				Thing_SpawnFacing(100, 195, 1, 666);
				Thing_SpawnFacing(101, 195, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 195, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 195, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 195, 1, 666);
				Delay(140);
			}
			if(difficulty == 17)
			{
				Thing_SpawnFacing(100, 196, 1, 666);
				Thing_SpawnFacing(101, 196, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 196, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 196, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 196, 1, 666);
				Delay(140);
			}
			if(difficulty == 18)
			{
				Thing_SpawnFacing(100, 197, 1, 666);
				Thing_SpawnFacing(101, 197, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 197, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 197, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 197, 1, 666);
				Delay(140);
			}
			if(difficulty == 19)
			{
				Thing_SpawnFacing(100, 198, 1, 666);
				Thing_SpawnFacing(101, 198, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 198, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 198, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 198, 1, 666);
				Delay(140);
			}
			if(difficulty >= 20)
			{
				Thing_SpawnFacing(100, 199, 1, 666);
				Thing_SpawnFacing(101, 199, 1, 666);
				if(numplayers >= 2) Thing_SpawnFacing(102, 199, 1, 666);
				if(numplayers >= 3) Thing_SpawnFacing(103, 199, 1, 666);
				if(numplayers >= 4) Thing_SpawnFacing(104, 199, 1, 666);
				Delay(140);
			}
		Delay(1);
		Restart;
		Break;
		}
	}
}
///////////////
//Shop System//
///////////////

Script 500 (void) //Chaingun Display
{
	if(CheckInventory("Chaingun") == 0 && CheckInventory("EnhancedChaingun") == 0 && CheckInventory("PerfectedChaingun") == 0)
	{
		Print(s:"A Chaingun. Price: 5 credits");
	}

	else if(CheckInventory("Chaingun") == 1 || CheckInventory("EnhancedChaingun") == 1 || CheckInventory("PerfectedChaingun") == 1)
	{
		Print(s:"100 Extra ammo for the Chaingun. Price: 5 credits");
	}
}

Script 501 (void) //Chaingun Buy
{
	if(CheckInventory("Credits") >= 5 && CheckInventory("Chaingun") == 0 && CheckInventory("EnhancedChaingun") == 0 && 
	CheckInventory("PerfectedChaingun") == 0)
	{
		Print(s:"Chaingun Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Chaingun",1);
		SetWeapon("Chaingun");
		GiveInventory("Clip",40);
		TakeInventory("Credits",5);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("Chaingun") == 0 && CheckInventory("EnhancedChaingun") == 0 && 
	CheckInventory("PerfectedChaingun") == 0)
	{
		print(s:"Not enough credits for a Chaingun!");
	}

	else if(CheckInventory("Credits") >= 5 && CheckInventory("Chaingun") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("EnhancedChaingun") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("PerfectedChaingun") == 1)
	{
		Print(s:"Extra ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Clip",100);
		TakeInventory("Credits",5);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("Chaingun") == 1 ||
	CheckInventory("Credits") < 5 && CheckInventory("EnhancedChaingun") == 1 ||
	CheckInventory("Credits") < 5 && CheckInventory("PerfectedChaingun") == 1)
	{
		print(s:"Not enough credits for extra ammo!");
	}
}

///////////////
////Shotgun////
///////////////

Script 502 (void) //Shotgun Display
{
	if(CheckInventory("Shotgun") == 0 && CheckInventory("EnhancedShotgun") == 0)
	{
	print(s:"A Shotgun. Price: 5 credits");
	}

	else if(CheckInventory("Shotgun") == 1 || CheckInventory("EnhancedShotgun") == 1)
	{
	print(s:"20 Extra shells for the Shotgun. Price: 5 credits");
	}
}

Script 503 (void) //Shotgun Buy
{
	if(CheckInventory("Credits") >= 5 && CheckInventory("Shotgun") == 0)
	{
		print(s:"Shotgun Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Shotgun",1);
		SetWeapon("Shotgun");
		TakeInventory("Credits",5);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("Shotgun") == 0)
	{
		print(s:"Not enough credits for a Shotgun!");
	}

	else if(CheckInventory("Credits") >= 5 && CheckInventory("Shotgun") == 1 || CheckInventory("Credits") >= 5 && CheckInventory("EnhancedShotgun") == 1)
	{
		print(s:"Extra ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Shell",20);
		TakeInventory("Credits",5);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("Shotgun") == 1 || CheckInventory("Credits") >= 5 && CheckInventory("EnhancedShotgun") == 1)
	{
		print(s:"Not enough credits for extra ammo!");
	}
}

Script 504 (void) //Green Armor Display
{
	print(s:"Security Armor that absorbs 33% of all damage. Price: 5 credits.");
}

Script 505 (void) //Green Armor Buy
{
	if(CheckInventory("Credits") >= 5)
	{
		print(s:"Security Armor Purchased!");
		GiveInventory("GreenArmor",1);
		TakeInventory("Credits",5);
		PlaySound(0,"Armor1"); //SFX
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5)
	{
		print(s:"Not enough credits for Security Armor!");
	}
	
Delay(35); //Prevent double buys
}

/////////////////////
////Super Shotgun////
/////////////////////

Script 506 (void) //Super Shotgun Display
{
	if(CheckInventory("SuperShotgun") == 0 && CheckInventory("EnhancedSuperShotgun") == 0 &&
	CheckInventory("PerfectedSuperShotgun") == 0)
	{
		print(s:"A Super Shotgun. Price: 20 credits");
	}

	else if(CheckInventory("SuperShotgun") == 1 || CheckInventory("EnhancedSuperShotgun") == 1 ||
	CheckInventory("PerfectedSuperShotgun") == 1)
	{
		print(s:"20 Extra shells for the Super Shotgun. Price: 5 credits");
	}
}

Script 507 (void) //Super Shotgun Buy
{
	if(CheckInventory("Credits") >= 20 && CheckInventory("SuperShotgun") == 0 && 
	CheckInventory("EnhancedSuperShotgun") == 0 && CheckInventory("PerfectedSuperShotgun") == 0)
	{
		Print(s:"Super Shotgun Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("SuperShotgun",1);
		SetWeapon("SuperShotgun");
		TakeInventory("Credits",20);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 20 && CheckInventory("SuperShotgun") == 0 &&
	CheckInventory("EnhancedSuperShotgun") == 0 && CheckInventory("PerfectedSuperShotgun") == 0)
	{
		Print(s:"Not enough credits for a Super Shotgun!");
	}

	else if(CheckInventory("Credits") >= 5 && CheckInventory("SuperShotgun") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("EnhancedSuperShotgun") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("PerfectedSuperShotgun") == 1)
	{
		Print(s:"Extra ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Shell",20);
		TakeInventory("Credits",5);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("SuperShotgun") == 1 ||
	CheckInventory("Credits") < 5 && CheckInventory("EnhancedSuperShotgun") == 1 ||
	CheckInventory("Credits") < 5 && CheckInventory("PerfectedSuperShotgun") == 1)
	{
		print(s:"Not enough credits for extra ammo!");
	}
}

Script 508 (void) //Medikit Display
{
	GetSourceport(); //Check source port
	if(sourceport == "ZDoom")
	{
		print(s:"A Medikit that heals 100 hit points. Price: 5 credits.");
	}
	if(sourceport == "Zandronum")
	{
		print(s:"A Medikit that heals 100 hit points. Price: 5 credits.");
	}
}

Script 509 (void) //Medikit
{
	if(CheckInventory("Credits") >= 5)
	{
		Print(s:"Medikit Purchased!");
		PlaySound(0,"Health1");
		GiveInventory("Medikit",100);
		TakeInventory("Credits",5);
	}
	
	else if(CheckInventory("Credits") < 5)
	{
		Print(s:"Not enough credits for Medikit!");
	}
	
Delay(35); //Prevent double buys
/*
	GetSourceport(); //Check source port
	if(sourceport == "ZDoom") //ZDoom
	{
		if(CheckInventory("Credits") >= 5 && GetActorProperty(0, APROP_Health) < GetActorProperty(0,APROP_SpawnHealth) )
		{
			Print(s:"Medikit Purchased!");
			PlaySound(0,"Health1");
			GiveInventory("Medikit",100);
			TakeInventory("Credits",5);
			Delay(5);
		}

		else if(CheckInventory("Credits") < 5)
		{
			Print(s:"Not enough credits for Medikit!");
		}

		else if(CheckInventory("Credits") >= 5 && GetActorProperty(0, APROP_Health) >= GetActorProperty(0,APROP_SpawnHealth) )
		{
			Print(s:"You are already at full health!");
		}
	}
	else if(sourceport == "Zandronum") //Zandronum - Dont check for current health
	{
		if(CheckInventory("Credits") >= 5)
		{
			Print(s:"Medikit Purchased!");
			PlaySound(0,"Health1");
			GiveInventory("Medikit",100);
			TakeInventory("Credits",5);
			Delay(5);
		}
		else if(CheckInventory("Credits") < 5)
		{
			Print(s:"Not enough credits for Medikit!");
		}
	}
	*/
}

///////////////////////
////Rocket Launcher////
///////////////////////

Script 510 (void) //Rocket Launcher Display
{
	if(CheckInventory("RocketLauncher") == 0 && CheckInventory("EnhancedRocketLauncher") == 0 && CheckInventory("PerfectedRocketLauncher") == 0)
	{
		print(s:"A Rocket Launcher. Price: 25 credits");
	}

	else if(CheckInventory("RocketLauncher") == 1 || CheckInventory("EnhancedRocketLauncher") == 1 || CheckInventory("PerfectedRocketLauncher") == 1)
	{
		print(s:"8 Extra rockets for the Rocket Launcher. Price: 5 credits");
	}
}

Script 511 (void) //Rocket Launcher Buy
{
	if(CheckInventory("Credits") >= 25 && CheckInventory("RocketLauncher") == 0 && CheckInventory("EnhancedRocketLauncher") == 0
	&& CheckInventory("PerfectedRocketLauncher") == 0)
	{
		print(s:"Rocket Launcher Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("RocketLauncher",1);
		GiveInventory("RocketBox",4);
		SetWeapon("RocketLauncher");
		TakeInventory("Credits",25);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 25 && CheckInventory("RocketLauncher") == 0 && CheckInventory("EnhancedRocketLauncher") == 0)
	{
		print(s:"Not enough credits for a Rocket Launcher!");
	}

	else if(CheckInventory("Credits") >= 5 && CheckInventory("RocketLauncher") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("EnhancedRocketLauncher") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("PerfectedRocketLauncher") == 1)
	{
		print(s:"Extra ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("RocketBox",8);
		TakeInventory("Credits",5);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("RocketLauncher") == 1 ||
	CheckInventory("Credits") < 5 &&  CheckInventory("EnhancedRocketLauncher") == 1 ||
	CheckInventory("Credits") < 5 &&  CheckInventory("PerfectedRocketLauncher") == 1)
	{
		print(s:"Not enough credits for extra ammo!");
	}
}

/////////////////////
////Backpack/////////
/////////////////////

Script 512 (void) //Backpack Display
{
	if(CheckInventory("Backpack") <= 0)
	{
		print(s:"A Backpack that raises your carrying capacity. Also contains a small amount of all ammo. Price: 15 credits.");
	}
	
	else if(CheckInventory("Backpack") >= 1)
	{
		print(s:"50 Bullets, 10 Shells, 4 Rockets and 25 Cells. Price: 10 credits.");
	}
}

Script 513 (void) //Backpack Buy
{
	if(CheckInventory("Credits") >= 15 && CheckInventory("Backpack") <= 0)
	{
		print(s:"Backpack Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Backpack",1);
		TakeInventory("Credits",15);
		Delay(5);
	}
	
	else if(CheckInventory("Credits") < 15 && CheckInventory("Backpack") <= 0)
	{
		print(s:"Not enough credits for a Backpack!");
	}
	
	else if(CheckInventory("Credits") >= 10 && CheckInventory("Backpack") >= 1)
	{
		print(s:"Ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Clip",50);
		GiveInventory("Shell",10);
		GiveInventory("RocketAmmo",4);
		GiveInventory("Cell",25);
		TakeInventory("Credits",10);
		weaponsbought++;
		Delay(5);
	}
	
	else if(CheckInventory("Credits") < 10 && CheckInventory("Backpack") >= 1)
	{
		print(s:"Not enough credits for ammo!");
	}
}

/////////////////////
////Plasma Rifle/////
/////////////////////

Script 514 (void) //Plasma Rifle Display
{
	if(CheckInventory("PlasmaRifle") == 0 && CheckInventory("EnhancedPlasmaRifle") == 0 && CheckInventory("PerfectedPlasmaRifle") == 0)
	{
		Print(s:"A Plasma Rifle. Price: 25 credits");
	}

	else if(CheckInventory("PlasmaRifle") == 1 || CheckInventory("EnhancedPlasmaRifle") == 1 && CheckInventory("PerfectedPlasmaRifle") == 1)
	{
		Print(s:"50 Extra cells for the Plasma Rifle. Price: 5 credits");
	}
}

Script 515 (void) //Plasma Rifle Buy
{
	if(CheckInventory("Credits") >= 25 && CheckInventory("PlasmaRifle") == 0 && 
	CheckInventory("EnhancedPlasmaRifle") == 0 && CheckInventory("PerfectedPlasmaRifle") == 0)
	{
		Print(s:"Plasma Rifle Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("PlasmaRifle",1);
		GiveInventory("Cell",10);
		SetWeapon("PlasmaRifle");
		TakeInventory("Credits",25);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 25 && CheckInventory("PlasmaRifle") == 0)
	{
		print(s:"Not enough credits for a Plasma Rifle!");
	}

	else if(CheckInventory("Credits") >= 5 && CheckInventory("PlasmaRifle") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("EnhancedPlasmaRifle") == 1 ||
	CheckInventory("Credits") >= 5 && CheckInventory("PerfectedPlasmaRifle") == 1)
	{
		Print(s:"Extra ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Cell",50);
		TakeInventory("Credits",5);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 5 && CheckInventory("PlasmaRifle") == 1 ||
	CheckInventory("Credits") < 5 && CheckInventory("EnhancedPlasmaRifle") == 1 ||
	CheckInventory("Credits") < 5 && CheckInventory("PerfectedPlasmaRifle") == 1)
	{
		Print(s:"Not enough credits for extra ammo!");
	}
}

/////////////////////
////BFG9000//////////
/////////////////////

Script 516 (void) //BFG9000 Display
{
	if(CheckInventory("BFG9000") == 0  && CheckInventory("EnhancedBFG9000") == 0 && CheckInventory("PerfectedBFG9000") == 0)
	{
		print(s:"A BFG 9000. Price: 40 credits");
	}

	else if(CheckInventory("BFG9000") == 1 || CheckInventory("EnhancedBFG9000") == 1 || CheckInventory("PerfectedBFG9000") == 1)
	{
		print(s:"100 Extra cells for the BFG 9000. Price: 10 credits");
	}
}

Script 517 (void) //BFG9000 Buy
{
	if(CheckInventory("Credits") >= 40 && CheckInventory("BFG9000") == 0 && CheckInventory("EnhancedBFG9000") == 0 &&
	CheckInventory("PerfectedBFG9000") == 0)
	{
		Print(s:"BFG9000 Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("BFG9000",1);
		SetWeapon("BFG9000");
		TakeInventory("Credits",40);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 40 && CheckInventory("BFG9000") == 0 && CheckInventory("EnhancedBFG9000") == 0 && 
	CheckInventory("PerfectedBFG9000") == 0)
	{
		print(s:"Not enough credits for a BFG 9000!");
	}

	else if(CheckInventory("Credits") >= 10 && CheckInventory("BFG9000") == 1 || 
	CheckInventory("Credits") >= 10 && CheckInventory("EnhancedBFG9000") == 1 ||
	CheckInventory("Credits") >= 10 && CheckInventory("PerfectedBFG9000") == 1)
	{
		print(s:"Extra ammo Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Cell",100);
		TakeInventory("Credits",10);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 10 && CheckInventory("BFG9000") == 1 ||
	CheckInventory("Credits") < 10 && CheckInventory("EnhancedBFG9000") == 1 ||
	CheckInventory("Credits") < 10 && CheckInventory("PerfectedBFG9000") == 1)
	{
		print(s:"Not enough credits for extra ammo!");
	}
}

/////////////////////
////Combat Armor/////
/////////////////////

Script 518 (void) //Blue Armor Display
{
	Print(s:"Combat Armor that absorbs 50% of all damage. Price: 25 credits.");
}

Script 519 (void) //Blue Armor Buy
{
	if(CheckInventory("Credits") >= 25)
	{
		Print(s:"Combat Armor Purchased!");
		PlaySound(0,"Armor1");
		GiveInventory("BlueArmor",1);
		TakeInventory("Credits",25);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 25)
	{
		Print(s:"Not enough credits for Combat Armor!");
	}
	
Delay(35); //Prevent double buys
}

Script "ChainsawDisplay" (void) //Chainsaw
{
	if(CheckInventory("Chainsaw") == 0 && CheckInventory("EnhancedChainsaw") == 0)
	{
		print(s:"A Chainsaw. Price: 10 credits");
	}

	else if(CheckInventory("Chainsaw") == 1 || CheckInventory("EnhancedChainsaw") == 1)
	{
		print(s:"You already own the Chainsaw!");
	}
}

Script "ChainsawBuy" (void) //Chainsaw
{
	if(CheckInventory("Credits") >= 10 && CheckInventory("Chainsaw") == 0 && CheckInventory("EnhancedChainsaw") == 0)
	{
		print(s:"Chainsaw Purchased!");
		PlaySound(0,"misc/w_pkup");
		GiveInventory("Chainsaw",1);
		SetWeapon("Chainsaw");
		TakeInventory("Credits",10);
		weaponsbought++;
		Delay(5);
	}

	else if(CheckInventory("Credits") < 10 && CheckInventory("Chainsaw") == 0 && CheckInventory("EnhancedChainsaw") == 0)
	{
		print(s:"Not enough credits for a Chainsaw!");
	}
	
	else if(CheckInventory("Chainsaw") == 1 || CheckInventory("EnhancedChainsaw") == 1)
	{
		print(s:"You already own the Chainsaw!");
	}
}

Script "RedArmorDisplay" (void) //Red Armor Display
{
	print(s:"Specialist Armor that absorbs 60% of all damage. Price: 50 credits.");
}

Script "RedArmorBuy" (void) //Red Armor Buy
{
	if(CheckInventory("Credits") >= 50)
	{
		print(s:"Specialist Armor Purchased!");
		PlaySound(0,"Armor1");
		GiveInventory("RedArmor",1);
		TakeInventory("Credits",50);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 50)
	{
		print(s:"Not enough credits for Specialist Armor!");
	}
Delay(35); //Prevent double buys
}

Script "MegasphereDisplay" (void) //
{
	print(s:"A MegaSphere for your team. Price: 100 credits.");
}

Script "MegasphereBuy" (void) //
{
	if(CheckInventory("Credits") >= 100)
	{
		print(s:"Megasphere Purchased!");
		ACS_NamedExecute("PowerupMegaSphere",0);
		TakeInventory("Credits",100);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 100)
	{
		print(s:"Not enough credits for a Megasphere!");
	}
Delay(105); //Prevent double buys
}

Script "MaxAmmoDisplay" (void) //
{
	print(s:"Max Ammo for your team. Price: 200 credits.");
}

Script "MaxAmmoBuy" (void) //
{
	if(CheckInventory("Credits") >= 200)
	{
		print(s:"Max Ammo Purchased!");
		ACS_NamedExecute("PowerupMaxAmmo",0);
		TakeInventory("Credits",200);
		Delay(5);
	}

	else if(CheckInventory("Credits") < 200)
	{
		print(s:"Not enough credits for Max Ammo!");
	}
Delay(105); //Prevent double buys
}

Script 1000 OPEN //Difficulty Display & Music.
{
	if(difficulty == 1)
	{
		HudMessageBold(s:"Difficulty: Very Easy";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "White", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			SetMusic("FAVEREAS");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			SetMusic("CIVEREAS");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			SetMusic("COVEREAS");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("ABVEREAS");
		}
	}
	
	if(difficulty == 2)
	{
		HudMessageBold(s:"Difficulty: Easy";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Green", 0.05, 0.05, 999999999);
		Delay(35);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			SetMusic("FAEASY");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			SetMusic("CIEASY");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			SetMusic("COEASY");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIEASY");
		}
	}

	if(difficulty == 3)
	{
		HudMessageBold(s:"Difficulty: Medium";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Yellow", 0.05, 0.05, 999999999);
		Delay(35);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1)
		{
			SetMusic("FAMEDIUM");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2)
		{
			SetMusic("CIMEDIUM");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3)
		{
			SetMusic("COMEDIUM");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIMEDIUM");
		}
	}

	if(difficulty == 4)
	{
		HudMessageBold(s:"Difficulty: Hard";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Orange", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1)
		{
			SetMusic("FAHARD");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2)
		{
			SetMusic("CIHARD");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3)
		{
			SetMusic("COHARD");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIHARD");
		}
	}

	if(difficulty == 5)
	{
		HudMessageBold(s:"Difficulty: Very Hard";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Red", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1)
		{
			SetMusic("FAVERHAR");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2)
		{
			SetMusic("CIVERHAR");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3)
		{
			SetMusic("COVERHAR");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIVERHAR");
		}
	}

	if(difficulty == 6)
	{
		HudMessageBold(s:"Difficulty: Insane";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Grey", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1)
		{
			SetMusic("FAINSANE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2)
		{
			SetMusic("CIINSANE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			SetMusic("COINSANE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIINSANE");
		}
	}

	if(difficulty == 7)
	{
		HudMessageBold(s:"Difficulty: Impossible";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Black", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			SetMusic("FAIMPOSS");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			SetMusic("CIIMPOSS");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			SetMusic("COVERHAR");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIIMPOSS");
		}
	}

	if(difficulty == 8)
	{
		HudMessageBold(s:"Difficulty: Agony";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Gold", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1)
		{
			SetMusic("FAAGONY");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2)
		{
			SetMusic("CIAGONY");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3)
		{
			SetMusic("COINSANE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIAGONY");
		}
	}

	if(difficulty == 9)
	{
		HudMessageBold(s:"Difficulty: Torment";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Gray", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			SetMusic("FATORMEN");
		}	
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			SetMusic("CITORMEN");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			SetMusic("COVERHAR");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CITORMEN");
		}
	}

	if(difficulty >= 10)
	{
		HudMessageBold(s:"Difficulty: Hell on Earth ",d:hellonearthdelay;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 100, "Black", 0.05, 0.05, 999999999);
		if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
		{
			SetMusic("FAHELLOE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
		{
			SetMusic("CIHELLOE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
		{
			SetMusic("COINSANE");
		}
		else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
		{
			SetMusic("CIHELLOE");
		}
	}

delay(35);
restart;
}

Script 1001 OPEN //Every second, add 1 to the dtimer integer.
{
	delay(35);
	dtimer += 1;
	restart;
}

Script 1002 OPEN //every 2 minutes, reset the timer, and add 1 to the difficulty.
{
	if(dtimer >= 120)
	{
		dtimer = 0;
		difficulty += 1;
		HudMessageBold(s:"DIFFICULTY INCREASED";
		HUDMSG_TYPEON | HUDMSG_COLORSTRING, 101, "RED", 0.5, 0.40, 200000);

		if(difficulty > 9) //Add to the Hell on Earth Delay when on Hell on Earth
		{
			hellonearthdelay++;
		}
	}

delay(1);
restart;
}

//Perks ---------------------------

//Health Regeneration
Script 1300 (void)
{
	Switch(CheckInventory("HealthRegenPerk"))
	{
		Case(0):
		{
			HudMessage(s:"Perk: Health Regeneration";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
			HudMessage(s:"Health Regeneration Perk. Heals 1 Health every 2 seconds up to 100 Health.";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
			HudMessage(s:"Price: 15 Credits";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
			Break;
		}
		Case(1):
		{
			HudMessage(s:"Upgrade Perk: Health Regeneration";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
			HudMessage(s:"Upgrade to: Heal 1 Health every second up to 100 Health.";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
			HudMessage(s:"Price: 20 Credits";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
			Break;
		}
		Case(2):
		{
			HudMessage(s:"Upgrade Perk: Health Regeneration";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
			HudMessage(s:"Upgrade to: Heal 2 Health every second up to 100 Health.";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
			HudMessage(s:"Price: 25 Credits";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
			Break;
		}
		Case(3):
		{
			HudMessage(s:"Health Regeneration Perk is already fully upgraded!";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
			//Clears any remaining messages
			HudMessage(s:"";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
			HudMessage(s:"";
			HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
			Break;
		}
	}
}

Script 1301 (void)
{
	if(CheckInventory("Credits") >= 15 && CheckInventory("HealthRegenPerk") <= 0)
	{
		TakeInventory("Credits",15);
		GiveInventory("HealthRegenPerk",1);
		PlaySound(0,"Health1"); //SFX
		ClearDisplay();
		print(s:"Perk Purchased!");
	}
	else if(CheckInventory("Credits") < 15 && CheckInventory("HealthRegenPerk") <= 0)
	{
		print(s:"Not enough credits.");
	}
	else if(CheckInventory("Credits") >= 20 && CheckInventory("HealthRegenPerk") == 1)
	{
		TakeInventory("Credits",20);
		GiveInventory("HealthRegenPerk",1);
		PlaySound(0,"Health1"); //SFX
		ClearDisplay();
		print(s:"Perk Upgraded!");
	}
	else if(CheckInventory("Credits") < 20 && CheckInventory("HealthRegenPerk") == 1)
	{
		print(s:"Not enough credits.");
	}
	else if(CheckInventory("Credits") >= 25 && CheckInventory("HealthRegenPerk") == 2)
	{
		TakeInventory("Credits",25);
		GiveInventory("HealthRegenPerk",1);
		PlaySound(0,"Health1"); //SFX
		ClearDisplay();
		print(s:"Perk Upgraded!");
	}
	else if(CheckInventory("Credits") < 25 && CheckInventory("HealthRegenPerk") == 2)
	{
		print(s:"Not enough credits.");
	}
}

Script 1302 OPEN //Health Regen Logic
{
	//Variable Control
	HealthVariables();

	//Display Logic
	p1healthregen = CheckActorInventory(888,"HealthRegenPerk");
	if (p1healthregen >= 1)
	{
		SetActivator(888);
		HudMessage(s:"+Health Regen ",d:p1healthregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 130, "Blue", 0.05, 0.15, 999999);
	}
	else //clear if no perk
	{
		SetActivator(888);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 130, "Blue", 0.05, 0.15, 999999);
	}
	p2healthregen = CheckActorInventory(889,"HealthRegenPerk");
	if (p2healthregen >= 1)
	{
		SetActivator(889);
		HudMessage(s:"+Health Regen ",d:p2healthregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 230, "Blue", 0.05, 0.15, 999999);
	}
	else //clear if no perk
	{
		SetActivator(889);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 230, "Blue", 0.05, 0.15, 999999);
	}
	p3healthregen = CheckActorInventory(890,"HealthRegenPerk");
	if (p3healthregen >= 1)
	{
		SetActivator(890);
		HudMessage(s:"+Health Regen ",d:p3healthregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 330, "Blue", 0.05, 0.15, 999999);
	}
	else //clear if no perk
	{
		SetActivator(890);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 330, "Blue", 0.05, 0.15, 999999);
	}
	p4healthregen = CheckActorInventory(891,"HealthRegenPerk");
	if (p4healthregen >= 1)
	{
		SetActivator(891);
		HudMessage(s:"+Health Regen ",d:p4healthregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 430, "Blue", 0.05, 0.15, 999999);
	}
	else //clear if no perk
	{
		SetActivator(891);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 430, "Blue", 0.05, 0.15, 999999);
	}

Delay(5);
restart;
}

Script "2second" OPEN
{
	//Variable Control
	HealthVariables();

	//HEALTH REGEN
	GetSourceport(); //Check source port
	if(sourceport == "ZDoom")
	{
		//Player 1
		SetActivator(888);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
		//Player 2
		SetActivator(889);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
		//Player 3
		SetActivator(890);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
		//Player 4
		SetActivator(891);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
	}
	if(sourceport == "Zandronum") //ZANDRONUM
	{
		//Player 1
		SetActivator(888);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
		//Player 2
		SetActivator(889);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
		//Player 3
		SetActivator(890);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
		//Player 4
		SetActivator(891);
		if(CheckInventory("HealthRegenPerk") == 1)
		{
			GiveInventory("Medikit",1);
		}
	}
	
	//ARMOR REGEN
	//Player 1
	SetActivator(888);
	if(CheckInventory("ArmorRegenPerk") == 1)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 2
	SetActivator(889);
	if(CheckInventory("ArmorRegenPerk") == 1)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 3
	SetActivator(890);
	if(CheckInventory("ArmorRegenPerk") == 1)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 4
	SetActivator(891);
	if(CheckInventory("ArmorRegenPerk") == 1)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}

	Delay(70);
	Restart;
}

Script "1second" OPEN
{
	//Variable Control
	HealthVariables();

	GetSourceport(); //Check source port
	if(sourceport == "ZDoom")
	{
		//Player 1
		SetActivator(888);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
		//Player 2
		SetActivator(889);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
		//Player 3
		SetActivator(890);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
		//Player 4
		SetActivator(891);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
	}
	if(sourceport == "Zandronum") //ZANDRONUM
	{
		//Player 1
		SetActivator(888);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
		//Player 2
		SetActivator(889);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
		//Player 3
		SetActivator(890);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
		//Player 4
		SetActivator(891);
		if(CheckInventory("HealthRegenPerk") == 2)
		{
			GiveInventory("Medikit",1);
		}
	}
	
	//ARMOR REGEN
	//Player 1
	SetActivator(888);
	if(CheckInventory("ArmorRegenPerk") == 2)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 2
	SetActivator(889);
	if(CheckInventory("ArmorRegenPerk") == 2)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 3
	SetActivator(890);
	if(CheckInventory("ArmorRegenPerk") == 2)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 4
	SetActivator(891);
	if(CheckInventory("ArmorRegenPerk") == 2)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}

	Delay(35);
	Restart;
}

Script "1/2second" OPEN
{
	//Variable Control
	HealthVariables();

	GetSourceport(); //Check source port
	if(sourceport == "ZDoom")
	{
		//Player 1
		SetActivator(888);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
		//Player 2
		SetActivator(889);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
		//Player 3
		SetActivator(890);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
		//Player 4
		SetActivator(891);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
	}
	if(sourceport == "Zandronum") //ZANDRONUM
	{
		//Player 1
		SetActivator(888);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
		//Player 2
		SetActivator(889);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
		//Player 3
		SetActivator(890);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
		//Player 4
		SetActivator(891);
		if(CheckInventory("HealthRegenPerk") >= 3)
		{
			GiveInventory("Medikit",1);
		}
	}

	//ARMOR REGEN
	//Player 1
	SetActivator(888);
	if(CheckInventory("ArmorRegenPerk") == 3)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 2
	SetActivator(889);
	if(CheckInventory("ArmorRegenPerk") == 3)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 3
	SetActivator(890);
	if(CheckInventory("ArmorRegenPerk") == 3)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}
	//Player 4
	SetActivator(891);
	if(CheckInventory("ArmorRegenPerk") == 3)
	{
		if(GetArmorType("RedArmor",PlayerNumber()))
		{
			GiveInventory("RedArmorBonus",1);
		}
		else
		{
			GiveInventory("ArmorBonus",1);
		}
	}

	Delay(17);
	Restart;
}


//Armor Regeneration
Script 1303 (void)
{

	if(CheckInventory("ArmorRegenPerk") <= 0)
	{
		HudMessage(s:"Perk: Armor Regeneration";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Armor Regeneration Perk. Gain 1 Armor every 2 seconds.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: 15 Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}

	else if(CheckInventory("ArmorRegenPerk") == 1)
	{
		HudMessage(s:"Upgrade Perk: Armor Regeneration";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Upgrade to: Gain 1 Armor every second.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: 20 Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}
	else if(CheckInventory("ArmorRegenPerk") == 2)
	{
		HudMessage(s:"Upgrade Perk: Armor Regeneration";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Upgrade to: Gain 2 Armor every second.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: 25 Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}
	else if(CheckInventory("ArmorRegenPerk") >= 3)
	{
		HudMessage(s:"Armor Regeneration Perk is already fully upgraded!";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		//Clears any remaining messages
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}

}

Script 1304 (void)
{

	if(CheckInventory("Credits") >= 15 && CheckInventory("ArmorRegenPerk") <= 0)
	{
		TakeInventory("Credits",15);
		GiveInventory("ArmorRegenPerk",1);
		PlaySound(0,"Armor1"); //SFX
		print(s:"Perk Purchased!");
	}

	else if(CheckInventory("Credits") < 15 && CheckInventory("ArmorRegenPerk") <= 0)
	{
		print(s:"Not enough credits.");
	}

	else if(CheckInventory("Credits") >= 20 && CheckInventory("ArmorRegenPerk") == 1)
	{
		TakeInventory("Credits",20);
		GiveInventory("ArmorRegenPerk",1);
		PlaySound(0,"Armor1"); //SFX
		print(s:"Perk Upgraded!");
	}

	else if(CheckInventory("Credits") < 20 && CheckInventory("ArmorRegenPerk") == 1)
	{
		print(s:"Not enough credits.");
	}
	else if(CheckInventory("Credits") >= 25 && CheckInventory("ArmorRegenPerk") == 2)
	{
		TakeInventory("Credits",25);
		GiveInventory("ArmorRegenPerk",1);
		PlaySound(0,"Armor1"); //SFX
		print(s:"Perk Upgraded!");
	}

	else if(CheckInventory("Credits") < 25 && CheckInventory("ArmorRegenPerk") == 2)
	{
		print(s:"Not enough credits.");
	}

}

Script 1305 OPEN //Armor Regen Logic
{
	//Display Logic
	p1armorregen = CheckActorInventory(888,"ArmorRegenPerk");
	if (p1armorregen >= 1)
	{
		SetActivator(888);
		HudMessage(s:"+Armor Regen ",d:p1armorregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 191, "Green", 0.05, 0.20, 999999);
	}
	else //clear if no perk
	{
		SetActivator(888);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 191, "Green", 0.05, 0.20, 999999);
	}
	p2armorregen = CheckActorInventory(889,"ArmorRegenPerk");
	if (p2armorregen >= 1)
	{
		SetActivator(889);
		HudMessage(s:"+Armor Regen ",d:p2armorregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 291, "Green", 0.05, 0.20, 999999);
	}
	else //clear if no perk
	{
		SetActivator(889);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 291, "Green", 0.05, 0.20, 999999);
	}
	p3armorregen = CheckActorInventory(890,"HealthRegenPerk");
	if (p3armorregen >= 1)
	{
		SetActivator(890);
		HudMessage(s:"+Armor Regen ",d:p3armorregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 391, "Green", 0.05, 0.20, 999999);
	}
	else //clear if no perk
	{
		SetActivator(890);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 391, "Green", 0.05, 0.20, 999999);
	}
	p4armorregen = CheckActorInventory(891,"HealthRegenPerk");
	if (p4armorregen >= 1)
	{
		SetActivator(891);
		HudMessage(s:"+Armor Regen ",d:p4armorregen;
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 491, "Green", 0.05, 0.20, 999999);
	}
	else //clear if no perk
	{
		SetActivator(891);
		HudMessage(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 491, "Green", 0.05, 0.20, 999999);
	}

Delay(5);
restart;
}

//EXTRA LIFE PERK
Script 1306 (void)
{
	if(CheckInventory("ExtraLifePerk") <= 1 && PlayerNumber() == 0) //Buy info display, and individualized buy prices
	{
		HudMessage(s:"Perk: Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Invulnerablility and full health after taking a deadly blow.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: ",d:p1revivesprice ,s:" Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}
	else if(CheckInventory("ExtraLifePerk") <= 1 && PlayerNumber() == 1)
	{
		HudMessage(s:"Perk: Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Invulnerablility and full health after taking a deadly blow.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: ",d:p2revivesprice ,s:" Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}
	else if(CheckInventory("ExtraLifePerk") <= 1 && PlayerNumber() == 2)
	{
		HudMessage(s:"Perk: Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Invulnerablility and full health after taking a deadly blow.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: ",d:p3revivesprice ,s:" Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}
	else if(CheckInventory("ExtraLifePerk") <= 1 && PlayerNumber() == 3)
	{
		HudMessage(s:"Perk: Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
		HudMessage(s:"Invulnerablility and full health after taking a deadly blow.";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
		HudMessage(s:"Price: ",d:p4revivesprice ,s:" Credits";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	}
	else if(CheckInventory("ExtraLifePerk") >= 1)
	{
		print(s:"You already have an extra life.");
	}

}

Script 1307 (void) //Buy Extra Life
{
	Switch(PlayerNumber())
	{
		Case(0):
		{
			if(CheckInventory("Credits") >= p1revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				TakeInventory("Credits",p1revivesprice);
				GiveInventory("ExtraLifePerk",1);
				p1revivesprice += 10;
				PlaySound(0,"Armor1"); //SFX
				print(s:"Perk Purchased!");
				weaponsbought++;
			}
			else if(CheckInventory("Credits") >= p1revivesprice && CheckInventory("ExtraLifePerk") >= 0)
			{
				ClearDisplay();
				print(s:"You already have this perk!");
			}
			else if(CheckInventory("Credits") <= p1revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				print(s:"You don't have enough credits!");
			}
			Break;
		}
		Case(1): //Player 2
		{
			if(CheckInventory("Credits") >= p2revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				TakeInventory("Credits",p2revivesprice);
				GiveInventory("ExtraLifePerk",1);
				p2revivesprice += 10;
				print(s:"Perk Purchased!");
				weaponsbought++;
			}
			else if(CheckInventory("Credits") >= p2revivesprice && CheckInventory("ExtraLifePerk") >= 0)
			{
				ClearDisplay();
				print(s:"You already have this perk!");
			}
			else if(CheckInventory("Credits") <= p2revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				print(s:"You don't have enough credits!");
			}
			Break;
		}
		Case(2): //Player 3
		{
			if(CheckInventory("Credits") >= p3revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				TakeInventory("Credits",p3revivesprice);
				GiveInventory("ExtraLifePerk",1);
				p3revivesprice += 10;
				print(s:"Perk Purchased!");
				weaponsbought++;
			}
			else if(CheckInventory("Credits") >= p3revivesprice && CheckInventory("ExtraLifePerk") >= 0)
			{
				ClearDisplay();
				print(s:"You already have this perk!");
			}
			else if(CheckInventory("Credits") <= p3revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				print(s:"You don't have enough credits!");
			}
			Break;
		}
		Case(3): //Player 4
		{
			if(CheckInventory("Credits") >= p4revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				TakeInventory("Credits",p4revivesprice);
				GiveInventory("ExtraLifePerk",1);
				p4revivesprice += 10;
				print(s:"Perk Purchased!");
				weaponsbought++;
			}
			else if(CheckInventory("Credits") >= p4revivesprice && CheckInventory("ExtraLifePerk") >= 0)
			{
				ClearDisplay();
				print(s:"You already have this perk!");
			}
			else if(CheckInventory("Credits") <= p4revivesprice && CheckInventory("ExtraLifePerk") <= 0)
			{
				ClearDisplay();
				print(s:"You don't have enough credits!");
			}
			Break;
		}
	}
}

Script 1308 OPEN //Revive Logic
{
	//Variable Control
	p1health = GetActorProperty(888, APROP_Health);
	p2health = GetActorProperty(889, APROP_Health);
	p3health = GetActorProperty(890, APROP_Health);
	p4health = GetActorProperty(891, APROP_Health);
	p1revive = CheckActorInventory(888,"ExtraLifePerk");
	p2revive = CheckActorInventory(889,"ExtraLifePerk");
	p3revive = CheckActorInventory(890,"ExtraLifePerk");
	p4revive = CheckActorInventory(891,"ExtraLifePerk");

	//PLAYER 1
	if(p1revive >= 1 && p1health >= 2)
	{
		SetActivator(888);
		SetPlayerProperty (0,1,PROP_BUDDHA); //Give Buddha
	}
	else if(p1revive >= 1 && p1health <= 1)
	{
		SetActivator(888);
		Print(s:"Extra Life Activated");
		SetActorProperty(888,APROP_Health,100);
		SetPlayerProperty(0,0,PROP_BUDDHA); //Disable Buddha
		GiveActorInventory(888,"ExtraLifeInvuln",1); //Give the Invuln Powerup

		HudMessageBold(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.05, 0.25, 999); //clears display

		TakeActorInventory(888,"ExtraLifePerk",1);
	}
	
	//PLAYER 2
	if(p2revive >= 1 && p2health >= 2)
	{
		SetActivator(889);
		SetPlayerProperty (0,1,PROP_BUDDHA); //Give Buddha
	}
	else if(p2revive >= 1 && p2health <= 1)
	{
		SetActivator(889);
		Print(s:"Extra Life Activated");
		SetActorProperty(889, APROP_Health, 100);
		SetPlayerProperty (0,0,PROP_BUDDHA); //Disable Buddha
		GiveActorInventory(889,"ExtraLifeInvuln",1); //Give the Invuln Powerup

		HudMessageBold(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.05, 0.25, 999); //clears display

		TakeActorInventory(889,"ExtraLifePerk",1);
	}
	
	//PLAYER 3
	if(p3revive >= 1 && p3health >= 2)
	{
		SetActivator(890);
		SetPlayerProperty (0,1,PROP_BUDDHA);
	}
	else if(p3revive >= 1 && p3health <= 1)
	{
		SetActivator(890);
		Print(s:"Extra Life Activated");
		SetActorProperty(890, APROP_Health, 100);
		SetPlayerProperty (0,0,PROP_BUDDHA); //Disable Buddha
		GiveActorInventory(890,"ExtraLifeInvuln",1); //Give the Invuln Powerup

		HudMessageBold(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.05, 0.25, 999); //clears display

		TakeActorInventory(890,"ExtraLifePerk",1);
	}
	
	//PLAYER 4
	if(p4revive >= 1 && p4health >= 2)
	{
		SetActivator(891);
		SetPlayerProperty (0,1,PROP_BUDDHA);
	}
	else if(p4revive >= 1 && p4health <= 1)
	{
		SetActivator(891);
		Print(s:"Extra Life Activated");
		SetActorProperty(891, APROP_Health, 100);
		SetPlayerProperty (0,0,PROP_BUDDHA); //Disable Buddha
		GiveActorInventory(891,"ExtraLifeInvuln",1); //Give the Invuln Powerup

		HudMessageBold(s:"";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.05, 0.25, 999); //clears display

		TakeActorInventory(891,"ExtraLifePerk",1);
	}

	Delay(2);
	Restart;
}

Script 1309 OPEN //Extra Life Display
{
	p1revive = CheckActorInventory(888,"ExtraLifePerk");
	p2revive = CheckActorInventory(889,"ExtraLifePerk");
	p3revive = CheckActorInventory(890,"ExtraLifePerk");
	p4revive = CheckActorInventory(891,"ExtraLifePerk");
	if (p1revive >= 1)
	{
		SetActivator(888);
		HudMessage(s:"+Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.04, 0.25, 999);
	}
	if (p2revive >= 1)
	{
		SetActivator(889);
		HudMessage(s:"+Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.04, 0.25, 999);
	}
	if (p3revive >= 1)
	{
		SetActivator(890);
		HudMessage(s:"+Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.04, 0.25, 999);
	}
	if (p4revive >= 1)
	{
		SetActivator(891);
		HudMessage(s:"+Extra Life";
		HUDMSG_PLAIN | HUDMSG_COLORSTRING, 135, "Gold", 0.04, 0.25, 999);
	}

Delay(5);
Restart;
}

/////////////////
//Weapon Enhancer
/////////////////

Script 2000 (void)
{
str weapon = GetWeapon();

	//Enhanced
	If(StrIcmp(weapon, "Pistol") == 0)
	{
		print(s:"Enhance Pistol. +Accuracy, +Massive Damage, +Firerate. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "Shotgun") == 0)
	{
		print(s:"Enhance Shotgun. +Accuracy, +Damage, +Firerate. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "Chaingun") == 0)
	{
		print(s:"Enhance Chaingun. +Accuracy, +Damage, +Firerate. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "SuperShotgun") == 0)
	{
		print(s:"Enhance Super Shotgun. +Damage, +Firerate. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "RocketLauncher") == 0)
	{
		print(s:"Enhance Rocket Launcher. +Damage, +Firerate +Speed +Radius. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "PlasmaRifle") == 0)
	{
		print(s:"Enhance Plasma Rifle. +Damage, +Firerate, +Speed Price: 40 credits.");
	}
	If(StrIcmp(weapon, "BFG9000") == 0)
	{
		print(s:"Enhance BFG9000. +Damage. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "Chainsaw") == 0)
	{
		print(s:"Enhance Chainsaw. +Damage. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "AutoRifle") == 0)
	{
		print(s:"Enhance The Auto Rifle. +Near Perfect Accuracy, +Damage, +Firerate. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "GrenadeLauncher") == 0)
	{
		print(s:"Enhance Grenade Launcher. +1 Extra Grenade Per Shot, +Direct Hit Damage. Price: 40 credits.");
	}
	If(StrIcmp(weapon, "AutoShotgun") == 0)
	{
		print(s:"Enhance Auto Shotgun. +Accuracy, +Damage, +Firerate. Price: 40 credits.");
	}
	
	//Perfected
	If(StrIcmp(weapon, "EnhancedPistol") == 0)
	{
		print(s:"Perfect Pistol. +Massive Damage, +Ammo Cost. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedChaingun") == 0)
	{
		print(s:"Perfect Chaingun. +Accuracy, +Damage, +Firerate. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedSuperShotgun") == 0)
	{
		print(s:"Perfect Super Shotgun. +Accuracy, +Massive Damage, +Ammo Cost. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedRocketLauncher") == 0)
	{
		print(s:"Perfect Rocket Launcher. +Damage, +Blast Damage, +Fire Rate. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedPlasmaRifle") == 0)
	{
		print(s:"Perfect Plasma Rifle. x3 Projectiles, +Damage, +Ammo Cost. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedBFG9000") == 0)
	{
		print(s:"Perfect BFG9000. +Massive Damage, +Railgun. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedAutoShotgun") == 0)
	{
		print(s:"Perfect Auto Shotgun. +Damage, +Accuracy, +Fire Rate Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedAutoRifle") == 0)
	{
		print(s:"Perfect Auto Rifle. +Damage. Price: 200 credits.");
	}
	If(StrIcmp(weapon, "EnhancedGrenadeLauncher") == 0)
	{
		print(s:"Perfect Grenade Launcher. +2 Extra Free Grenades Per Shot, +Direct Hit Damage. Price: 200 credits.");
	}
}

Script 2001 (void)
{

str weapon = GetWeapon();
		
		//Perfected Pistol
		If(StrIcmp(weapon, "EnhancedPistol") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Pistol Perfected!");
			GiveInventory("PerfectedPistol",1);
			SetWeapon("PerfectedPistol");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedPistol",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedPistol") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Chaingun
		If(StrIcmp(weapon, "EnhancedChaingun") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Chaingun Perfected!");
			GiveInventory("PerfectedChaingun",1);
			SetWeapon("PerfectedChaingun");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedChaingun",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedChaingun") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Super Shotgun
		If(StrIcmp(weapon, "EnhancedSuperShotgun") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Super Shotgun Perfected!");
			GiveInventory("PerfectedSuperShotgun",1);
			SetWeapon("PerfectedSuperShotgun");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedSuperShotgun",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedSuperShotgun") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Rocket Launcher
		If(StrIcmp(weapon, "EnhancedRocketLauncher") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Rocket Launcher Perfected!");
			GiveInventory("PerfectedRocketLauncher",1);
			SetWeapon("PerfectedRocketLauncher");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedRocketLauncher",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedRocketLauncher") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Plasma Rifle
		If(StrIcmp(weapon, "EnhancedPlasmaRifle") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Plasma Rifle Perfected!");
			GiveInventory("PerfectedPlasmaRifle",1);
			SetWeapon("PerfectedPlasmaRifle");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedPlasmaRifle",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedPlasmaRifle") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected BFG 9000
		If(StrIcmp(weapon, "EnhancedBFG9000") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"BFG9000 Perfected!");
			GiveInventory("PerfectedBFG9000",1);
			SetWeapon("PerfectedBFG9000");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedBFG9000",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedBFG9000") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Auto Shotgun
		If(StrIcmp(weapon, "EnhancedAutoShotgun") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Auto Shotgun Perfected!");
			GiveInventory("PerfectedAutoShotgun",1);
			SetWeapon("PerfectedAutoShotgun");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedAutoShotgun",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedAutoShotgun") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Auto Rifle
		If(StrIcmp(weapon, "EnhancedAutoRifle") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Auto Rifle Perfected!");
			GiveInventory("PerfectedAutoRifle",1);
			SetWeapon("PerfectedAutoRifle");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedAutoRifle",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedAutoRifle") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}
		//Perfected Grenade Launcher
		If(StrIcmp(weapon, "EnhancedGrenadeLauncher") == 0 && CheckInventory("Credits") >= 200)
		{
			print(s:"Grenade Launcher Perfected!");
			GiveInventory("PerfectedGrenadeLauncher",1);
			SetWeapon("PerfectedGrenadeLauncher");
			TakeInventory("Credits",200);
			TakeInventory("EnhancedGrenadeLauncher",1);
			weaponsbought += 5;
		}
		else If(StrIcmp(weapon, "EnhancedGrenadeLauncher") == 0 && CheckInventory("Credits") < 200)
		{
			print(s:"Not enough credits to perfect weapon.");
		}

		//Enhanced
		else If(StrIcmp(weapon, "Pistol") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Pistol Enhanced!");
			GiveInventory("EnhancedPistol",1);
			SetWeapon("EnhancedPistol");
			TakeInventory("Credits",40);
			TakeInventory("Pistol",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "Shotgun") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Shotgun Enhanced!");
			GiveInventory("EnhancedShotgun",1);
			SetWeapon("EnhancedShotgun");
			TakeInventory("Credits",40);
			TakeInventory("Shotgun",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "Chaingun") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Chaingun Enhanced!");
			GiveInventory("EnhancedChaingun",1);
			SetWeapon("EnhancedChaingun");
			TakeInventory("Credits",40);
			TakeInventory("Chaingun",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "SuperShotgun") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Super Shotgun Enhanced!");
			GiveInventory("EnhancedSuperShotgun",1);
			SetWeapon("EnhancedSuperShotgun");
			TakeInventory("Credits",40);
			TakeInventory("SuperShotgun",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "RocketLauncher") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Rocket Launcher Enhanced!");
			GiveInventory("EnhancedRocketLauncher",1);
			SetWeapon("EnhancedRocketLauncher");
			TakeInventory("Credits",40);
			TakeInventory("RocketLauncher",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "PlasmaRifle") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Plasma Rifle Enhanced!");
			GiveInventory("EnhancedPlasmaRifle",1);
			SetWeapon("EnhancedPlasmaRifle");
			TakeInventory("Credits",40);
			TakeInventory("PlasmaRifle",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "BFG9000") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"BFG9000 Enhanced!");
			GiveInventory("EnhancedBFG9000",1);
			SetWeapon("EnhancedBFG9000");
			TakeInventory("Credits",40);
			TakeInventory("BFG9000",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "Chainsaw") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Chainsaw Enhanced!");
			GiveInventory("EnhancedChainsaw",1);
			SetWeapon("EnhancedChainsaw");
			TakeInventory("Credits",40);
			TakeInventory("Chainsaw",1);
			weaponsbought++;
		}

		else If(StrIcmp(weapon, "AutoRifle") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Auto Rifle Enhanced!");
			GiveInventory("EnhancedAutoRifle",1);
			SetWeapon("EnhancedAutoRifle");
			TakeInventory("Credits",40);
			TakeInventory("AutoRifle",1);
			weaponsbought++;
		}
		
		else If(StrIcmp(weapon, "GrenadeLauncher") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Grenade Launcher Enhanced!");
			GiveInventory("EnhancedGrenadeLauncher",1);
			SetWeapon("EnhancedGrenadeLauncher");
			TakeInventory("Credits",40);
			TakeInventory("GrenadeLauncher",1);
			weaponsbought++;
		}
		
		else If(StrIcmp(weapon, "AutoShotgun") == 0 && CheckInventory("Credits") >= 40)
		{
			print(s:"Auto Shotgun Enhanced!");
			GiveInventory("EnhancedAutoShotgun",1);
			SetWeapon("EnhancedAutoShotgun");
			TakeInventory("Credits",40);
			TakeInventory("AutoShotgun",1);
			weaponsbought++;
		}
		
		else if(CheckInventory("Credits") < 40)
		{
			print(s:"Not enough credits to enhance weapon.");
		}

}

Script 2002 OPEN //Weapon held logic
{
	for(int playeriter = 887; playeriter <892; playeriter++) //Go through players 1-4 and set their HoldingWeapon item to match what they are using
	{
		SetActivator(888);
		ClearWeaponHeld();
		str weapon = GetWeapon();
		
		if(StrIcmp(weapon, "Fist") == 0) GiveInventory("HoldingFist",1);
		if(StrIcmp(weapon, "Pistol") == 0) GiveInventory("HoldingPistol",1);
		if(StrIcmp(weapon, "Shotgun") == 0) GiveInventory("HoldingShotgun",1);
		if(StrIcmp(weapon, "SuperShotgun") == 0) GiveInventory("HoldingSuperShotgun",1);
		if(StrIcmp(weapon, "Chaingun") == 0) GiveInventory("HoldingChaingun",1);
		if(StrIcmp(weapon, "RocketLauncher") == 0) GiveInventory("HoldingRocketLauncher",1);
		if(StrIcmp(weapon, "PlasmaRifle") == 0) GiveInventory("HoldingPlasmaRifle",1);
		if(StrIcmp(weapon, "BFG") == 0) GiveInventory("HoldingBFG",1);
		if(StrIcmp(weapon, "Chainsaw") == 0) GiveInventory("HoldingChainsaw",1);
		if(StrIcmp(weapon, "AutoRifle") == 0) GiveInventory("HoldingAutoRifle",1);
		if(StrIcmp(weapon, "AutoShotgun") == 0) GiveInventory("HoldingAutoShotgun",1);
		if(StrIcmp(weapon, "GrenadeLauncher") == 0) GiveInventory("HoldingGrenadeLauncher",1);
	}
	
Delay(35);
Restart;
}


Script 8000 OPEN //Supply Caches
{
	if(supplytimerset == false)
	{
		supplytimerequired = random(240,360);
		supplytimerset = true;
		supplylocation = supplylocationlist[random(1,7)];
	}

	if(supplytimer >= supplytimerequired)
	{
		HudMessageBold(s:"A SUPPLY CACHE HAS BEEN DETECTED.";
		HUDMSG_TYPEON | HUDMSG_COLORSTRING, 102, "WHITE", 0.5, 0.15, 400000);

		Thing_SpawnFacing(supplylocation, 212, 0, 0); //Spawn supplies on a random spot between spots 25-31.

		supplytimer = 0;
		supplytimerset = false;
	}

supplytimer += 1;
delay(35);
restart;
}

//511 = Spawner ID, 34 = MapSpot Tag

Script "SpawnAnomaly" OPEN
{
	if(anomalytimerset == false)
	{
		anomalytimerequired = random(340,420);
		anomalytimerequired -= hellonearthdelay*10;
		if(anomalytimerequired < 30) anomalytimerequired = 30;
		//anomalytimerequired = 10; //debug
		anomalytimerset = true;
		anomalylocation = anomalylocationlist[random(1,4)];
	}

	if(anomalytimer >= anomalytimerequired)
	{
		HudMessageBold(s:"AN ANOMALY HAS BEEN DETECTED";
		HUDMSG_TYPEON | HUDMSG_COLORSTRING, 102, "BLACK", 0.5, 0.20, 400000);

			if(GetLevelInfo(LEVELINFO_LEVELNUM) == 1) //Facility
			{
				Thing_SpawnFacing(anomalylocation, 211, 0, 0);
			}
			else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 2) //Citadel
			{
				Thing_SpawnFacing(anomalylocation, 214, 0, 0);
			}
			else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 3) //Corrupt
			{
				Thing_SpawnFacing(anomalylocation, 211, 0, 0);
			}
			else if(GetLevelInfo(LEVELINFO_LEVELNUM) == 4) //Abyss
			{
				Thing_SpawnFacing(anomalylocation, 214, 0, 0);
			}
			

		anomalytimer = 0;
		anomalytimerset = false;
	}

anomalytimer += 1;
delay(35);
restart;
}

Script 8001 (void)
{
	Print(s:"Equipment Fabricator. Creates a random item. Price: 15 credits.");
}

Script 8002 (void) //Fabricator
{
	if(CheckInventory("Credits") >= 15)
	{
		TakeInventory("Credits",15);
		Thing_SpawnFacing(32, 213, 0, 0);
		print(s:"Item Fabricated!");
	}

	else if(CheckInventory("Credits") < 15)
	{
		print(s:"Not enough credits to use fabricator.");
	}

}
//Debug Scripts
Script 9999 (void)
{
	print(s:"Debug: Difficulty 8");
	difficulty = 8;
}
Script "DebugDif10" (void)
{
	print(s:"Debug: Difficulty 10");
	HellOnEarthDelay = 1;
	difficulty = 10;
}
Script "DebugDif20" (void)
{
	print(s:"Debug: Difficulty 20");
	HellOnEarthDelay = 11;
	difficulty = 20;
}
Script "DebugDif50" (void)
{
	print(s:"Debug: Difficulty 50");
	HellOnEarthDelay = 41;
	difficulty = 50;
}

Script 10000 OPEN //Prevents the player from having an enhanced and normal version of a weapon at the same time.
{ //Ugliest code of all time but it works and I'm scared to touch it
//Player 1
	if (CheckActorInventory(888,"EnhancedPistol") == 1)
	{
		TakeActorInventory(888,"Pistol",1);
	}
	if (CheckActorInventory(888,"EnhancedShotgun") == 1)
	{
		TakeActorInventory(888,"Shotgun",1);
	}
	if (CheckActorInventory(888,"EnhancedChaingun") == 1)
	{
		TakeActorInventory(888,"Chaingun",1);
	}
	if (CheckActorInventory(888,"EnhancedSuperShotgun") == 1)
	{
		TakeActorInventory(888,"SuperShotgun",1);
	}
	if (CheckActorInventory(888,"EnhancedRocketLauncher") == 1)
	{
		TakeActorInventory(888,"RocketLauncher",1);
	}
	if (CheckActorInventory(888,"EnhancedPlasmaRifle") == 1)
	{
		TakeActorInventory(888,"PlasmaRifle",1);
	}
	if (CheckActorInventory(888,"EnhancedBFG9000") == 1)
	{
		TakeActorInventory(888,"BFG9000",1);
	}
	if (CheckActorInventory(888,"EnhancedAutoRifle") == 1)
	{
		TakeActorInventory(888,"AutoRifle",1);
	}
	if (CheckActorInventory(888,"EnhancedChainsaw") == 1)
	{
		TakeActorInventory(888,"Chainsaw",1);
	}
	if (CheckActorInventory(888,"EnhancedGrenadeLauncher") == 1)
	{
		TakeActorInventory(888,"GrenadeLauncher",1);
	}
	if (CheckActorInventory(888,"EnhancedAutoShotgun") == 1)
	{
		TakeActorInventory(888,"AutoShotgun",1);
	}
	//Perfected
	if (CheckActorInventory(888,"PerfectedPistol") == 1)
	{
		TakeActorInventory(888,"EnhancedPistol",1);
		TakeActorInventory(888,"Pistol",1);
	}
	if (CheckActorInventory(888,"PerfectedChaingun") == 1)
	{
		TakeActorInventory(888,"EnhancedChaingun",1);
		TakeActorInventory(888,"Chaingun",1);
	}
	if (CheckActorInventory(888,"PerfectedSuperShotgun") == 1)
	{
		TakeActorInventory(888,"EnhancedSuperShotgun",1);
		TakeActorInventory(888,"SuperShotgun",1);
	}
	if (CheckActorInventory(888,"PerfectedRocketLauncher") == 1)
	{
		TakeActorInventory(888,"EnhancedRocketLauncher",1);
		TakeActorInventory(888,"RocketLauncher",1);
	}
	if (CheckActorInventory(888,"PerfectedPlasmaRifle") == 1)
	{
		TakeActorInventory(888,"EnhancedPlasmaRifle",1);
		TakeActorInventory(888,"PlasmaRifle",1);
	}
	if (CheckActorInventory(888,"PerfectedBFG9000") == 1)
	{
		TakeActorInventory(888,"EnhancedBFG9000",1);
		TakeActorInventory(888,"BFG9000",1);
	}
	if (CheckActorInventory(888,"PerfectedAutoRifle") == 1)
	{
		TakeActorInventory(888,"EnhancedAutoRifle",1);
		TakeActorInventory(888,"AutoRifle",1);
	}
	if (CheckActorInventory(888,"PerfectedAutoShotgun") == 1)
	{
		TakeActorInventory(888,"EnhancedAutoShotgun",1);
		TakeActorInventory(888,"AutoShotgun",1);
	}
//Player 2
	if (CheckActorInventory(889,"EnhancedPistol") == 1)
	{
		TakeActorInventory(889,"Pistol",1);
	}
	if (CheckActorInventory(889,"EnhancedShotgun") == 1)
	{
		TakeActorInventory(889,"Shotgun",1);
	}
	if (CheckActorInventory(889,"EnhancedChaingun") == 1)
	{
		TakeActorInventory(889,"Chaingun",1);
	}
	if (CheckActorInventory(889,"EnhancedSuperShotgun") == 1)
	{
		TakeActorInventory(889,"SuperShotgun",1);
	}
	if (CheckActorInventory(889,"EnhancedRocketLauncher") == 1)
	{
		TakeActorInventory(889,"RocketLauncher",1);
	}
	if (CheckActorInventory(889,"EnhancedPlasmaRifle") == 1)
	{
		TakeActorInventory(889,"PlasmaRifle",1);
	}
	if (CheckActorInventory(889,"EnhancedBFG9000") == 1)
	{
		TakeActorInventory(889,"BFG9000",1);
	}
	if (CheckActorInventory(889,"EnhancedAutoRifle") == 1)
	{
		TakeActorInventory(889,"AutoRifle",1);
	}
	if (CheckActorInventory(889,"EnhancedChainsaw") == 1)
	{
		TakeActorInventory(889,"Chainsaw",1);
	}
	if (CheckActorInventory(889,"EnhancedGrenadeLauncher") == 1)
	{
		TakeActorInventory(889,"GrenadeLauncher",1);
	}
	if (CheckActorInventory(889,"EnhancedAutoShotgun") == 1)
	{
		TakeActorInventory(889,"AutoShotgun",1);
	}
	//Perfected
	if (CheckActorInventory(889,"PerfectedPistol") == 1)
	{
		TakeActorInventory(889,"EnhancedPistol",1);
		TakeActorInventory(889,"Pistol",1);
	}
	if (CheckActorInventory(889,"PerfectedChaingun") == 1)
	{
		TakeActorInventory(889,"EnhancedChaingun",1);
		TakeActorInventory(889,"Chaingun",1);
	}
	if (CheckActorInventory(889,"PerfectedSuperShotgun") == 1)
	{
		TakeActorInventory(889,"EnhancedSuperShotgun",1);
		TakeActorInventory(889,"SuperShotgun",1);
	}
	if (CheckActorInventory(889,"PerfectedRocketLauncher") == 1)
	{
		TakeActorInventory(889,"EnhancedRocketLauncher",1);
		TakeActorInventory(889,"RocketLauncher",1);
	}
	if (CheckActorInventory(889,"PerfectedPlasmaRifle") == 1)
	{
		TakeActorInventory(889,"EnhancedPlasmaRifle",1);
		TakeActorInventory(889,"PlasmaRifle",1);
	}
	if (CheckActorInventory(889,"PerfectedBFG9000") == 1)
	{
		TakeActorInventory(889,"EnhancedBFG9000",1);
		TakeActorInventory(889,"BFG9000",1);
	}
	if (CheckActorInventory(889,"PerfectedAutoRifle") == 1)
	{
		TakeActorInventory(889,"EnhancedAutoRifle",1);
		TakeActorInventory(889,"AutoRifle",1);
	}
	if (CheckActorInventory(889,"PerfectedAutoShotgun") == 1)
	{
		TakeActorInventory(889,"EnhancedAutoShotgun",1);
		TakeActorInventory(889,"AutoShotgun",1);
	}
//Player 3
	if (CheckActorInventory(890,"EnhancedPistol") == 1)
	{
		TakeActorInventory(890,"Pistol",1);
	}
	if (CheckActorInventory(890,"EnhancedShotgun") == 1)
	{
		TakeActorInventory(890,"Shotgun",1);
	}
	if (CheckActorInventory(890,"EnhancedChaingun") == 1)
	{
		TakeActorInventory(890,"Chaingun",1);
	}
	if (CheckActorInventory(890,"EnhancedSuperShotgun") == 1)
	{
		TakeActorInventory(890,"SuperShotgun",1);
	}
	if (CheckActorInventory(890,"EnhancedRocketLauncher") == 1)
	{
		TakeActorInventory(890,"RocketLauncher",1);
	}
	if (CheckActorInventory(890,"EnhancedPlasmaRifle") == 1)
	{
		TakeActorInventory(890,"PlasmaRifle",1);
	}
	if (CheckActorInventory(890,"EnhancedBFG9000") == 1)
	{
		TakeActorInventory(890,"BFG9000",1);
	}
	if (CheckActorInventory(890,"EnhancedAutoRifle") == 1)
	{
		TakeActorInventory(890,"AutoRifle",1);
	}
	if (CheckActorInventory(890,"EnhancedChainsaw") == 1)
	{
		TakeActorInventory(890,"Chainsaw",1);
	}
	if (CheckActorInventory(890,"EnhancedGrenadeLauncher") == 1)
	{
		TakeActorInventory(890,"GrenadeLauncher",1);
	}
	if (CheckActorInventory(890,"EnhancedAutoShotgun") == 1)
	{
		TakeActorInventory(890,"AutoShotgun",1);
	}
	//Perfected
	if (CheckActorInventory(890,"PerfectedPistol") == 1)
	{
		TakeActorInventory(890,"EnhancedPistol",1);
		TakeActorInventory(890,"Pistol",1);
	}
	if (CheckActorInventory(890,"PerfectedChaingun") == 1)
	{
		TakeActorInventory(890,"EnhancedChaingun",1);
		TakeActorInventory(890,"Chaingun",1);
	}
	if (CheckActorInventory(890,"PerfectedSuperShotgun") == 1)
	{
		TakeActorInventory(890,"EnhancedSuperShotgun",1);
		TakeActorInventory(890,"SuperShotgun",1);
	}
	if (CheckActorInventory(890,"PerfectedRocketLauncher") == 1)
	{
		TakeActorInventory(890,"EnhancedRocketLauncher",1);
		TakeActorInventory(890,"RocketLauncher",1);
	}
	if (CheckActorInventory(890,"PerfectedPlasmaRifle") == 1)
	{
		TakeActorInventory(890,"EnhancedPlasmaRifle",1);
		TakeActorInventory(890,"PlasmaRifle",1);
	}
	if (CheckActorInventory(890,"PerfectedBFG9000") == 1)
	{
		TakeActorInventory(890,"EnhancedBFG9000",1);
		TakeActorInventory(890,"BFG9000",1);
	}
	if (CheckActorInventory(890,"PerfectedAutoRifle") == 1)
	{
		TakeActorInventory(890,"EnhancedAutoRifle",1);
		TakeActorInventory(890,"AutoRifle",1);
	}
	if (CheckActorInventory(890,"PerfectedAutoShotgun") == 1)
	{
		TakeActorInventory(890,"EnhancedAutoShotgun",1);
		TakeActorInventory(890,"AutoShotgun",1);
	}
//Player 4
	if (CheckActorInventory(891,"EnhancedPistol") == 1)
	{
		TakeActorInventory(891,"Pistol",1);
	}
	if (CheckActorInventory(891,"EnhancedShotgun") == 1)
	{
		TakeActorInventory(891,"Shotgun",1);
	}
	if (CheckActorInventory(891,"EnhancedChaingun") == 1)
	{
		TakeActorInventory(891,"Chaingun",1);
	}
	if (CheckActorInventory(891,"EnhancedSuperShotgun") == 1)
	{
		TakeActorInventory(891,"SuperShotgun",1);
	}
	if (CheckActorInventory(891,"EnhancedRocketLauncher") == 1)
	{
		TakeActorInventory(891,"RocketLauncher",1);
	}
	if (CheckActorInventory(891,"EnhancedPlasmaRifle") == 1)
	{
		TakeActorInventory(891,"PlasmaRifle",1);
	}
	if (CheckActorInventory(891,"EnhancedBFG9000") == 1)
	{
		TakeActorInventory(891,"BFG9000",1);
	}
	if (CheckActorInventory(891,"EnhancedAutoRifle") == 1)
	{
		TakeActorInventory(891,"AutoRifle",1);
	}
	if (CheckActorInventory(891,"EnhancedChainsaw") == 1)
	{
		TakeActorInventory(891,"Chainsaw",1);
	}
	if (CheckActorInventory(891,"EnhancedGrenadeLauncher") == 1)
	{
		TakeActorInventory(891,"GrenadeLauncher",1);
	}
	if (CheckActorInventory(891,"EnhancedAutoShotgun") == 1)
	{
		TakeActorInventory(891,"AutoShotgun",1);
	}
	//Perfected
	if (CheckActorInventory(891,"PerfectedPistol") == 1)
	{
		TakeActorInventory(891,"EnhancedPistol",1);
		TakeActorInventory(891,"Pistol",1);
	}
	if (CheckActorInventory(891,"PerfectedChaingun") == 1)
	{
		TakeActorInventory(891,"EnhancedChaingun",1);
		TakeActorInventory(891,"Chaingun",1);
	}
	if (CheckActorInventory(891,"PerfectedSuperShotgun") == 1)
	{
		TakeActorInventory(891,"EnhancedSuperShotgun",1);
		TakeActorInventory(891,"SuperShotgun",1);
	}
	if (CheckActorInventory(891,"PerfectedRocketLauncher") == 1)
	{
		TakeActorInventory(891,"EnhancedRocketLauncher",1);
		TakeActorInventory(891,"RocketLauncher",1);
	}
	if (CheckActorInventory(891,"PerfectedPlasmaRifle") == 1)
	{
		TakeActorInventory(891,"EnhancedPlasmaRifle",1);
		TakeActorInventory(891,"PlasmaRifle",1);
	}
	if (CheckActorInventory(891,"PerfectedBFG9000") == 1)
	{
		TakeActorInventory(891,"EnhancedBFG9000",1);
		TakeActorInventory(891,"BFG9000",1);
	}
	if (CheckActorInventory(891,"PerfectedAutoRifle") == 1)
	{
		TakeActorInventory(891,"EnhancedAutoRifle",1);
		TakeActorInventory(891,"AutoRifle",1);
	}
	if (CheckActorInventory(891,"PerfectedAutoShotgun") == 1)
	{
		TakeActorInventory(891,"EnhancedAutoShotgun",1);
		TakeActorInventory(891,"AutoShotgun",1);
	}
Delay(35);
Restart;
}

Script 10001 (void)
{
	ClearDisplay();
}

Function void ClearDisplay(void)
{
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 131, "Green", 0.50, 0.30, 400000);
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 132, "White", 0.50, 0.40, 400000);
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 133, "Gold", 0.50, 0.50, 400000);
	//Respawn
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 155, "Green", 0.50, 0.30, 400000);
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 255, "Green", 0.50, 0.30, 400000);
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 355, "Green", 0.50, 0.30, 400000);
	HudMessageBold(s:"";
	HUDMSG_PLAIN | HUDMSG_COLORSTRING, 455, "Green", 0.50, 0.30, 400000);

}