//Scripts of my old bike. Required to make the tank work.


#library "VEHICLECONTROL"
#include "zcommon.acs"



int playerprevioushealth;
int playerpreviousarmor;
int vehicleprevioushealth;




//FORWARD
script "BDForwardInput" ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
   
if (buttons & BT_FORWARD)
{
   GiveInventory("Accelerate", 1);
   //giveinventory("HealthBonus", GetActorProperty(0, APROP_HEALTH));
   
   delay(1);
}
   delay(1);
   TakeInventory("Accelerate", 1);
 }
}


//BACKPEDAL
script "BDBackInput" ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_BACK)
{
    GiveInventory("BackPedal", 1);
	delay(2);
}

   delay(2);
   TakeInventory("BackPedal", 1);
 }
}


//LEFT
script "BDLeftInput" ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_MOVELEFT)
{
    GiveInventory("TurnLeft", 1);
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("RollLeft", 1); }
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("GoSpecial", 1); }
}
   delay(1);
   TakeInventory("TurnLeft", 1);
 }
}



//RIGHT
script "BDRightInput" ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
   
if (buttons & BT_MOVERIGHT)
{
    GiveInventory("TurnRight", 1);
	
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("RollRight", 1); }
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("GoSpecial", 1); }
}

   delay(1);
   
   TakeInventory("TurnRight", 1);
 }
}

//USE
script "BDUseInput" ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_USE)
{
    GiveInventory("PressedUse", 1);
}

   delay(1);
 }
}

//JUMP
script "BDJumpInput" ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_JUMP)
{
    GiveInventory("PressedJump", 1);
}

   delay(1);
 }
}


Script "HeliRollRight" (VOID)
{
ChangeActorRoll (0, 0.005, 1); delay (1);
ChangeActorRoll (0, 0.010, 1); delay (1);
ChangeActorRoll (0, 0.015, 1); delay (1);
ChangeActorRoll (0, 0.02, 1); delay (1);
ChangeActorRoll (0, 0.03, 1); delay (1);
ChangeActorRoll (0, 0.05, 1); delay (1);
ChangeActorRoll (0, 0.06, 1); delay (1);
ChangeActorRoll (0, 0.07, 1); delay (1);
ChangeActorRoll (0, 0.075, 1); delay (1);
ChangeActorRoll (0, 0.08, 1); delay (1);
ChangeActorRoll (0, 0.085, 1); delay (1);
ChangeActorRoll (0, 0.09, 1); delay (1);
}

Script "HeliRollLeft" (VOID)
{
ChangeActorRoll (0, -0.005, 1); delay (1);
ChangeActorRoll (0, -0.010, 1); delay (1);
ChangeActorRoll (0, -0.015, 1); delay (1);
ChangeActorRoll (0, -0.02, 1); delay (1);
ChangeActorRoll (0, -0.03, 1); delay (1);
ChangeActorRoll (0, -0.05, 1); delay (1);
ChangeActorRoll (0, -0.06, 1); delay (1);
ChangeActorRoll (0, -0.07, 1); delay (1);
ChangeActorRoll (0, -0.075, 1); delay (1);
ChangeActorRoll (0, -0.08, 1); delay (1);
ChangeActorRoll (0, -0.085, 1); delay (1);
ChangeActorRoll (0, -0.09, 1); delay (1);
}




Script "HeliStopRight" (VOID)
{
ChangeActorRoll (0, 0.09, 1); delay (1);
ChangeActorRoll (0, 0.085, 1); delay (1);
ChangeActorRoll (0, 0.08, 1); delay (1);
ChangeActorRoll (0, 0.075, 1); delay (1);
ChangeActorRoll (0, 0.07, 1); delay (1);
ChangeActorRoll (0, 0.06, 1); delay (1);
ChangeActorRoll (0, 0.05, 1); delay (1);
ChangeActorRoll (0, 0.03, 1); delay (1);
ChangeActorRoll (0, 0.02, 1); delay (1);
ChangeActorRoll (0, 0.015, 1); delay (1);
ChangeActorRoll (0, 0.007, 1); delay (1);
ChangeActorRoll (0, 0, 1); delay (1);
}

Script "HeliStopLeft" (VOID)
{
ChangeActorRoll (0, -0.09, 1); delay (1);
ChangeActorRoll (0, -0.085, 1); delay (1);
ChangeActorRoll (0, -0.08, 1); delay (1);
ChangeActorRoll (0, -0.075, 1); delay (1);
ChangeActorRoll (0, -0.07, 1); delay (1);
ChangeActorRoll (0, -0.06, 1); delay (1);
ChangeActorRoll (0, -0.05, 1); delay (1);
ChangeActorRoll (0, -0.03, 1); delay (1);
ChangeActorRoll (0, -0.02, 1); delay (1);
ChangeActorRoll (0, -0.015, 1); delay (1);
ChangeActorRoll (0, -0.007, 1); delay (1);
ChangeActorRoll (0, 0, 1); delay (1);
}


//Bike


