CLEO Help Reload Cleo

CLEO related
Status
Not open for further replies.

PopandaulX

Active member
Joined
Jul 15, 2013
Messages
189
Reaction score
1
Hello. I need to find a way to reload all the cleo scripts, without restarting the game.
 

LongJohnMilkeyway

New member
Joined
Mar 8, 2014
Messages
3
Reaction score
1
Yes, it's possible to reload a running cleoscript
But it needs some preparations and some knowledge about valid gta scripting

1. opcode 0ABA: terminates cleoscript, called thread
It requires that the cleoscript contains a valid thread_name

Code:
0ABA: end_custom_thread_named 'TXDTEST'

Sanny description says
0ABA ends a CLEO-thread with given name.
A thread gets its name with the opcode 03A4.
If the thread wasn't named with 03A4, the thread gets its name by first 7 letters of the file name.
For example, the thread from the file test.cs will have name 'test.cs';
from the file myscript.cs - 'myscrip'.
The opcode 0ABA immediately finishes the execution of a thread with given name.
This opcode is the same as 0459, but is made for the CLEO scripts.

Parameters:
1 - name of the thread to end.


But the usage
"If the thread wasn't named with 03A4, the thread gets its name by first 7 letters of the file name."
isn't true, i tested a lot on cleo3 as well on CLEO 4.1.1.30f by Alien
opcode 0ABA: don't work if you insert the filename

opcode 0ABA: requires to insert the thread_name

So it needs to make shure that the script which should be terminated cantains a valid thread_name
This needs to open this script and check it out and maybe correct it

The threadname should be written at scriptbeginn after the cleo directive
Code:
{$CLEO .cs}
03A4: name_thread 'TXDTEST'
can also be written in this way
Code:
{$CLEO .cs}
thread 'TXDTEST'
written as short string (single apostrophe)
Important: max. 7 charackters as thread_name are valid

2. Terminating a script by that method can cause negative effects because of following reason

Scripts often creates some entities and valid written scripts remove the created entities at specified cases
we call it cleanup, it's like disposing the stuff
with opcodes like
01C2: remove_references_to_actor 2@ // Like turning an actor into a random pedestrian
01C4: remove_references_to_object 82@(39@,16i) // This object will now disappear when the player looks away
009B: destroy_actor 18@
00A6: destroy_car 22@
0108: destroy_object $Wanted_List_Object

So a created actor will stay ingame after thread_ending, because the cleanup can't be read anymore
Maybe it's not a big problem if not much entities remains

But you should never make then savegame,
because remaing objects, pickups or parked_car_generators will be written into the savegames of GTA SA User file folder

Now the How to do
As first an example script that we want to terminate
A script to display a texture on screen as soon as Player is availabel ingame
The texture will be shown as long as the script is running, as long as opcode 03F0: and 038D: is running in a loop
Thread_name = 'TXDTEST'
Save and compile the script as TEXTURE.cs
This filename is required to can start this script again with opcode 0A92:


Code:
{$CLEO .cs}
:TEXTURE
thread 'TXDTEST'// <--- thread name, max. 7 charackters are valid, written as short string (single apostrophe)
wait 1000

//this script shows a texture on screen as soon as Player is availabel ingame


while true
    wait 0
    if
        0256:   player $PLAYER_CHAR defined
    then
        0390: load_txd_dictionary "ld_bum"// <--- texture archive name, max. 7 charackters are valid, written as long string (double apostrophe)
        038F: load_texture "bum2" as 1

        while   0256:   player $PLAYER_CHAR defined
            wait 0
            03F0: enable_text_draw 1
            038D: draw_texture 1 position 150.0 130.0 size 180.5 210.0 RGBA 255 255 255 255
        end        
    end
end

Then the script to terminate TEXTURE.cs by using

Code:
0ABA: end_custom_thread_named 'TXDTEST'

and to start it it again by using

Code:
0A92: create_custom_thread "TEXTURE.cs"

0ABA: needs to insert the threadname as short string
0A92: needs to insert the filename as long string

press Backspace to terminate the TEXTURE.cs
Code:
{$CLEO .cs}
:Refresh_Cleoscript
thread 'RECLEO'
wait 1000

while true
    wait 0
    if
        0256:   player $PLAYER_CHAR defined
    then
        if
            0AB0:   key_pressed 8//--------------------------------- press Backspace    
        then

            0ABA: end_custom_thread_named 'TXDTEST' // - cleo 3 -

                repeat
                    wait 0
                until 8AB0: not  key_pressed 8

            0A92: create_custom_thread "TEXTURE.cs" // - cleo 3 -

        end
    end
end


Advanced codes:
It's a good idea to check first if the file exist as well to check if the thread is running
To check if file exist needs to insert the filename
Code:
0AAB:   file_exists "CLEO\TEXTURE.cs"
To check if the thread is running needs to insert the thread_name
Code:
0AAA: 0@ = thread 'TXDTEST' pointer
if
    not 0@ == 0    
then

The advanced script, press Backspace to terminate the TEXTURE.cs
Code:
{$CLEO .cs}
:Refresh_Cleoscript
thread 'RECLEO'
wait 1000

while true
    wait 0
    if
        0256:   player $PLAYER_CHAR defined
    then
        if
            0AB0:   key_pressed 8//--------------------------------- press Backspace    
        then
            if
                0AAB:   file_exists "CLEO\TEXTURE.cs"    
            then
                0AAA: 0@ = thread 'TXDTEST' pointer
                if
                    not 0@ == 0    
                then
                    0ABA: end_custom_thread_named 'TXDTEST' // - cleo 3 -

                        repeat
                            wait 0
                        until 8AB0: not  key_pressed 8

                    0A92: create_custom_thread "TEXTURE.cs" // - cleo 3 -
                end
            end
        end
    end
end
 
Status
Not open for further replies.
Top