SYNTAX

["Open" COMMAND]... ["Close" COMMAND]

There're several "Open" commands as well as several operators, especially conditions and allways does it need to close the function by a "Close" command

END = ["Close" COMMAND]

the construct of commands must always be closed by END
unless for a few exeptions with another
"Close" COMMAND

 

LOOP Construct:

A loop is a statement which allows code to be repeatedly executed
We use following as standart main loop

WHILE ["Open" COMMAND] true [loop-condition]
...
END ["Close" COMMAND]

Important rule for gta engine:
Every loop must have a wait of at least 0, as the rest of the game is processed and rendered during those waits

WHILE ["Open" COMMAND] true [loop-condition]
wait 0
END ["Close" COMMAND]

 

 

CONDITIONAL CHECK Construct

There is the operator IF to evaluate the condition.

IF ["Open" COMMAND]
..
THEN
..
END ["Close" COMMAND]

 

A condition is created by the rules described above.

After the word THEN, you have to specify the command(-s) that are executed if the condition is true.

IF..THEN..END

After the word ELSE, you have to specify the command(-s) that are executed if the condition is false.

IF..THEN..ELSE..END

 

 

Let's write a simple script
The plan: if player spawn at gameload between 18:00 and midnight, then enables infrared_vision
____

Opcode 00BF: returns the game time, we only need to check the hours = 1@

The running thread instance will be terminated after one second by 0A93: end_custom_thread

The construct for conditional check:

if
then
end

{$CLEO .cs}
thread 'IVISION'
wait 1000
00BF: 1@ = current_time_hours, 0@ = current_time_minutes

if
    1@ > 17
then
    08B2: set_infrared_vision 1
end

0A93: end_custom_thread
	

LOOP Construct:

Basic loop cunstruct instead of end_custom_thread

WHILE true
...
END

Script example below displays the internal timer on screen

only three codes inside the loop
wait 0 as first
then two codes for displaying the timer value


{$CLEO .cs}
thread 'timer'
33@ = 0

while true
    wait 0
    03F0: enable_text_draw 1 
    045A: draw_text_1number 100.0  200.0 GXT 'NUMBER' number 33@
end
	

LOOP Construct:

Basic loop and one conditional check

if internal timer is bigger than 7000,
then reset timer to 0

 

After the word THEN, you have to specify the command(-s) that are executed if the condition is true.
IF..THEN..END

After the word ELSE, you have to specify the command(-s) that are executed if the condition is false.
IF..THEN..ELSE..END

Script example below displays the internal timer on screen

only three codes inside the loop
wait 0 as first
then two codes for displaying the timer value


{$CLEO .cs}
thread 'timer'
while true
    wait 0
    03F0: enable_text_draw 1 
    045A: draw_text_1number 100.0  200.0 GXT 'NUMBER' number 33@
    if
        33@ > 7000
    then
        33@ = 0
    end
end
	

The local variables 32@ and 33@ are reserved for the use as internal timer that counts permanently up in milliseconds
They can't be used for anything else, but we can restore it to 0 and then check if specified time goes by

if
    33@ > 7000
then
    33@ = 0
end
	

extend the conditional check by argument "else"

if
..[condition] i key is pressed
then
..[code]enables infrared_vision
else
..[code]disables infrared_vision
end


{$CLEO .cs}
thread 'IVISION'


while true
    wait 0
    if
        0AB0:   key_pressed 73// 	i key
    then
        08B2: set_infrared_vision 1
    else    
        08B2: set_infrared_vision 0
    end
end
	

 

The Syntax allows to build constructs into each other

Each construct requires the END["Close" COMMAND] at right place to lock the right content in
it needs to close first the the construct of the deepest level, then these of the next upper level


while true
    wait 0 
    if 
        0256:   player $PLAYER_CHAR defined
    then
        if
        then
        else 
            if 
            then
            else 
                if 
                then
                end        
            end
        end
    end   
end
	

Or collect conditional checks below of each other
Example below does same as the one above additional with operator "OR"


