{$CLEO .cs}
0000: NOP
// MASTER SAYED - Mortal Kombat Tournament v2.1 Fixed
// F5 = Start Tournament manually
// Auto-starts at random hour when near the arena
// Map blip shows the arena location

// Arena center
0007: 1@ = 2494.0
0007: 2@ = -1687.0
0007: 3@ = 13.5

// Opponent spawn point
0007: 5@ = 2498.0
0007: 6@ = -1687.0
0007: 7@ = 13.5

0006: 31@ = 0      // state: 0 = idle, 1 = waiting for hit, 2 = fighting
0006: 30@ = 0      // opponent actor
0006: 29@ = 0      // current round
0006: 28@ = 0      // health baseline
0006: 27@ = 0
0006: 25@ = 0      // spectators flag
0006: 24@ = 0      // blip handle
0006: 23@ = 0      // auto schedule flag
0006: 21@ = 0      // target hour

// Create map blip
018A: 24@ = create_checkpoint_at 1@ 2@ 3@
0165: set_marker 24@ color_to 1
016B: set_marker 24@ radar_icon_to 20

:MAIN
0001: wait 200
00D6: if 0
0256: player $PLAYER_CHAR defined
004D: jump_if_false @MAIN
01F5: 16@ = player $PLAYER_CHAR actor

// ========== F5 Manual Start ==========
00D6: if 0
0AB0: key_pressed 116          // F5
004D: jump_if_false @CHECK_AUTO
00D6: if 0
0038: 31@ == 0
004D: jump_if_false @MAIN
0001: wait 300
0050: gosub @START_TOURNAMENT
0002: jump @MAIN

// ========== Auto Start System ==========
:CHECK_AUTO
00D6: if 0
0038: 23@ == 0
004D: jump_if_false @CHECK_TIME

// Schedule random hour (10 to 22)
0209: 21@ = random_int_in_ranges 10 23
0006: 23@ = 1

:CHECK_TIME
00D6: if 0
0038: 31@ == 0
004D: jump_if_false @STATE_MACHINE
00D6: if 0
0038: 23@ == 1
004D: jump_if_false @STATE_MACHINE

// Must be near the arena
00D6: if 0
00FE: actor 16@ sphere 0 in_sphere 1@ 2@ 3@ radius 80.0 80.0 30.0
004D: jump_if_false @STATE_MACHINE

// Check current hour
00BF: get_time_of_day 17@ 18@
00D6: if 0
003B: 17@ == 21@
004D: jump_if_false @STATE_MACHINE

0ACD: show_text_highpriority "MORTAL KOMBAT TOURNAMENT STARTING!" 4000
0001: wait 2000
0050: gosub @START_TOURNAMENT
0006: 23@ = 0
0002: jump @MAIN

// ========== State Machine ==========
:STATE_MACHINE
00D6: if 0
0038: 31@ == 0
004D: jump_if_false @STATE_WAIT
0002: jump @MAIN

:STATE_WAIT
00D6: if 0
0038: 31@ == 1
004D: jump_if_false @STATE_ACTIVE

00D6: if 0
056D: actor 30@ defined
004D: jump_if_false @CLEANUP

00D6: if 0
0118: actor 16@ dead
004D: jump_if_false @WAIT_OK
0002: jump @TOURNAMENT_LOST

:WAIT_OK
00D6: if 0
00FE: actor 16@ sphere 0 in_sphere 1@ 2@ 3@ radius 50.0 50.0 15.0
004D: jump_if_false @CANCEL

0226: 27@ = actor 30@ health
00D6: if 0
0039: 27@ == 28@
004D: jump_if_false @START_FIGHT
0002: jump @MAIN

:START_FIGHT
0006: 31@ = 2
0ACD: show_text_highpriority "FIGHT!" 2000
05E2: AS_actor 30@ kill_actor 16@
0002: jump @MAIN

:STATE_ACTIVE
00D6: if 0
0038: 31@ == 2
004D: jump_if_false @MAIN

00D6: if 0
0118: actor 16@ dead
004D: jump_if_false @PLAYER_ALIVE
0002: jump @TOURNAMENT_LOST

:PLAYER_ALIVE
00D6: if 0
00FE: actor 16@ sphere 0 in_sphere 1@ 2@ 3@ radius 45.0 45.0 15.0
004D: jump_if_false @FORCE_RETURN

00D6: if 0
056D: actor 30@ defined
004D: jump_if_false @ROUND_WON
00D6: if 0
0118: actor 30@ dead
004D: jump_if_false @MAIN
0002: jump @ROUND_WON

:FORCE_RETURN
00A1: put_actor 16@ at 1@ 2@ 3@
0ACD: show_text_highpriority "NO ESCAPE!" 1500
0002: jump @MAIN

:ROUND_WON
0ACD: show_text_highpriority "ROUND WON!" 2000
0050: gosub @REMOVE_OPPONENT
00D6: if 0
0038: 29@ >= 5
004D: jump_if_false @NEXT_ROUND
0ACD: show_text_highpriority "TOURNAMENT CHAMPION!" 4500
0001: wait 4500
0002: jump @COMPLETE

:NEXT_ROUND
000A: 29@ += 1
0001: wait 2200
0050: gosub @SPAWN_OPPONENT
00D6: if 0
0038: 30@ == 0
004D: jump_if_false @NEXT_READY
0002: jump @TOURNAMENT_LOST

