Special Particularities in Cleo

  1. CLEO OPCODES

  2. The extra-Cleo opcodes can be found in Sannybuilder-HELP
  3. CLEO 3 Code Library >> CLEO 3: opcodes CLEO 3 Code Library>> CLEO 3: opcodes
  4.  

  5. CLEO4 opcodes can be found in opcodes.txt which comes with sannybuilder update files by installion of cleo4
  6. or download my opcodes.txt and put it in Sannybuilder installation directory\data\sa
  7. then you have everything for your opcode search

  8. Two major codes to start scripts are those which already exist in the main.scm and have been re-created for Cleo:
  9. 1.) 004F: create_thread @SAVEGAME starts an ordinary thread in the main.scm.
    We dont need it in Cleo because it will be allready started from Cleo programm
    To start an other thread of a cleo script, started from a cleo script needs following opcode:
    0A92: create_custom_thread "New_Test_thread.cs"
    The code needs to insert the name of the script file which should get started inclusiv dot and extension
  10. The Cleo script file get then the file extension, which is written in the Cleo Script directive at the beginning of the script
  11. {$CLEO .cs} = Cleo directive will be compiled to *.cs
    As New_Test_thread.txt saved and compiled as New_Test_thread.cs
  12. The script get then started at second once. Once from Cleo programm and once from the 0A92: create_custom_thread
    It needs to set a conditional check at script beginn to let the script ending when it was started from Cleo programm.
  13. An other chance is to give the script the extension.S
    This needs to insert following:
    0A92: create_custom_thread "New_Test_thread.s"
    The Cleo script file which should get started, must have {$CLEO .cs} as directive and will be compiled as *.cs
    You must change the extension manual by renaming from .CS in .S
    In this case the Cleo script will only run if it was started with 0A92: create_custom_thread from another Cleo script.
  14. The opcode 0A92: create_custom_thread can transport more information to the script which should be started
    This opcode can be extended with up to 30 values or variables as parameters
    exemble:
    0A92: create_custom_thread "PimpmyCarFULL2A1.cs" 1 2 0 3@ 4@ 5@ 6@ 29@ 8@ 9@ 10@
    The started thread recieves these parameter values with following rule
    0@ get value of 1.parameter
    1@ get value of 2.parameter
    2@ get value of 3.parameter
    3@ get value of 4.parameter
    4@ get value of 5.parameter
    and so on
    Its also possible to start much threads in one and the same Cleo script, started from the same script which recieve the create_thread commands.
  15.  

     

  16. 2.) 0417: start_mission 3 starts a mission script of the main.scm.
    It needs to insert the number which the mission script get from the listing of the mission table
    It's also possible to do it with a cleo script
  17. For Cleo mission scripts dont exist a mission table and its listing,
    but it needs allways a Cleo mission starter script with following command:
    0A94: start_custom_mission "DriftMission"
    The code needs to insert the name of the script file which should get started but without extension
  18.  

  19. The Cleo script file get then the file extension, which is written in the Cleo Script directive at the beginning of the script
  20. {$CLEO .cm} = Cleo directive will be compiled to *.cm
    As DriftMission.txt saved and compiled as DriftMission.cm
  21. script template, see below


  22. 0A93: end_custom_thread let a script ending. Its disabled then.
    The original version of this code of the main.scm is 004E: end_thread
    And this original version must be used furthermore in Cleo mission scripts (*.cm)
    004E: end_thread
  23.  

  24. Again:
  25. 0A93: end_custom_thread in normal Cleo scripts, compiled to a *.cs file
  26. {$CLEO .cs}
    0A93: end_custom_thread
  27. 004E: end_thread in mission scripts, compiled to a *.cm file
  28. {$CLEO .cm}
    004E: end_thread


    Cleo creates extra save files if a save was done, stored in folder CLEO\Cleo_save

    By loading a save file must taken care to check that the presence of the scripts in Cleo folder is the same as it was as the save was done.
    Special attention in this case are going to those scripts which includes the Cleo opcode to registrate and store the Script State

     


    Registrate (store) the Script State

    The Cleo scripts with extension .cs are started allways from new by loading a save game or start new game,
    If such a script includes for exemble a parked car generator and execute it and after this a save game is made,
    and then this save game is loaded,
    will be created a duplicate of the item, in this case a duplicate of a parked car generator.
    This happens with parked car generator, pickups as well as placed objects.

    To prevent this or to read the script state by using special special Cleo-variable
    must be used following Cleo opcode:

    0A95: enable_thread_saving

    This instruct Cleo to store the script state by making a savegame


    Special Global Cleo Variable

    This theme requires the understanding of the description about Local Variables and Global Variables
    of the theme DATA TYPE MEANING

     

    To realize Global Variables for Cleo scripts exist following Cleo opcode connected with a special expression:

    Opcode 0AB3: and 0AB4:

    The expression var together with a number, <var><space><number> is building the Special Global Cleo Variable

    0AB3: var 0 = 10
    or
    0006: 13@ =  10  // integer values
    0AB3: var 0 = 13@
    
    and
    0AB4: 0@= var 0

    var 0 up to var 999 will be stored, in exemble var 0 is stored with 10

    to get then stored value into your script needs to submit into a local:

    0AB4: 13@ = var 44
    if
    0039:   13@ ==  1  // integer values
    004D: jump_if_false @nextlabel


    Template for Cleo Mission Script

    (requires to understand all previous themes of this tut)

    To run a Cleo mission script requires allways 2 Cleo script files
    1. A .cs file to start the Cleo mission script file
    2. The Cleo mission script file itself with extension .cm
    The mission starter thread below is done with a conditional check to check if the player is near a specified point,
    which must passed to start the mission.

    The coordinates of the near_point check are the location in San Fierro/Carlton Heights near savehouse
    Edit the coordinates to set your own location for starting

    The parameter 1 of the near_point opcode 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point
    is displaying a red marker (sphere).
    If the parameter is zero 00FE: actor $PLAYER_ACTOR 0 (in-sphere)near_point does not displaying a red marker.
    To display a red marker in this way needs to set 0ms as maximum in the wait code of this Loop

    {$CLEO .cs}
    :Test_M_Start_1
    03A4: name_thread 'TSTM'
    
    :Test_M_Start_2
    0001: wait  0 ms
    00D6: if  0
    0256:   player $PLAYER_CHAR defined
    004D: jump_if_false @Test_M_Start_2
    00D6: if  0
    0038:   $ONMISSION ==  0  // integer values
    004D: jump_if_false @Test_M_Start_2
    
    :Test_M_Start_6
    00D6: if  0
    00FE:   actor $PLAYER_ACTOR  1 (in-sphere)near_point 2480.1343 -1665.475 13.3348 radius  3.5  3.5  5.5
    004D: jump_if_false @Test_M_Start_2
    00BA: text_styled 'STAD_02'  1000 ms  2
    0004: $ONMISSION =  1  // integer values
    0A94: start_custom_mission "TestMission"  //
    0002: jump @Test_M_Start_2

     

    The mission starter script includes the following Cleo opcode to start the Cleo mission script:
    0A94: start_custom_mission "TestMission"
    The code needs to insert the name of the script file which should get started but without extension

    The Cleo script file get then the file extension, which is written in the Cleo Script directive at the beginning of the script
    {$CLEO .cm} = Cleo directive will be compiled to *.cm
    As TestMission.txt saved and compiled as TestMission.cm

    {$CLEO .cm}
    :TestMiss_1
    03A4: name_thread "TESTM"  
    0050: gosub @TestMiss_main_1
    00D6: if  0
    0112:   wasted_or_busted
    004D: jump_if_false @TestMiss_end_1
    0050: gosub @TestMiss_fail_1                    
    
    :TestMiss_end_1
    0050: gosub @TestMiss_clep_1
    004E: end_thread
    
    :TestMiss_main_1
    0317: increment_mission_attempts//here starts the missionscript
    0004: $ONMISSION =  1
    054C: use_GXT_table 'MENU2P'
    00BC: text_highpriority 'MENU_18'  5000 ms  1
    
    :TestMiss_11
    0001: wait 0 ms
    if and
    02D8:   actor $PLAYER_ACTOR currentweapon == 0
    00E1:   key_pressed 0 17
    004D: jump_if_false @TestMiss_11
    
    :TestMiss_pass_1
    00BA: text_styled 'M_PASS'  5000 ms  1
    0051: return
    
    :TestMiss_fail_1
    00BA: text_styled 'M_FAIL'  5000 ms  1
    0051: return
    
    :TestMiss_clep_1
    0004: $ONMISSION =  0
    00D8: mission_cleanup
    0051: return
  29. When the mission script from above is running it can be completed by pressing fire key while player have weapon 0/naked fist.
  30.  

    Further advising for making proper mission scripts

  31. $ONMISSION is not only a variable to check if a mission script is running or not.
    Set $ONMISSION to 1 activates a special mission mode if some important conditions are accomplished.
    R*s mission scripts run allways in a subroutine which will be cancled from the exe if player is wasted or busted like reading a return code in the script.
  32. 1. At first it needs to set $ONMISSION equal to on_mission_flag
  33. 0180: set_on_mission_flag_to $ONMISSION// Note: your missions have to use the variable defined here
  34. This code is set by default in the main part of the original main.scm
  35.  

  36. 2. By starting the mission script must the reading process be sended with a gosub command into a subroutine for the main part of the mission script.
    It must be the first gosub of the mission script.
  37. 0050: gosub @TestMiss_main_1

     

  38. 3. By starting the mission script must be activated the onmission mode with
  39. 0004: $ONMISSION =  1
    0317: increment_mission_attempts//here starts the missionscript
  40. Then the mission is running in a subroutine and dont needs to check if player is defined or dead or busted.
    If player dies or get busted, the exe cancels the subroutine as like as a return code of our script is readed
  41. The rest of the mission script is just a cunning gosub construct.
  42. gosub

  43. The gosub command leads the reading process to an excluded subscript.
    Excluded means the codes of the subscript are not binded in code following of our thread.
  44. 0050: gosub @MODLSUBROUTINE
  45. The subscript must end with return
  46. 0051: return

     

  47. If the subscript ends with 0051: return, our thread then continues with reading the codes after the 0050: gosub command
    example:
  48. {$CLEO .cs}
    :MODLSUB_1
    03A4: name_thread 'MODLSUB'
    
    :MODLSUB_2
    0001: wait  0 ms
    00D6: if  0
    0256:   player $PLAYER_CHAR defined
    004D: jump_if_false @MODLSUB_2
    00D6: if  0
    00FF:   actor $PLAYER_ACTOR  1 (in-sphere)near_point_on_foot 2491.5  -1667.5  13.35 radius  1.0  1.0  1.0
    004D: jump_if_false @MODLSUB_2
    0050: gosub @MODLSUBROUTINE
    
    :Loop_1
    0001: wait  0 ms
    00D6: if  0
    8118:   NOT   actor 1@ dead
    004D: jump_if_false @Cleanup_1
    00D6: if  0
    0104:   actor $PLAYER_ACTOR near_actor 1@ radius  80.0  80.0  10.0 sphere  0
    004D: jump_if_false @Cleanup_1
    0002: jump @Loop_1
    
    :Cleanup_1
    01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
    0002: jump @MODLSUB_2
    
    
    :MODLSUBROUTINE
    0005: 1@ = 2473.25
    0005: 2@ = -1657.79
    0005: 3@ = 13.4
    0005: 4@ = 2501.12
    0005: 5@ = -1676.5
    0005: 6@ = 13.4
    0208: 7@ = random_float_in_ranges 1@ 4@
    0208: 8@ = random_float_in_ranges 2@ 5@
    0208: 9@ = random_float_in_ranges 3@ 6@
    0247: request_model #TRIBOSS
    0247: request_model #AK47
    
    :Load_MODLSUB_Check
    0001: wait  0 ms
    00D6: if  and
    0248:   model #TRIBOSS available
    0248:   model #AK47 available
    004D: jump_if_false @Load_MODLSUB_Check
    
    009A: 1@ = create_actor  24 #TRIBOSS at  7@ 8@ 9@
    0173: set_actor 1@ z_angle_to  180.0
    01B2: give_actor 1@ weapon  30 ammo  99999  // Load the weapon model before using this
    02E2: set_actor 1@ weapon_accuracy_to  100
    0223: set_actor 1@ health_to  1000
    05E2: AS_actor 1@ kill_actor $PLAYER_ACTOR
    0249: release_model #TRIBOSS
    0051: return 
  49. Script above spawns the actor Triboss with gun in Grovestreet at different places
    The coords are generated random
    The part with the coords generation and actor spawn is excluded in a subscript
  50. If player leave the area with radius 80.0 80.0 or if the actor is dead,
    the actor will be released from script and the reading process jumps back into 1.Loop
  51.  

nothing
nothing