#library "global"
#include "zcommon.acs"

int timestop=0;

//////////////////////////////////////////////////////////////////////////////////////////
//The scripts classes mod changes: 

// Player Color
//
script 991 (int weap)
{
	// Terminate if any teamplay game mode
	if(GetCvar("teamplay")==1){terminate;}
	if(GetCvar("teamlms")==1){terminate;}
	if(GetCvar("ctf")==1){terminate;}
	if(GetCvar("oneflagctf")==1){terminate;}
	if(GetCvar("teampossession")==1){terminate;} //plz add to vanilla

// See WCOLORS for color information
if (!CheckInventory("DocBusterC")&&!CheckInventory("BearerFlag")) {
	Thing_SetTranslation(0, weap);
}
}

script 984 (void)

{
if(CheckInventory("CanCopyWeapons")==1||CheckInventory("RollFlag")==1||CheckInventory("BearerFlag")==1){
if(CheckInventory("EnergyBalancerActive")==1){
SetResultValue( TRUE );
} else {
if(CheckWeapon("MegaBuster")==1 || CheckWeapon("MegaBusterC")==1 ||
CheckWeapon("ProtoBusterC")==1 || CheckWeapon("BassBusterC")==1 ||
CheckWeapon("PowerFistC")==1 || CheckWeapon("JetBusterC")==1 ||
CheckWeapon("SuperAdaptorWep")==1 || CheckWeapon("TrebleboosterWepC")==1 ||
CheckInventory("DocBusterC")||CheckWeapon("ArchiveBusterC")) {
SetResultValue( FALSE );
} else {
SetResultValue( TRUE );
}
}
} else {
SetResultValue( FALSE );
}
}

// Some extra stuff to help bots
//
script 983 ENTER
{
	if(PlayerIsBot(PlayerNumber())){
		if(timestop==0){
		// Give the bot the special "stair checker" actor
		GiveInventory("CreateBotBuddy",1);
		// And infinite ammo
		GiveInventory("WeaponEnergy",50);
		
		// Bot AI on weapons
		GiveInventory("IsBotFlag",1);
		if (CheckInventory("BotRetreatFlag")) {
			GiveInventory("BotRetreat",1);
		} else if (CheckInventory("BotHugFlag")){
			GiveInventory("BotHug",1);
		} else {
			GiveInventory("BotRevert",1);
		}
		
		/*GiveInventory("KFCAmmo",50);
		GiveInventory("GutsArmAmmo",50);
		GiveInventory("IcicleAmmo",50);
		GiveInventory("GigaAmmo",50);
		GiveInventory("FireyAmmo",50);
		GiveInventory("ElectricAmmo",50);
		GiveInventory("OilClassAmmo",50);
		GiveInventory("TimeClassAmmo",50);
		GiveInventory("MootalAmmo",50);
		GiveInventory("ZippoAmmo",50);
		GiveInventory("Can'tDefeatAmmo",50);
		GiveInventory("IncredibleAmmo",50);
		GiveInventory("TimeAmmo",50);
		GiveInventory("PlasmaAmmo",50);
		GiveInventory("ClashAmmo",50);
		GiveInventory("PullAmmo",50);
		GiveInventory("NoodleAmmo",50);
		GiveInventory("SnakemanAmmo",50);
		GiveInventory("DrillBombClassAmmo",50);
		GiveInventory("FlashStopperClassAmmo",50);
		GiveInventory("DiveMissileClassAmmo",50);
		GiveInventory("SkullBusterClassAmmo",50);
		GiveInventory("CrushEmAmmo",50);
		GiveInventory("PharaohShotClassAmmo",50);
		GiveInventory("NapalmClassAmmo",50);
		GiveInventory("GravityHoldClassAmmo",50);
		GiveInventory("StoneBossAmmo",50);
		GiveInventory("ChargeKickClassAmmo",50);
		GiveInventory("WaterWaveClassAmmo",50);
		GiveInventory("CrystalEyeClassAmmo",50);
		GiveInventory("StarCrashClassAmmo",50);
		GiveInventory("GyroFly",50);
		GiveInventory("FlameBossAmmo",50);
		GiveInventory("BallAmmo",50);
		GiveInventory("KnightmanAmmo",50);
		GiveInventory("CentaurAmmo",50);
		GiveInventory("PlantbossAmmo",50);
		GiveInventory("TomahawkClassAmmo",50);
		GiveInventory("YamatoClassAmmo",50);
		GiveInventory("WindClassAmmo",50);
		GiveInventory("MrFreezeAmmo",50);
		GiveInventory("BursterAmmo",50);
		GiveInventory("Petrol",50);
		GiveInventory("RainAmmo",50);
		GiveInventory("GumAmmo",50);
		GiveInventory("TrunkAmmo",50);
		GiveInventory("DashAmmo",50);
		GiveInventory("NoiseCrushClassAmmo",50);
		GiveInventory("MirrorCharge",50);
		GiveInventory("ScrewCrushAmmo",50);
		GiveInventory("BalladeCrackerBalladeAmmo",50);*/
		SetWeapon("JunkShielderBoss");
		Delay(1);
		
		// If CutterFlag is 999, the player is dead, so terminate this script
		if(CheckInventory("CutterFlag")==999){terminate;}
		
		Restart;
		}
	}
}