:NEXT_READY
0006: 20@ = 150
00D6: if 0
0038: 29@ == 2
004D: jump_if_false @H3
0006: 20@ = 230
:H3
00D6: if 0
0038: 29@ == 3
004D: jump_if_false @H4
0006: 20@ = 320
:H4
00D6: if 0
0038: 29@ == 4
004D: jump_if_false @H5
0006: 20@ = 450
:H5
00D6: if 0
0038: 29@ == 5
004D: jump_if_false @HSET
0006: 20@ = 1000
0ACD: show_text_highpriority "FINAL BOSS!" 3000
:HSET
0223: set_actor 30@ health_to 20@
0226: 28@ = actor 30@ health
0006: 31@ = 1
0ACD: show_text_highpriority "HIT TO START NEXT ROUND" 2500
0002: jump @MAIN

:CANCEL
0050: gosub @REMOVE_OPPONENT
0050: gosub @REMOVE_SPECTATORS
0006: 31@ = 0
0006: 29@ = 0
0ACD: show_text_highpriority "TOURNAMENT CANCELLED" 2500
0002: jump @MAIN

:TOURNAMENT_LOST
0ACD: show_text_highpriority "FATALITY! YOU LOST" 4000
0001: wait 4000
0050: gosub @REMOVE_OPPONENT
0050: gosub @REMOVE_SPECTATORS
0006: 31@ = 0
0006: 29@ = 0
0002: jump @MAIN

:COMPLETE
0050: gosub @REMOVE_OPPONENT
0050: gosub @REMOVE_SPECTATORS
0006: 31@ = 0
0006: 29@ = 0
0002: jump @MAIN

:CLEANUP
0050: gosub @REMOVE_OPPONENT
0050: gosub @REMOVE_SPECTATORS
0006: 31@ = 0
0006: 29@ = 0
0002: jump @MAIN

// ========================
:START_TOURNAMENT
0006: 29@ = 1
0006: 31@ = 1
0050: gosub @SPAWN_SPECTATORS
0050: gosub @SPAWN_OPPONENT
00D6: if 0
0038: 30@ == 0
004D: jump_if_false @START_OK
0006: 31@ = 0
0050: gosub @REMOVE_SPECTATORS
0051: return

:START_OK
0223: set_actor 30@ health_to 150
0226: 28@ = actor 30@ health
0ACD: show_text_highpriority "ROUND 1 - HIT TO START" 3000
0051: return

// ========================
:SPAWN_OPPONENT
0006: 30@ = 0
0209: 22@ = random_int_in_ranges 0 256
0085: 20@ = 22@
000A: 20@ += 19000
00D6: if 0
0038: 20@ == 19141
004D: jump_if_false @SO_LOAD
0006: 20@ = 19140

:SO_LOAD
0050: gosub @LOADMODEL
00D6: if 0
0038: 10@ == 0
004D: jump_if_false @SO_FALLBACK
0002: jump @SO_CREATE

:SO_FALLBACK
0249: release_model 20@
0006: 20@ = 7
0050: gosub @LOADMODEL
00D6: if 0
0038: 10@ == 0
004D: jump_if_false @SO_FAIL

:SO_CREATE
009A: 30@ = create_actor_pedtype 4 model 20@ at 5@ 6@ 7@
0249: release_model 20@
0051: return

:SO_FAIL
0249: release_model 20@
0051: return

// ========================
:LOADMODEL
0006: 10@ = 0
0006: 9@ = 400
0247: load_model 20@
:LM_WAIT
0001: wait 0
00D6: if 0
0248: model 20@ available
004D: jump_if_false @LM_NOT
0051: return
:LM_NOT
000E: 9@ -= 1
00D6: if 0
0018: 9@ > 0
004D: jump_if_false @LM_FAIL
0002: jump @LM_WAIT
:LM_FAIL
0006: 10@ = 1
0051: return

// ========================
:SPAWN_SPECTATORS
0006: 25@ = 0
0006: 20@ = 7
0050: gosub @LOADMODEL
00D6: if 0
0038: 10@ == 0
004D: jump_if_false @SS_END

009A: 8@ = create_actor_pedtype 4 model 20@ at 2490.0 -1684.0 13.5
009A: 9@ = create_actor_pedtype 4 model 20@ at 2490.0 -1690.0 13.5
009A: 11@ = create_actor_pedtype 4 model 20@ at 2500.0 -1684.0 13.5
009A: 12@ = create_actor_pedtype 4 model 20@ at 2500.0 -1690.0 13.5

0249: release_model 20@
0006: 25@ = 1
:SS_END
0051: return

:REMOVE_SPECTATORS
00D6: if 0
0038: 25@ == 0
004D: jump_if_false @RS_DO
0051: return
:RS_DO
00D6: if 0
056D: actor 8@ defined
004D: jump_if_false @RS1
009B: destroy_actor_instantly 8@
:RS1
00D6: if 0
056D: actor 9@ defined
004D: jump_if_false @RS2
009B: destroy_actor_instantly 9@
:RS2
00D6: if 0
056D: actor 11@ defined
004D: jump_if_false @RS3
009B: destroy_actor_instantly 11@
:RS3
00D6: if 0
056D: actor 12@ defined
004D: jump_if_false @RS_END
009B: destroy_actor_instantly 12@
:RS_END
0006: 25@ = 0
0051: return

:REMOVE_OPPONENT
00D6: if 0
0038: 30@ == 0
004D: jump_if_false @RM_DO
0051: return
:RM_DO
00D6: if 0
056D: actor 30@ defined
004D: jump_if_false @RM_END
009B: destroy_actor_instantly 30@
:RM_END
0006: 30@ = 0
0051: return