Script structure and conditional checks

  1. The scripts which are running in GTA are called THREAD
  2. They are defined in the main.scm as thread with the create_thread command or a mission script as mission
    As well the Extern scripts of script.img are also threads.
  3. The cleo programm checks if there is a .CS file in the Cleo folder
    and if yes, it start this script as thread
  4.  


     

  5. Script structur / short version

  6. At first, the head, it beginns with the Cleo directive
  7. {$CLEO .cs}
  8. First Label (adress)
  9. :Akt
  10. Then give the thread a name
  11. 03A4: name_thread 'AKT'
  12. now put a code inthere which will doing something and then end_custom_thread as last code
    its ready then to test it ingame
  13. {$CLEO .cs}
    :Akt
    03A4: name_thread 'AKT'
    08B2: toggle_thermal_vision 1
    0A93: end_custom_thread
  14. Script above activates the Infrarot view unless in cutscenes
    The script ends then, will be deactivated because it ends with opcode 0A93: end_custom_thread
    The script will be started by each loading of savegame or by start new game
  15.  

    Next step / using conditional checks

  16. A conditional check requires minimum 3 opcodes
  17. 1. the IF-variation details about IF-Variation, see below
  18. 2. the real question
  19. 3. the jump instruction by negation

    1. if

    2. 0AB0: key_pressed 8

    3. 004D: jump_if_false @akt_01

  20. We use the previous script again but now we wonna be able to switch into normal view
  21. Therefore we use a conditional check and build a "LOOP"
    Loop means that a jump instruction can send the reading process to a previous adress
    I call such an adress "Loop-adress"
  22.  

  23. Important:
  24. The first opcode after such a Loop-adress must be the wait opcode
  25. mostly wait 0 millisecond
  26.  

  27. the jump instruction can be a jump instruction by negation
  28. or also a normal jump instruction
  29. 004D: jump_if_false @akt_01

     

  30. The conditional check of a key press in the script below should be passed by pressing BACKSPACE
  31. {$CLEO .cs}
    :Akt
    03A4: name_thread 'AKT'
    08B2: toggle_thermal_vision 1
    
    :Akt_01//----------------------------Loop Adresse
    0001: wait 0 ms
    if
    0AB0:   key_pressed 8
    004D: jump_if_false @Akt_01//--------Sprunganweisung bei Verneinung
    08B2: toggle_thermal_vision 0
    0A93: end_custom_thread
  32. Script above activates the Infrarot view and toggle back to normal view by key_press
    1. The reading process is looping as long as BACKSPACE is not pressed
      the jump instruction by negation sends the reading process allways to the label :Akt_01
      1000 times per second

  33. Next Step/ Script structure simple

    The previous scripts ended because of the opcode 0A93: end_custom_thread
    Instead let the script ending we use a jump instruction at script end to the 1.Loop adress
    So the reading process is permanent looping

    0002: jump @Akt_01

    And since now we add a check in our loop which we add allways after a Loop adress.

  34. It is:
  35. if
    0256:   player $PLAYER_CHAR defined
    004D: jump_if_false @Akt_01
  36. It should prevent crashes if the player dies or gets arrested
    The "IF Player- Defined-check" should allway be the first check in a loop
    Script structure simple with 1 Loop:
  37. - Script head
  38. - 1.Loop-Adress
  39. - wait code
  40. - IF player_defined-check
  41. - Conditional Check
  42. - Event
  43. - Normal jump instruction to 1.LoopAdress
  44. {$CLEO .cs}
    :Akt
    03A4: name_thread 'AKT'
    
    :Akt_01
    0001: wait 0 ms
    if
    0256: player $PLAYER_CHAR defined
    004D: jump_if_false @Akt_01
    if
    0AB0:   key_pressed 8//-----------------key = Backspace
    004D: jump_if_false @Akt_01
    08B2: toggle_thermal_vision 1
    0001: wait 3000 ms
    08B2: toggle_thermal_vision 0
    0002: jump @Akt_01//--------Normal jump instruction to 1.LoopAdress
  45. Script above activates the Infrarot view after key_press
    and toggle back to normal view after 3 seconds
  46.  

    Next Step/ Script structure extended

    To start an event with our script will change the game state and the conditions.
    This needs to redirect the reading process to prevent that the same code will be read again.
    Therefore we add a second Loop in the script
    Loop 1 - before the event
    Loop 2 - after the event

  47. Script structure extended with 2 Loops:
  48. - Script head
  49. - 1.Loop-Adress
  50. - wait code
  51. - IF player_defined-check
  52. - Conditional Check
  53. - Event
  54. - 2.Loop-Adress
  55. - wait code
  56. - IF player_defined-check
  57. - Conditional Check
  58. - Normal jump instruction to 1.LoopAdress
  59. {$CLEO .cs}
    :akt
    03A4: name_thread 'AKT'
    
    :akt01//----------------------------1.Loop Adress
    0001: wait 0 ms
    if
    0256:   player $PLAYER_CHAR defined
    004D: jump_if_false @akt01
    if
    00DF:   actor $PLAYER_ACTOR driving
    004D: jump_if_false @akt01
    
    03C0: 1@ = actor $PLAYER_ACTOR car
    0229: set_car 1@ color_to 17 0
    02AC: set_car 1@ immunities BP 1 FP 1 EP 1 CP 1 MP 1
    053F: set_car 1@ tires_vulnerability 0
    
    
    :akt03//----------------------------2.Loop Adress
    0001: wait 0 ms
    if
    0256:   player $PLAYER_CHAR defined
    004D: jump_if_false @akt03
    if
    80DF:   not actor $PLAYER_ACTOR driving
    004D: jump_if_false @akt03
    
    01C3: remove_references_to_car 1@
    
    0002: jump @akt01//--------Normal jump instruction to 1.LoopAdress

    The script above makes the player_car undestructable as soon as a car is entered
    Therefore we must registrate the instance of the car and define it with a variable name
    03C0: 1@ = actor $PLAYER_ACTOR car
    Then we can use this variable name 1@ to make the car immun

    After player has left the car, the reading process jumps back into the first Loop.

  60. Youre not restricted by 2 Loops and there are also other kinds of script structure
  61. But I recommand to build your scripts with this structure as long as you have not much experience
  62. View picture to understand how a loop and conditional checks are executed
  63. Example Scripts:
  64. Screenshot
  65. Slowmotion
  66. First Person Camera

     

    The IF - Variation

    if
    00FF:   actor $PLAYER_ACTOR  1 (in-sphere)near_point_on_foot 2493.5  -1682.5  13.35 radius  1.0  1.0  1.0
    004D: jump_if_false @Teleport_2

    By more than one question in an conditional check requires to determine,
    if it means
    if or or if and

    if and
    00DF:   actor $PLAYER_ACTOR driving
    8119:   NOT   car 0@ wrecked
    004D: jump_if_false @AD_5
    if or
    00E1: key_pressed 0 0
    00E1: key_pressed 0 1
    00E1: key_pressed 0 14
    00E1: key_pressed 0 18
    004D: jump_if_false @AD_7
    if or
    8118:   NOT   actor 7@ dead
    8118:   NOT   actor 8@ dead
    004D: jump_if_false @AD_25
    0002: jump @AD_12
  1. maximum 7 condition in a conditional check are valid
  2. The most question codes can be changed into the opposite question
  3. exemble:
  4. 00E1: key_pressed 0 10 
    and
    80E1: NOT key_pressed 0 11

     


nothing
nothing