int buttons2[32];
int fallingplayer[32];
 
// Jump Canceling script. Very awkward but it works somewhat!
//
script 977 ENTER
{
if(PlayerIsBot(PlayerNumber())){terminate;}
  while (TRUE)
  {
    buttons2[PlayerNumber()] = GetPlayerInput(-1, INPUT_BUTTONS);
	if(GetActorZ (0) - GetActorFloorZ (0)==0.0)
	{
	GiveInventory("JumpCancler",1);
	//print(s:"You're grounded!");
	if(CheckInventory("CanWallJump")){
		GiveInventory("Stamina",5);
	}
	if(CheckInventory("BassBusterC")){
		TakeInventory("NoJump",999);
	}
	}
	
	if(GetActorVelZ(0)<0.0)
	{
	TakeInventory("JumpCancler",1);
	//print(s:"You're falling!");
	}
	fallingplayer[ActivatorTID()] = GetActorZ (0);
	
	if(CheckInventory("JumpCancler")>0){
	//print(s:"You let go but are already falling!");
    if (GetPlayerInput(-1, INPUT_OLDBUTTONS) == GetPlayerInput(-1, INPUT_BUTTONS) + BT_JUMP )
    {
	TakeInventory("JumpCancler",1);
    //  print(s:"You let go!");
	  ThrustThingZ(0,0,0,0);
    }}
	
	if(!CheckInventory("FlightDisableFlag")){
	
	if(CheckWeapon("SuperAdaptorWep")==1){
	if(CheckInventory("NoBoost")==0){
	if(CheckInventory("JumpCancler")==0){
    if (GetPlayerInput(-1, INPUT_OLDBUTTONS) == GetPlayerInput(-1, INPUT_BUTTONS) - BT_JUMP )
    {
	GiveInventory("Boosting",1);
    }
	}
	}
	}
	if(CheckInventory("BassBusterC")==1){
	if(CheckInventory("NoJump")==0){
	if(CheckInventory("JumpCancler")==0){
    if (GetPlayerInput(-1, INPUT_OLDBUTTONS) == GetPlayerInput(-1, INPUT_BUTTONS) - BT_JUMP )
    {
	GiveInventory("Jumping",1);
    }
	}
	}
	}
	if(CheckInventory("CanWallJump")){
	if(CheckInventory("NoJump")==0){
	if(CheckInventory("JumpCancler")==0){
    if (GetPlayerInput(-1, INPUT_OLDBUTTONS) == GetPlayerInput(-1, INPUT_BUTTONS) - BT_JUMP )
    {
	GiveInventory("WallJumping",1);
    }
	}
	}
	}
	
	}
	
	if(CheckInventory("OnCeilingFlag")==1){
    if (GetPlayerInput(-1, INPUT_OLDBUTTONS) == GetPlayerInput(-1, INPUT_BUTTONS) - BT_JUMP )
    {
	GiveInventory("ReverseJump",1);
	}
	}
    delay(1);
		
  }
}

function int max (int a, int b)
{
	if (a > b)
		return a;

	return b;
}

function int min (int a, int b)
{
	if (a < b)
		return a;

	return b;
}