Script "BikeRollRight" (VOID)
{
ChangeActorRoll (0, 0.005, 1); delay (1);
ChangeActorRoll (0, 0.010, 1); delay (1);
ChangeActorRoll (0, 0.015, 1); delay (1);
ChangeActorRoll (0, 0.02, 1); delay (1);
ChangeActorRoll (0, 0.03, 1); delay (1);
ChangeActorRoll (0, 0.05, 1); delay (1);
}

Script "BikeRollLeft" (VOID)
{
ChangeActorRoll (0, -0.005, 1); delay (1);
ChangeActorRoll (0, -0.010, 1); delay (1);
ChangeActorRoll (0, -0.015, 1); delay (1);
ChangeActorRoll (0, -0.02, 1); delay (1);
ChangeActorRoll (0, -0.03, 1); delay (1);
ChangeActorRoll (0, -0.05, 1); delay (1);
}

Script "BikeStopRight" (VOID)
{
ChangeActorRoll (0, 0.04, 1); delay (1);
ChangeActorRoll (0, 0.03, 1); delay (1);
ChangeActorRoll (0, 0.02, 1); delay (1);
ChangeActorRoll (0, 0.015, 1); delay (1);
ChangeActorRoll (0, 0, 1); delay (1);
}

Script "BikeStopLeft" (VOID)
{
ChangeActorRoll (0, -0.04, 1); delay (1);
ChangeActorRoll (0, -0.03, 1); delay (1);
ChangeActorRoll (0, -0.02, 1); delay (1);
ChangeActorRoll (0, -0.015, 1); delay (1);
ChangeActorRoll (0, 0, 1); delay (1);
}




Script "BDFiredTankMainGun" (VOID) NET
{
 delay (90);
 TakeInventory("FiredTankMainGun", 1);
}


Script "BDUnMorph" (VOID) NET
{
 delay (1);
 UnMorphActor(0, 0);
}

Script "BDCHeckOnline" (VOID)//Check if player is online.
{
if	(GameType () > 0) 
	SetActorState(0,"IsOnline"); 
}

script "GetVehiclePreviousHealth" (VOID) NET
{
 vehicleprevioushealth = GetActorProperty(261, APROP_Health);
  delay(1);
}

script "GetVehiclePreviousHealth2" (VOID) NET
{
 delay(1);
 playerprevioushealth = GetActorProperty( 0, APROP_Health);
 playerpreviousarmor = CheckInventory("Armor");
}


//Entering Heavy Machinegun
script "BDEnterHMG" (VOID) NET
{
 delay(6);
 SetActorAngle (0, GetActorAngle (261));
 Thing_Move(0, 261, 1);
 GiveInventory("GiveArmor", playerpreviousarmor);
 SetActorProperty(0, APROP_Health, playerprevioushealth);
 int thisgunmachinegunammo = CheckActorInventory(261, "HeavyMachinegunAmmo");
 GiveInventory("HeavyMachinegunAmmo", thisgunmachinegunammo);
 delay(1);
}



//leaving Heavy Machinegun
script "BDLeaveHMG" (VOID) NET
{
 delay (1);
 playerprevioushealth = GetActorProperty( 0, APROP_Health);
 playerpreviousarmor = CheckInventory("Armor");
 delay (1);
 int thisgunmachinegunammo = CheckInventory("HeavyMachinegunAmmo");
 GiveActorInventory(261, "HeavyMachinegunAmmo", thisgunmachinegunammo);
 TakeInventory("HeavyMachinegunAmmo", 400);
 Thing_Move(0, 264, 1);
 UnMorphActor(0, 0);
 delay (1);
 TakeInventory("Armor", 999);
 SetActorProperty(0, APROP_Health, playerprevioushealth);
 GiveInventory("GiveArmor", playerpreviousarmor);
}


//Entering Tank
script "BDEnterTank" (VOID) NET
{
 delay(1);
 delay(5);
 SetActorAngle (0, GetActorAngle (261));
 Thing_Move(0, 261, 1);
 vehicleprevioushealth = GetActorProperty(261, APROP_Health);
 GiveInventory("StoredArmorInsideVehicle", playerpreviousarmor);
 GiveInventory("StoredHealthInsideVehicle", playerprevioushealth);
 SetActorProperty(0, APROP_Health, vehicleprevioushealth);
 int thisgunmachinegunammo = CheckActorInventory(261, "HeavyMachinegunAmmo");
 int thistankammo = CheckActorInventory(261, "TankAmmo");
 int thisvehicleHelicopterRocketAmmo = CheckActorInventory(261, "HelicopterRocketAmmo");
 int thisvehicleMechMortarAmmo = CheckActorInventory(261, "MechMortarAmmo");
 int thisvehicleMechLaserAmmo = CheckActorInventory(261, "MechLaserAmmo");
 int thisvehicleMechRocketAmmo = CheckActorInventory(261, "MechRocketAmmo");
 int vehiclepreviousbaseangle = CheckActorInventory(261, "TankBaseDirection");
 GiveInventory("HeavyMachinegunAmmo", thisgunmachinegunammo);
 GiveInventory("TankAmmo", thistankammo);
 GiveInventory("HelicopterRocketAmmo", thisvehicleHelicopterRocketAmmo);
 GiveInventory("MechMortarAmmo", thisvehicleMechMortarAmmo);
 GiveInventory("MechLaserAmmo", thisvehicleMechLaserAmmo);
 GiveInventory("MechRocketAmmo", thisvehicleMechRocketAmmo);
 SetUserVariable(0, "user_tankbasedirection", vehiclepreviousbaseangle);
 delay(1);
}

