GTA SAN ANDREAS
MODS for


Script structure and conditional checks
- The scripts which are running in GTA are called THREAD
- 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. - The cleo programm checks if there is a .CS
file in the Cleo folder
and if yes, it start this script as thread -
Script structur / short version
- At first, the head, it beginns with the Cleo directive
- First Label (adress)
- Then give the thread a name
- now put a code inthere which will doing something and then end_custom_thread
as last code
its ready then to test it ingame - 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 - A conditional check requires minimum 3 opcodes
- 1. the IF-variation details about IF-Variation, see below
- 2. the real question
- 3. the jump instruction by negation
1. if
2. 0AB0: key_pressed 8
3. 004D: jump_if_false @akt_01
- We use the previous script again but now we wonna be able to switch into normal view
- 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" - Important:
- The first opcode after such a Loop-adress must be the wait opcode
- mostly wait 0 millisecond
- the jump instruction can be a jump instruction by negation
- or also a normal jump instruction
- The conditional check of a key press in the script below should be passed by pressing BACKSPACE
- Script above activates the Infrarot view and toggle back to normal
view by key_press
- 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
- The reading process is looping as long as BACKSPACE is not pressed
- It is:
- 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: - - Script head
- - 1.Loop-Adress
- - wait code
- - IF player_defined-check
- - Conditional Check
- - Event
- - Normal jump instruction to 1.LoopAdress
- Script above activates the Infrarot view after key_press
and toggle back to normal view after 3 seconds - Script structure extended with 2 Loops:
- - Script head
- - 1.Loop-Adress
- - wait code
- - IF player_defined-check
- - Conditional Check
- - Event
- - 2.Loop-Adress
- - wait code
- - IF player_defined-check
- - Conditional Check
- - Normal jump instruction to 1.LoopAdress
- Youre not restricted by 2 Loops and there are also other kinds of script structure
- But I recommand to build your scripts with this structure as long as you have not much experience
- View picture to understand how a loop and conditional checks are executed
- Example Scripts:
- Screenshot
- Slowmotion
- First Person Camera
{$CLEO .cs}
:Akt
03A4: name_thread 'AKT'
{$CLEO .cs}
:Akt
03A4: name_thread 'AKT'
08B2: toggle_thermal_vision 1
0A93: end_custom_thread
Next step / using conditional checks
004D: jump_if_false @akt_01
{$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
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.
if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @Akt_01
{$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
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
{$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.
- maximum 7 condition in a conditional check are valid
- The most question codes can be changed into the opposite question
- exemble:
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
00E1: key_pressed 0 10
and
80E1: NOT key_pressed 0 11

- First Steps in Cleo Scripting with Sannybuilder
- Placing Cars by Using Parked_Car_Generator and Weapon Pickups
- The Editor Functions
- HELP
- Reading Coordinates of player poisition
- The Opcode
- DATA TYPE MEANING
- Special Particularities in Cleo
- mission script template
- Scripting/Writing a Thread - coding praxis - conditional checks
- Screenshot
- Slowmotion
- First Person Camera
INDEX
Example Scripts