// Scorch Wheel speed adjuster
//
script 191 (int speed)
{
	switch (speed) {
	//Bot Revert
		case 8:
		int o1 = GetActorProperty(0,APROP_SPEED);
		  SetActorProperty(0,APROP_SPEED,max(o1,o1*-1));
		  break;
	//Bot Reverse
		case 7:
		int o2 = GetActorProperty(0,APROP_SPEED);
		  SetActorProperty(0,APROP_SPEED,min(o2,o2*-1));
		  break;
	//Bomb man
		case 6:
		  SetActorProperty(0,APROP_SPEED,0.5);
		  break;
	//Bass Dash
		case 5:
		  //SetActorProperty(0,APROP_SPEED,0.85);
		  break;
	//Gravity man
		case 4:
		  SetActorProperty(0,APROP_SPEED,2.0);
		  break;
	//Darkman 1
		case 2:
		  int healthSpeed = 0.006;
		  healthSpeed *= 100-min(PlayerHealth(),100);
		  SetActorProperty(0,APROP_SPEED,(1.0+healthSpeed));
		  break;
	//Scorch Wheel
		case 1:
		  SetActorProperty(0,APROP_SPEED,1.45);
		  break;
		case 0:
		  if (!CheckInventory("DocBusterC")) {
			SetActorProperty(0,APROP_SPEED,1.0);
		  } else {
			SetActorProperty(0,APROP_SPEED,1.05);
		  }
		  break;
		default:
		  SetActorProperty(0,APROP_SPEED,1.0);
		  break;
	}
}

// Set up weapon randomization for LMS/TLMS
//
str RangedWepC[12]={
"BlizzardAttackWepC",
"SparkShockWepC",
"FireStormWepC",
"DustCrusherWepC",
"ThunderBeamWepC",
"GyroAttackWepC",
"DiveMissileWepC",
"SilverTomahawkWepC",
"MagnetMissileWepC",
"GeminiLaserWepC",
"ThunderBoltWepC",
"FreezeCrackerWepC"
};
str RapidWepC[9]={
"QuickBoomerangWepC",
"IceSlasherWepC",
"WaterWaveWepC",
"MetalBladeWepC",
"ScrewCrusherWepC",
"YamatoSpearWepC",
"NeedleCannonWepC",
"ScorchWheelWepC",
"WildCoilWepC"
};
str CloseWepC[15]={
"BubbleLeadWepC",
"WindStormWepC",
"CrystalEyeWepC",
"PowerStoneWepC",
"RingBoomerangWepC",
"RollingCutterWepC",
"ChargeKickWepC",
"SearchSnakeWepC",
"FlameBlastWepC",
"ShadowBladeWepC",
"KnightCrushWepC",
"TopSpinWepC",
"AirShooterWepC",
"NoiseCrushWepC",
"SlashClawWepC"
};
str PowerWepC[10]={
"PharaohShotWepC",
"SuperArmWepC",
"AtomicFireWepC",
"HardKnuckleWepC",
"CrashBombWepC",
"NapalmBombWepC",
"HyperBombWepC",
"DrillBombWepC",
"BalladeCrackerWepC",
"DangerWrapWepC"
};
str ShieldWepC[6]={
"LeafShieldWepC",
"StarCrashWepC",
"MirrorBusterWepC",
"PlantBarrierWepC",
"SkullBarrierWepC",
"JunkShieldWepC"
};

global int 0:RangedWepCRandom;
global int 1:RapidWepCRandom;
global int 2:CloseWepCRandom;
global int 3:PowerWepCRandom;
global int 4:ShieldWepCRandom;

// LMS Weapon Randomization
//
script 981 (void)
{
// Check if the game is actually LMS
if(GetCvar("lastmanstanding")==1||GetCvar("teamlms")==1){
	// Ignore if game is set to instagib
	if(GetCvar("instagib")==1){terminate;}
	
	Delay(1);
	
	// Take bots Mega Buster so they actually use a different weapon (limited to ranged weapon at present)
	if(PlayerIsBot(PlayerNumber())){
		TakeInventory("MegaBuster",1);
	}
	
	// Give players one of each weapon type at random
//	GiveInventory(ShieldWepC[ShieldWepCRandom],1);
	GiveInventory(RapidWepC[RapidWepCRandom],1);
	GiveInventory(CloseWepC[CloseWepCRandom],1);
	GiveInventory(PowerWepC[PowerWepCRandom],1);
	GiveInventory(RangedWepC[RangedWepCRandom],1);
	
	Delay(1);
	
	// Give the bot the Mega Buster back
	if(PlayerIsBot(PlayerNumber())){
		GiveInventory("MegaBuster",1);
	}
}
}

