
If script>0 Then

	;Texte
	;Sterben
	If script=2 Then
		Color 255,0,0
		SetFont font_menu
		Text opt_sx/2, opt_sy/2-20, "Du bist gestorben!",1
		SetFont font_norm
		Text opt_sx/2, opt_sy/2, "< drücke Escape zum fortfahren >",1
	;Gewinnen
	ElseIf script=4 Then
		Color 0,255,0
		SetFont font_menu
		Text opt_sx/2, opt_sy/2-50, "Herzlichen Glückwunsch!",1
		Text opt_sx/2, opt_sy/2-30, "Du hast es geschafft die Insel zu verlassen",1
		Text opt_sx/2, opt_sy/2-10, "und nach Hause zu fahren!",1
		SetFont font_norm
		Text opt_sx/2, opt_sy/2+10, "< drücke Enter zum fortfahren >",1
	;Custom Mission: Gewinnen
	ElseIf script=5 Then
		Color 0,255,0
		SetFont font_menu
		Text opt_sx/2, opt_sy/2-20, "Gewonnen! Glückwunsch!",1
		SetFont font_norm
		Text opt_sx/2, opt_sy/2, "< drücke Escape zum fortfahren >",1
	;Custom Mission: Timeout
	ElseIf script=6 Then
		Color 255,0,0
		SetFont font_menu
		Text opt_sx/2, opt_sy/2-20, "Verloren! Zeit vorbei!",1
		SetFont font_norm
		Text opt_sx/2, opt_sy/2, "< drücke Escape zum fortfahren >",1

	EndIf
	

	If ms-script_timer>=25 Then
		speed# = (ms-script_timer)/25.00
		script_timer=ms
		
		Select script
		
		
			;Aufstehen
			Case 1
				EntityAlpha lspr, (100.0-script_timer2)/100.0
				RotateEntity camera, EntityPitch(camera),EntityYaw(camera),script_timer2-100
				PositionEntity camera, 95, 4.0+(script_timer2/20.0), 50
				If script_timer2=5 Then PlaySound sfx_standup
				If script_timer2=100 Then script_run(0)
				
			;Sterben
			Case 2
				EntityAlpha lspr, (script_timer2)/100.0
				If script_timer2=100 Then
					script_timer2=100
				EndIf
				If Not ChannelPlaying(sfx_track) Then
					sfx_track=PlaySound(sfx_track_gameover)
				EndIf
				ChannelVolume sfx_track, (script_timer2)/100.0
				If script_timer2=5 Then PlaySound sfx_die
				
			;Schlafen
			Case 3
				If script_timer2>100 Then
					If pl_tired>0 Then pl_tired=pl_tired-1
					If pl_tilebuild=2 And pl_tilebuildb=0 And pl_health<pl_health_max Then pl_health=pl_health+1
				EndIf
				If script_timer2<=100
					EntityAlpha lspr, (script_timer2)/100.0
				ElseIf script_timer2=101 Then
					PlaySound sfx_sleep
					sleep(1)
				ElseIf script_timer2>=200 Then
					EntityAlpha lspr, (300.0-script_timer2)/100.0
				EndIf
				If script_timer2=300 Then
					game_save("autosave",0)
					If (pl_health_cache-pl_health)<0 Then
						msg("Du hast geschlafen (0 Müde, +"+(-(pl_health_cache-pl_health))+" Energie)",1,1)
					Else
						msg("Du hast geschlafen (0 Müde, -"+(pl_health_cache-pl_health)+" Energie)",1,1)	
					EndIf
					script_run(0)
				EndIf
				
			;Gewinnen
			Case 4
				EntityAlpha lspr, (script_timer2)/100.0
				If script_timer2=100 Then
					script_timer2=100
				EndIf
				If Not ChannelPlaying(sfx_track) Then
					sfx_track=PlaySound(sfx_track_won)
				EndIf
				ChannelVolume sfx_track, (script_timer2)/100.0
				If script_timer2=1 Then PlaySound sfx_skill
				If KeyHit(28) Then
					StopChannel sfx_track
					clear()
					menu_set(10)
					Goto menu
				EndIf
				
			;Custom Mission: Gewinnen
			Case 5
				EntityAlpha lspr, (script_timer2)/100.0
				If script_timer2=100 Then
					script_timer2=100
				EndIf
				If Not ChannelPlaying(sfx_track) Then
					sfx_track=PlaySound(sfx_track_won)
				EndIf
				ChannelVolume sfx_track, (script_timer2)/100.0
				If script_timer2=5 Then PlaySound sfx_skill

			;Custom Mission: Timeout
			Case 6
				EntityAlpha lspr, (script_timer2)/100.0
				If script_timer2=100 Then
					script_timer2=100
				EndIf
				If Not ChannelPlaying(sfx_track) Then
					sfx_track=PlaySound(sfx_track_gameover)
				EndIf
				ChannelVolume sfx_track, (script_timer2)/100.0
				If script_timer2=5 Then PlaySound sfx_die

			;Mit Rakete davonfliegen
			Case 7
				If script_timer2 > 50
					MoveEntity pl_tilebuildm,0,(script_timer2-50)/60,0
				Else
					MoveEntity camera,0,0,-0.5
				EndIf
				If Not ChannelPlaying(sfx_rocketc)
					sfx_rocketc = PlaySound(sfx_rocket)
				EndIf
				ChannelVolume sfx_rocketc,Float(script_timer2)/EntityDistance#(camera,pl_tilebuildm)
				If Rand(0,1+30/script_timer2)=1 Then effect_puff(EntityX(pl_tilebuildm)+Rnd(-6,6),EntityY(pl_tilebuildm)+Rnd(3,6),EntityZ#(pl_tilebuildm)+Rnd(-6,6),Rnd(4,10),Rand(200,250),Rand(130,190),Rand(50,130),Rnd(.6,1),Rnd(-.1,.2))
				PointEntity camera,pl_tilebuildm
				If script_timer2>=350 Then script_run(4)			
		
		 End Select
		script_timer2=script_timer2+1
	EndIf
EndIf