
; some variables
_plane1 = _this select 0
_player = player
after=false

;init=[_this select 0] exec "\BWC_MIII\scr\auto.sqs"
#start 
;check if it is player or AI in plane
;If AI this loops
;if plane is Empty this loops until Player is in plane or
;until plane is destroyed 
	_Inplane = _player in _plane1
	_GetDamage = getdammage _plane1
	?(_getdamage>=0.9) : goto "exit"
	~0.0001

;hint format["Is Player in Plane? %1",_InPLane]
	?(_player in _plane1): goto "again"

goto "Start"


;Main Loop
#again
; check if vehicle is dammaged, if not then go to end
	_GetDamage = getdammage _plane1
	? (alive _plane) : goto "exit"
; set the texture dor the afterburner to off (Transparency)
	_plane1 setobjecttexture[0, ""]
	_plane1 animate ["Nozzle1", 0];
	_plane1 animate ["Nozzle2", 0];
	_plane1 animate ["Nozzle3", 0];
	_plane1 animate ["Nozzle4", 0];
	_plane1 animate ["Nozzle5", 0];
	_plane1 animate ["Nozzle6", 0];
	_plane1 animate ["Nozzle7", 0];
	_plane1 animate ["Nozzle8", 0];
	_plane1 animate ["Nozzle9", 0];
	_plane1 animate ["Nozzle10", 0];
; check whether the engine is on or off. If on then got to next loop, other wise continue in this loop
?(isengineon _plane1): goto "next" 
	goto "again"
; end of main loop

;Next loop
	#next
~2.5

; Add user action and go to burner on script
	AfterAct = _plane1 addAction ["Afterburner On","\BWC_MIII\scr\burner2.sqs"]
#Repeat
	~0.0001
?!(after):goto "EngineOff"
	@(after)
	~0.1

	
; Add user action to cancel the Afterburner
	cancelafterAct = _plane1 addAction ["Cancel Afterburner","\BWC_MIII\scr\cancelafter.sqs"] 
~0.1
; remove the Afterburner On user cation
	_plane1 removeaction AfterAct;
;Nested loop
#again2
	~0.1
; check that the engine is off
;?!(isengineon _plane1): goto "engineoff"
; Check that variable After returns false, if it doesn't repeat nested loop until it does
	?(after) : goto "engineoff2";
; remove the Cancel Afterburner Action
	_plane1 removeaction cancelAfteract;
; return to main loop
goto "again";


#EngineOff
?(isengineon _plane1):goto "repeat"
	_plane1 removeaction cancelAfteract;
	_plane1 removeaction Afteract;
	_plane1 setobjecttexture[0, ""]
	_plane1 animate ["Nozzle1", 0];
	_plane1 animate ["Nozzle2", 0];
	_plane1 animate ["Nozzle3", 0];
	_plane1 animate ["Nozzle4", 0];
	_plane1 animate ["Nozzle5", 0];
	_plane1 animate ["Nozzle6", 0];
	_plane1 animate ["Nozzle7", 0];
	_plane1 animate ["Nozzle8", 0];
	_plane1 animate ["Nozzle9", 0];
	_plane1 animate ["Nozzle10", 0];
;after=false;
goto "Again"

#EngineOff2
?(isengineon _plane1):goto "again2"
	_plane1 removeaction cancelAfteract;
	_plane1 removeaction Afteract;
	_plane1 setobjecttexture[0, ""]
	_plane1 animate ["Nozzle1", 0];
	_plane1 animate ["Nozzle2", 0];
	_plane1 animate ["Nozzle3", 0];
	_plane1 animate ["Nozzle4", 0];
	_plane1 animate ["Nozzle5", 0];
	_plane1 animate ["Nozzle6", 0];
	_plane1 animate ["Nozzle7", 0];
	_plane1 animate ["Nozzle8", 0];
	_plane1 animate ["Nozzle9", 0];
	_plane1 animate ["Nozzle10", 0];
after=false;
goto "Again"

#Exit
; sets the afterburner to off
	_plane1 setobjecttexture[0, ""]
	_plane1 animate ["Nozzle1", 0];
	_plane1 animate ["Nozzle2", 0];
	_plane1 animate ["Nozzle3", 0];
	_plane1 animate ["Nozzle4", 0];
	_plane1 animate ["Nozzle5", 0];
	_plane1 animate ["Nozzle6", 0];
	_plane1 animate ["Nozzle7", 0];
	_plane1 animate ["Nozzle8", 0];
	_plane1 animate ["Nozzle9", 0];
	_plane1 animate ["Nozzle10", 0];
~0.1
exit