//Rest of global scripts merely have c on the end of the weapons.
////////////////////////////////////////////////////////////////////////////////////////////////

// Fade Script (?)
//
Script 999 (int fade)
{
	// Clear all fades
	if(fade==0){
	FadeTo(0,0,0,0.0,0.0);
	}
	
	// Fade to Green (?)
	if(fade==1){
	FadeTo(0,255,0,0.3,0.0);
	}
}

// Various per player scritps
// On level enter/spawn
//
script 997 ENTER
{
	// Team specific player colors
	if(PlayerTeam()==1){
	Thing_SetTranslation(0, 48);
	}
	if(PlayerTeam()==2){
	Thing_SetTranslation(0, 43);
	}
	if(PlayerTeam()==3){
	Thing_SetTranslation(0, 47);
	}
	
	// If a timestop is active, freeze the player
	if(timestop>0){
	SetPlayerProperty(0,1,4);
	}

	// If instagib is enabled, give Instagib Blades
	if(GetCvar("instagib")==1){
	TakeInventory("MegaBuster",1);
	GiveInventory("IGMetalBladeWepC",1);
	}

	// If player is a bot, enable ledge blocking (Monster Cross Lines)
	if(PlayerIsBot(PlayerNumber())){
	GiveInventory("MonsterBlock",1);
	}

// Give Player a unique TID (tag)
Thing_ChangeTID(0,PlayerNumber()+1000);

// Clear the HUD of any effects/messages etc
HudMessage(s:""; HUDMSG_PLAIN,50,CR_UNTRANSLATED,0.0,0.0,0.1);
}

// Various per player scritps
// On respawn
//

// Various per player scritps
// On respawn
//
script 996 RESPAWN
{
	// If players is on the red team, change color
	if(PlayerTeam()==1){
	Thing_SetTranslation(0, 48);
	}

// Execute the ENTER script above
ACS_ExecuteAlways(997,0);
}

// Foce compat_clientssendfullbuttoninfo true (to enable jump cancel)
//
script 995 OPEN
{
	// Check if multiplayer
	if(PlayerCount()>0){
		// Check if the server has compat_clientssendfullbuttoninfo set to false
		if(GetCVar("compat_clientssendfullbuttoninfo")==0){
		ConsoleCommand("compat_clientssendfullbuttoninfo 1");
		}
		
		// Prevent suicides in LMS and Team LMS
		if(GetCvar("lastmanstanding")==1){
			if(GetCvar("sv_disallowsuicide")==0){
			ConsoleCommand("sv_disallowsuicide 1");
			}
		}
		if(GetCvar("teamlms")==1){
			if(GetCvar("sv_disallowsuicide")==0){
			ConsoleCommand("sv_disallowsuicide 1");
			}
		}
	}
}

// Force certain weapons to not function in CTF/LMS/Possession etc such as Time stop
//
script 994 (void)
{
if(PlayerIsBot(PlayerNumber())){
if(CheckInventory("TimeStopperWepC")>0){
TakeInventory("TimeStopperWepC",1);
GiveInventory("MegaBuster",1);
SetWeapon("MegaBuster");
}

if(CheckInventory("SkullBarrierWepC")>0){
TakeInventory("SkullBarrierWepC",1);
GiveInventory("MegaBuster",1);
SetWeapon("MegaBuster");
}

if(CheckInventory("JunkShieldWepC")>0){
TakeInventory("JunkShieldWepC",1);
GiveInventory("MegaBuster",1);
SetWeapon("MegaBuster");
}

if(CheckInventory("PlantBarrierWepC")>0){
TakeInventory("PlantBarrierWepC",1);
GiveInventory("MegaBuster",1);
SetWeapon("MegaBuster");
}
SetPlayerProperty(0,1,4);
Delay(1);
SetPlayerProperty(0,0,4);
}}