//leaving Tank
script "BDLeaveTank" (VOID) NET
{
 int thisgunmachinegunammo = CheckInventory("HeavyMachinegunAmmo");
 int thistankammo = CheckInventory("TankAmmo");
 int thisvehicleHelicopterRocketAmmo = CheckInventory("HelicopterRocketAmmo");
 int thisvehicleMechMortarAmmo = CheckInventory("MechMortarAmmo");
 int thisvehicleMechLaserAmmo = CheckInventory("MechLaserAmmo");
 int thisvehicleMechRocketAmmo = CheckInventory("MechRocketAmmo");
 vehicleprevioushealth = GetActorProperty(0, APROP_Health);
 int vehiclepreviousbaseangle = GetUserVariable(0, "user_tankbasedirection");
 TakeInventory("HeavyMachinegunAmmo", 9999);
 TakeInventory("TankAmmo", 9999);
 TakeInventory("HelicopterRocketAmmo", 9999);
 TakeInventory("MechRocketAmmo", 9999);
 TakeInventory("MechLaserAmmo", 9999);
 TakeInventory("MechMortarAmmo", 9999);
 Thing_Move(0, 264, 1);
 UnMorphActor(0, 0);
 delay (1);
 int resetarmor = CheckInventory("StoredArmorInsideVehicle");
 int resethealth = CheckInventory("StoredHealthInsideVehicle");
 SetActorProperty(0, APROP_Health, resethealth);
 GiveInventory("GiveArmor", resetarmor);
 SetActorProperty(261, APROP_Health, vehicleprevioushealth);
 GiveActorInventory(261, "HeavyMachinegunAmmo", thisgunmachinegunammo);
 GiveActorInventory(261, "TankAmmo", thistankammo);
 GiveActorInventory(261, "HelicopterRocketAmmo", thisvehicleHelicopterRocketAmmo);
 GiveActorInventory(261, "MechMortarAmmo", thisvehicleMechMortarAmmo);
 GiveActorInventory(261, "MechLaserAmmo", thisvehicleMechLaserAmmo);
 GiveActorInventory(261, "MechRocketAmmo", thisvehicleMechRocketAmmo);
 GiveActorInventory(261, "TankBaseDirection", vehiclepreviousbaseangle);
 SetActorProperty(261, APROP_Health, vehicleprevioushealth);
 TakeInventory("StoredHealthInsideVehicle", 9999);
 TakeInventory("StoredArmorInsideVehicle", 9999);
}

script "BDForceUnmorph" (VOID) NET
{
 UnMorphActor(0, 0);
}


//Set Tank's new base angle after you leave it.
script "BDSetBaseAngle" (VOID) NET
{
 delay (1);
 int thisvehiclecurrentbaseangle = CheckInventory("TankBaseDirection");
 delay (1);
 SpawnSpot("TankBaseStationed", 0, 0, thisvehiclecurrentbaseangle*256/360);
 delay (1);
}


//Set the current direction of a newly spawned tank.
script "BDSetNewTankDirection" (VOID) NET
{
 delay (1);
 int thisvehicleinitialbaseangle = GetActorAngle(0);
 int angleformulacalculation = thisvehicleinitialbaseangle >> 8;
 int angleformulacalculationlastpart = angleformulacalculation*360/256;
 delay (1);
 GiveInventory("TankBaseDirection", angleformulacalculationlastpart);
 delay (1);
}












Script "BDEnterTankInfo"(VOID)
{
setfont("TNHSA0");
	hudmessage(s:"A"; 
				HUDMSG_PLAIN, 0, CR_UNTRANSLATED, 0.5, 0.57, 1.0);
	delay(40 * 6);
}

Script "BDMechAmmoHUD"(VOID)
{
setfont("CONFONT");
 int mgunammo = CheckInventory("HeavyMachinegunAmmo");
	hudmessage(d: mgunammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.38, 0.80, 0.06);
 int rocketammo = CheckInventory("MechRocketAmmo");
	hudmessage(d: rocketammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.65, 0.80, 0.06);
int laserammo = CheckInventory("MechLaserAmmo");
	hudmessage(d: laserammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.38, 0.94, 0.06);	
int mortarammo = CheckInventory("MechMortarAmmo");
	hudmessage(d: mortarammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.65, 0.94, 0.06);	
int mechhealth = GetActorProperty(0, APROP_HEALTH);
	hudmessage(d: mechhealth; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.50, 0.96, 0.06);		
	delay(2);
}