while true
    wait 0 
    if 
        0256:   player $PLAYER_CHAR defined
    then
        if or
        then
        end    
        if or
        then
        end        
    end   
end
	

 

After the word THEN, you have to specify the command(-s) that are executed if the condition is true.
IF..THEN..END

After the word ELSE, you have to specify the command(-s) that are executed if the condition is false.
IF..THEN..ELSE..END

Script example below gives paintjob to car model blade and carcolor to car model ALPHA and BULLET
when player is driving specified car model

 


{$CLEO .cs}
thread 'PAINT' 

while true
    wait 0 
    if 
        0256:   player $PLAYER_CHAR defined
    then
        if 
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #blade
        then
            03C0: 0@ = actor $PLAYER_ACTOR car
            06ED: set_car 0@ paintjob 0
            wait 1000
            06ED: set_car 0@ paintjob 1
            wait 1000
        else 
            if 
                00DD:   actor $PLAYER_ACTOR driving_car_with_model #ALPHA
            then
                03C0: 0@ = actor $PLAYER_ACTOR car
                0229: set_car 0@ primary_color_to 17 secondary_color_to 0
                wait 1000
            else 
                if 
                    00DD:   actor $PLAYER_ACTOR driving_car_with_model #BULLET
                then
                    03C0: 0@ = actor $PLAYER_ACTOR car
                    0229: set_car 0@ primary_color_to 0 secondary_color_to 17
                    wait 1000
                end        
            end
        end
        wait 5000
    end   
end
	

 

The script can also be written in this way
Now it gives paintjob to car model Blade, Remington and Savanna and carcolor to ALPHA, Infernus and BULLET
when player is driving specified car model

CONDITIONAL CHECK can expand by logic operator OR or AND


IF OR - conditions connected with the logic operator OR

IF AND - conditions connected with the logic operator AND

 


{$CLEO .cs}
thread 'PAINT' 

while true
    wait 0 
    if 
        0256:   player $PLAYER_CHAR defined
    then
        if or
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #REMINGTN
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #blade
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #SAVANNA
        then
            03C0: 0@ = actor $PLAYER_ACTOR car
            06ED: set_car 0@ paintjob 0
            wait 1000
            06ED: set_car 0@ paintjob 1
            wait 1000 
        end    
        if or
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #BULLET
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #ALPHA
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #INFERNUS
        then
            03C0: 0@ = actor $PLAYER_ACTOR car
            0229: set_car 0@ primary_color_to 0 secondary_color_to 17
            wait 1000
       
        end        
        wait 5000
    end   
end
	

IF AND - conditions connected with the logic operator AND

IF OR - conditions connected with the logic operator OR


Next Script example gives paintjob and carcolor

when player is driving specified car model
AND
key is pressed

 


{$CLEO .cs}
thread 'PAINT' 

while true
    wait 0 
    if 
        0256:   player $PLAYER_CHAR defined
    then
        if  and
            0AB0:   key_pressed 66// 	b key
            00DD:   actor $PLAYER_ACTOR driving_car_with_model #blade
        then
            03C0: 0@ = actor $PLAYER_ACTOR car
            06ED: set_car 0@ paintjob 0
            wait 1000
            06ED: set_car 0@ paintjob 1
            wait 1000
        else 
            if  and
                0AB0:   key_pressed 78// 	n key
                00DD:   actor $PLAYER_ACTOR driving_car_with_model #ALPHA
            then
                03C0: 0@ = actor $PLAYER_ACTOR car
                0229: set_car 0@ primary_color_to 17 secondary_color_to 0
                wait 1000
            end 
            if  and
                0AB0:   key_pressed 77// 	m key
                00DD:   actor $PLAYER_ACTOR driving_car_with_model #BULLET
            then
                03C0: 0@ = actor $PLAYER_ACTOR car
                0229: set_car 0@ primary_color_to 0 secondary_color_to 17
                wait 1000
            end        

        end

    end   
end

Homepage: www.zazmahall.de/index.htm
E-Mail: zaz@zazmahall.de
13-Februar-2020