// Rotation scripts
// Will try to change this to make it more flexible later...
script 990 (int whichrotate)
{
	// Top Spin
	if(whichrotate==1){
	SetActorAngle (ActivatorTID(), GetActorAngle (ActivatorTID()) - 0.06);
	}
	// Power Stone
	if(whichrotate==2){
	SetActorAngle (ActivatorTID(), GetActorAngle (ActivatorTID()) - 0.05);
	}
}

script 989 (void) // Empty script woo!
{

}

// Integer to keep track of the unique TIDs of Power Stone (5000 - 5100)
int powerstonecount=5000;

// Delicously horrible way to keep each unique Power Stone rotating
//
script 988 (void)
{
// New Power Stone TID
powerstonecount++;
Thing_ChangeTID(0,powerstonecount);
	
	// Do not allow any more than 100 Power Stone TIDs
	// FUN FACT: If you can summon more than 100 Power Stones in a match, this will most likely go nuts
	if(powerstonecount>=5100){
	powerstonecount = 5000;
	}
}
// Remove Time Stop on Death (user only)
// (could probably merge a few scripts with this)
script 987 DEATH
{
	// Check if the guy who died stopped time
	if(timestop==PlayerNumber()){
	ACS_Terminate(986,0); // Stop the flashy effects on the HUD for all players
	HudMessageBold(s:""; HUDMSG_PLAIN,50,CR_UNTRANSLATED,0.0,0.0,0.1);
	SetWeapon("MegaBuster");
	Delay(1);
	SetPlayerProperty(1,0,4);
	TakeInventory("PowerTimeFreezer",1);
	TakeInventory("TimeFreezer",1);
	TakeInventory("TimeStopperWepC",1);
	timestop=0;
	ACS_Terminate(193,0); //
	}
	
	// Stop the HUD effects
	HudMessageBold(s:""; HUDMSG_PLAIN,50,CR_UNTRANSLATED,0.0,0.0,0.1);
	//ACS_Terminate(986,0);
}

// Time Stopper HUD FX
//
script 986 (void)
{
SetHudSize(256,224,0);
SetFont("FLASHS1");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS2");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS3");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS4");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS5");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS6");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS7");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS8");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
SetFont("FLASHS9");
HudMessageBold(s:"A"; HUDMSG_PLAIN,50,CR_UNTRANSLATED,128.0,112.0,0.0);
Delay(4);
Restart;
}


script 985 (void) // Empty script woo!
{

}

// Very basic Mega Buster check (used for certain items?)
//
/* -- see above for energy balancer replacement -- ssw
script 984 (void)
{
	if(CheckWeapon("MegaBuster")==0){
	SetResultValue( TRUE );
	}
	if(CheckWeapon("MegaBuster")==1){
	SetResultValue( FALSE );
	}
}
*/

// Duplicate of the above for RESPAWN
//
script 982 RESPAWN
{
ACS_ExecuteAlways(983,0);
}

// A script to generate random numbers for LMS weapons
//
script 980 OPEN
{
	Delay(10);
	RangedWepCRandom = Random(0,11);
	RapidWepCRandom = Random(0,8);
	CloseWepCRandom = Random(0,14);
	PowerWepCRandom = Random(0,9);
	ShieldWepCRandom = Random(0,5);
}

// Clientside script that is executed everytime a weapon's NoAmmo state is called.
// All weapons have it but the script is currently unused.
script 979 (void) CLIENTSIDE
{
}

// Forces a bot to select his Mega Buster.
//
script 978 (void)
{
if(PlayerIsBot(PlayerNumber())){
SetWeapon("MegaBuster");
}
}

script 972 (void)
{
SetWeapon("NewTrebleboosterWepC");
}


// Quick flash script for Flash Stopper/Centaur Flash
//
script 976 (Void) clientside
{
FadeTo(255,255,255,1.0,0.0);
Delay(2);
FadeTo(255,255,255,0.0,0.0);
Delay(2);
}

// Return the current game mode. Used for checking if certain items should be available in these modes.
// 0 = Deathmatch
// 1 = Poessesion
// 2 = LMS
// 3 = Duel
// 4 = CTF
script 975 (Void)
{
	if(GetCvar("deathmatch")==1){SetResultValue(0);}
	if(GetCvar("possession")==1){SetResultValue(1);}
	if(GetCvar("teampossession")==1){SetResultValue(1);}
	if(GetCvar("lastmanstanding")==1){SetResultValue(2);}
	if(GetCvar("teamlms")==1){SetResultValue(2);}
	if(GetCvar("duel")==1){SetResultValue(3);}
	if(GetCvar("ctf")==1){SetResultValue(4);}
	if(GetCvar("oneflagctf")==1){SetResultValue(4);}
}

// Quickly freeze/unfreeze a bot. Used to force them to keep pressing the fire button
//
script 974 (void)
{
	if(PlayerIsBot(PlayerNumber()))
	{
	SetPlayerProperty(0,1,4);
	Delay(5);
	SetPlayerProperty(0,0,4);
	}
}

// Force players to change certain console commands.
// Word of warning for fellow modders: BE NICE WITH CONSOLECOMMAND!
script 973 ENTER clientside
{
	// Prevent weapon names showing up on the HUD (because they all end in "WepC" and it looks wrong)
	ConsoleCommand("cl_showweapnameoncycle false");
}

// Beat Call Script
// Activated on certain maps via sector actions (in pitfalls)
script 205 (void)
{
	if(CheckInventory("BeatCallCheck")>0){
		if(CheckInventory("BeatCounter")==0){
		
		// Remove Rush Jet
		TakeInventory("RushCounter",999);
		// Activate Beat (flying properties etc)
		GiveInventory("BeatActivate",1);
		GiveInventory("BeatCounter",20);
		ThingSound(ActivatorTID(),"item/beat",127);
		
		}
	}
}

// Gravity altering script for certain maps with water (horrible method)
//
script 204 (int grav)
{
	if(grav==0){SetActorProperty(ActivatorTID(), APROP_Gravity, 0.8);}
	if(grav==1){SetActorProperty(ActivatorTID(), APROP_Gravity, 0.25);}
}

// Boss music script. Boss music depends on the level's par setting.
// For custom maps, either change the par or make your own music altering script!
// Also this script is activated via the "KilledMe" actor, which is given to the killer when a player dies.
// Might be useful for other things, such as ingame achievements (GVH style)
script 203 (void)
{
	if(GetCvar("lastmanstanding")==1){terminate;}
	if(GetCvar("teamlms")==1){terminate;}
	if(GetCvar("duel")==1){terminate;}
	if(GetCvar("ctf")==1){terminate;}
	if(GetCvar("oneflagctf")==1){terminate;}
	if(GetCvar("possession")==1){terminate;}
	if(GetCvar("teampossession")==1){terminate;}

	// Check if the player has five frags remaining
	if(PlayerFrags() == GetCVar("fraglimit") - 5){
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==1){SetMusic("MM1BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==2){SetMusic("MM2BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==3){SetMusic("MM3BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==4){SetMusic("MM4BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==5){SetMusic("MM5BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==6){SetMusic("MM6BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==7){SetMusic("MM7BOSS");}
	}
}

// A Respawn script for check for jump cancelling (akward, might move it later) and freezing players in LMS.
// The latter is done to attempt to stop the weapon randomization messing up
script 201 RESPAWN
{
ACS_ExecuteAlways(977,0);

	if(GetCvar("lastmanstanding")==1||GetCvar("teamlms")==1){
	Delay(1);
		if(Timer()>200){
		//SetPlayerProperty(1,1,4);
		//Instead of freezing, make the player completely invincible!
		GiveInventory("LMSInvincible",1);
		}
	}
}

// Check Flame Blast for oil in Flame Man's stage
//
script 202 (void)
{
if(CheckActorFloorTexture(0, "FLAMOIL1")){
ACS_Execute(1,0,0);
}
if(CheckActorFloorTexture(0, "FLAMOIL2")){
ACS_Execute(2,0,0);
}
}


global int 0:SecretUnlock[];
global int 1: rushtime;

// Unlock Global Value (Singleplayer)
//
Script 200 (int which)
{
SecretUnlock[which]=1;
}

// Check if a global value has been unlocked
//
script 199 (int which)
{
SetResultValue( SecretUnlock[which] );
}

// Set all global values to zero (locked)
//
Script 198 (void)
{
SecretUnlock[0]=0;
SecretUnlock[1]=0;
SecretUnlock[2]=0;
SecretUnlock[3]=0;
SecretUnlock[4]=0;
SecretUnlock[5]=0;
SecretUnlock[6]=0;
SecretUnlock[7]=0;
SecretUnlock[8]=0;
}

// Singleplayer secret weapons
//
Script 197 ENTER
{
	// Checks if the second player is a human. Useful for checking if it is TRUELY an online game.
	if(PlayerIsBot(PlayerNumber())){terminate;}
	
	Delay(1);
	
	// Give secret weapons
	if(SecretUnlock[6]==1){
	GiveInventory("ScrewCrusherWepC",1);
	}
	if(SecretUnlock[7]==1){
	GiveInventory("MirrorBusterWepC",1);
	}
	if(SecretUnlock[8]==1){
	GiveInventory("BalladeCrackerWepC",1);
	}
}

// Duplicate of the above, for when you respawn
//
Script 196 RESPAWN
{
ACS_Execute(197,0);
}

// Used to thrust a bot into the air (?)
//
Script 195 (void)
{
	if(PlayerIsBot(PlayerNumber())){
	ThrustThingZ(0,50,0,1);
	Delay(35);
	}
}

// Force a bot to use the Mega Buster (DUPLICATE???)
//
Script 194 (void)
{
	if(PlayerIsBot(PlayerNumber())){
	GiveInventory("MegaBuster",1);
	SetWeapon("MegaBuster");
	}
}

// Needlessly complex failsafe for the Time Stopper
//
Script 193 (void)
{
timestop=PlayerNumber();
//PrintBold(s:"Timestop failsafe started");
Delay(35*30);
//PrintBold(s:"Timestop failsafe Ended");
ACS_Terminate(986,0);
HudMessageBold(s:""; HUDMSG_PLAIN,50,CR_UNTRANSLATED,0.0,0.0,0.1);
Delay(1);
SetPlayerProperty(1,0,4);
TakeInventory("PowerTimeFreezer",1);
TakeInventory("TimeFreezer",1);
TakeInventory("TimeStopperWepC",1);
timestop=0;
//PrintBold(s:"Timestop failsafe Sucess!");
}

// Failsafe continued
//
Script 192 (int who) DISCONNECT
{
//PrintBold(s:"Disconnected");
if(timestop==who){
//PrintBold(s:"Found time stopper man");
ACS_Terminate(986,0);
HudMessageBold(s:""; HUDMSG_PLAIN,50,CR_UNTRANSLATED,0.0,0.0,0.1);
SetWeapon("MegaBuster");
Delay(1);
SetPlayerProperty(1,0,4);
//PrintBold(s:"unfroze people");
TakeInventory("PowerTimeFreezer",1);
TakeInventory("TimeFreezer",1);
TakeInventory("TimeStopperWepC",1);
timestop=0;
ACS_Terminate(193,0);
}
}

script 190 OPEN
{
	if(GetCvar("ctf")==1){
		if(BlueScore() == GetCVar("pointlimit") - 1 || RedScore() == GetCVar("pointlimit") - 1){
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==1){SetMusic("MM1BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==2){SetMusic("MM2BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==3){SetMusic("MM3BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==4){SetMusic("MM4BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==5){SetMusic("MM5BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==6){SetMusic("MM6BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==7){SetMusic("MM7BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==8){SetMusic("MM7OBOS");}
		}
	}
	if(GetCvar("oneflagctf")==1){
		if(BlueScore() == GetCVar("pointlimit") - 1 || RedScore() == GetCVar("pointlimit") - 1){
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==1){SetMusic("MM1BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==2){SetMusic("MM2BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==3){SetMusic("MM3BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==4){SetMusic("MM4BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==5){SetMusic("MM5BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==6){SetMusic("MM6BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==7){SetMusic("MM7BOSS");}
		if(GetLevelInfo(LEVELINFO_PAR_TIME)==8){SetMusic("MM7OBOS");}
		}
	}
	if(GetCvar("ctf")==0){
	if(GetCvar("oneflagctf")==0){
	terminate;
	}
	}
	Delay(35*2);
	restart;
}