CLEO Help Cancelling cycle

CLEO related

dotaczik

Member
Joined
Jan 13, 2020
Messages
6
Reaction score
0
Location
Czech republic
Hi

I have a problem in my little cleo script and I cant find soloution.
The thing is I have a code where my script fire in cycle. There is command wait, where it waits 80 sec.
And I want to stop this cycling by pressing some key. But when it waits 80 sec I cant use condition for pressing a certain key to cancel this cycle. I guess it has to be solved by threads, but I know almost nothing about threads.

Thanks for help.

PHP:
{$CLEO .cs}

0000: "myscript"


:loop
wait 0
if
  0AB0:   is_key_pressed 192
then

  0ACD: show_text_highpriority "activated" time 2500
  wait 10000

  while true
     0AB1: @FAKE_KEYPRESS 1 _OFFSET_KEY_ 0x22
     wait 80000
  end
    
  0002: jump @loop

else
 
  0002: jump @loop

end

:FAKE_KEYPRESS
1@ = 0xB73458
005A: 1@ += 0@  // (int)
0A8C: write_memory 1@ size 1 value 255 virtual_protect 0
0AB2: ret 0

{
Offset        Slot     
+ 0x0        Right                       
+ 0x1        Left                           
+ 0x2        Backwards                   
+ 0x3        Forward                       
+ 0x4        Look right                   
+ 0x5        Look left                   
+ 0x6        Look down                       
+ 0x7        Look up                           
+ 0x8        Action           
+ 0xA        Previous weapon/target               
+ 0xC        Aim weapon                   
+ 0xE        Next weapon/target               
+ 0x10        Group CTRL forward                   
+ 0x12        Group CTRL back                       
+ 0x14        Conversation - NO                   
+ 0x16        Conversation - YES                   
+ 0x1A        Change camera                   
+ 0x1C        Jump                           
+ 0x1E        Enter+exit                       
+ 0x20        Sprint                           
+ 0x22        Fire                           
+ 0x24        Crouch                           
+ 0x26        Look behind                       
+ 0x28        Unused                           
+ 0x2A        Walk                           
}
 

Fr0z3n

Well-known member
Joined
Nov 20, 2019
Messages
301
Reaction score
36
Location
Srbija
Try this...


C++:
{$CLEO .cs}

0000: "myscript"


0B34: "iskljuci" @toggle // toggle 30@ command: /iskljuci

:loop
wait 0
if
  0AB0:   is_key_pressed 192
then

  0ACD: show_text_highpriority "activated" time 2500
  wait 10000

  while true
    30@ == 0 // if its on
    then // then do thing...
      0AB1: @FAKE_KEYPRESS 1 _OFFSET_KEY_ 0x22
      wait 80000
    end // end for checking if its on
  end
   
  0002: jump @loop

else

  0002: jump @loop

end

:toggle                              
0B12: 30@ = 30@ XOR 1 // opcode tu turn of/on
if 30@ == 1        
then  
        0AF8: "{f58142}OFF!" color -1
    ELSE
        0AF8: "{f58142}ON!" color -1                                    
END
SAMP.CmdRet()

:FAKE_KEYPRESS
1@ = 0xB73458
005A: 1@ += 0@  // (int)
0A8C: write_memory 1@ size 1 value 255 virtual_protect 0
0AB2: ret 0

{
Offset        Slot    
+ 0x0        Right                      
+ 0x1        Left                          
+ 0x2        Backwards                  
+ 0x3        Forward                      
+ 0x4        Look right                  
+ 0x5        Look left                  
+ 0x6        Look down                      
+ 0x7        Look up                          
+ 0x8        Action          
+ 0xA        Previous weapon/target              
+ 0xC        Aim weapon                  
+ 0xE        Next weapon/target              
+ 0x10        Group CTRL forward                  
+ 0x12        Group CTRL back                      
+ 0x14        Conversation - NO                  
+ 0x16        Conversation - YES                  
+ 0x1A        Change camera                  
+ 0x1C        Jump                          
+ 0x1E        Enter+exit                      
+ 0x20        Sprint                          
+ 0x22        Fire                          
+ 0x24        Crouch                          
+ 0x26        Look behind                      
+ 0x28        Unused                          
+ 0x2A        Walk                          
}
 
Last edited:

dotaczik

Member
Joined
Jan 13, 2020
Messages
6
Reaction score
0
Location
Czech republic
So Am i right, that this code works this way: when command is typed in console, it will call directive "toogle" and it will change state of 30@. And when wait command end and code get to checking if 30@== 0 than it will react to current state if it is turned on or off. Is there some way, how to do it without samp funcs ? I mean to use just key press to turn it on and off. Because samp funcs is crashing my game :(
 

dotaczik

Member
Joined
Jan 13, 2020
Messages
6
Reaction score
0
Location
Czech republic
But with this edited code you posted, isnt that key press condition irelevant ? Code start, it will check the condition if key is pressed and if no it will jump to start, if its pressed it will enter while loop, where i am toogling just by writing command in chat, it will never get out of the loop it will either fire and wait 80 sec or it will be just looping and checking if its on or off, but never get out of while. So this key press condition is only condition to enter the loop while. Or Am I wrong ?
 

Fr0z3n

Well-known member
Joined
Nov 20, 2019
Messages
301
Reaction score
36
Location
Srbija
So... paste this script and name it KeyPress.cs

C++:
{$CLEO .cs}

0000: "myscript"

thread 'TEST' // DONT CHANGE NAME

:loop
wait 0
if
  0AB0:   is_key_pressed 192
then

  0ACD: show_text_highpriority "activated" time 2500
  wait 10000

  while true
      0AB1: @FAKE_KEYPRESS 1 _OFFSET_KEY_ 0x22
      wait 80000
  end
    
  0002: jump @loop

else
 
  0002: jump @loop

end

:FAKE_KEYPRESS
1@ = 0xB73458
005A: 1@ += 0@  // (int)
0A8C: write_memory 1@ size 1 value 255 virtual_protect 0
0AB2: ret 0

Than you wanna create another script(name does not matter) with this code...

C++:
{$CLEO .cs}

0000:

:Terminate
thread 'COLAPSE'
wait 1000

while true
    wait 0
    if
        0256:   player $PLAYER_CHAR defined
    then
        if
            0AB0:   key_pressed 0X7A// F11 
        then
            if
                0AAB:   file_exists "CLEO\KeyPress.cs" // if script KeyPress.cs exist in cleo   
            then
                0AAA: 0@ = thread 'TEST' pointer
                if
                    not 0@ == 0 // IF script is working   
                then
                    0ABA: end_custom_thread_named 'TEST' // colapse

                        repeat
                            wait 0
                        until 8AB0: not  key_pressed 0X7A // until you dont press F11 THE THREAD WILL BE PAUSED

                    0A92: create_custom_thread "KeyPress.cs"// PLAY SCRIPT AGAIN IF U PRESS F11
                end
            end
        end
    end
end

In practice, when you press F11 the script should pause, when you click F11 again the script will start working...

In practice, it should work ... Change if I did something wrong...
 

JaggerJam

Active member
Joined
Sep 14, 2017
Messages
98
Solutions
1
Reaction score
21
Hi

I have a problem in my little cleo script and I cant find soloution.
The thing is I have a code where my script fire in cycle. There is command wait, where it waits 80 sec.
And I want to stop this cycling by pressing some key. But when it waits 80 sec I cant use condition for pressing a certain key to cancel this cycle. I guess it has to be solved by threads, but I know almost nothing about threads.

Thanks for help.

PHP:
{$CLEO .cs}

0000: "myscript"


:loop
wait 0
if
  0AB0:   is_key_pressed 192
then

  0ACD: show_text_highpriority "activated" time 2500
  wait 10000

  while true
     0AB1: @FAKE_KEYPRESS 1 _OFFSET_KEY_ 0x22
     wait 80000
  end
  
  0002: jump @loop

else

  0002: jump @loop

end

:FAKE_KEYPRESS
1@ = 0xB73458
005A: 1@ += 0@  // (int)
0A8C: write_memory 1@ size 1 value 255 virtual_protect 0
0AB2: ret 0

{
Offset        Slot   
+ 0x0        Right                     
+ 0x1        Left                         
+ 0x2        Backwards                 
+ 0x3        Forward                     
+ 0x4        Look right                 
+ 0x5        Look left                 
+ 0x6        Look down                     
+ 0x7        Look up                         
+ 0x8        Action         
+ 0xA        Previous weapon/target             
+ 0xC        Aim weapon                 
+ 0xE        Next weapon/target             
+ 0x10        Group CTRL forward                 
+ 0x12        Group CTRL back                     
+ 0x14        Conversation - NO                 
+ 0x16        Conversation - YES                 
+ 0x1A        Change camera                 
+ 0x1C        Jump                         
+ 0x1E        Enter+exit                     
+ 0x20        Sprint                         
+ 0x22        Fire                         
+ 0x24        Crouch                         
+ 0x26        Look behind                     
+ 0x28        Unused                         
+ 0x2A        Walk                         
}
The wait opcode is pausing the loop until it reaches 80000 ms and then proceeds to loop back, when you are pressing the key in "freezed" loop the if condition will not work. Here is the code using game timer
JavaScript:
{$CLEO .cs}
{$USE bitwise}
0000:

wait 5000

while true

    if 0ab0: is_key_pressed 192
    then
        repeat
        wait 0
        until 8ab0: 192 //anti-spam
       
        0B12: 31@ = 31@ XOR 1 //if 0 then returns 1 | if 1 then returns 0
       
        if 31@ == 1
        then
            32@ = 0 //timera
            30@ = 1
            0ACD: show_text_highpriority "activated" time 2500
        else
            0ACD: show_text_highpriority "deactivated" time 2500
        end
    end
   
    if 31@ == 1 //while true
    then
        if 30@ == 1 //activate FAKE_KEYPRESS
        then
            0AB1: @FAKE_KEYPRESS 1 _OFFSET_KEY_ 0x22
            30@ = 0
        end
       
        if 32@ >= 80000 //wait 80 sec
        then
            30@ = 1
            32@ = 0
        end
    end
END {while}


:FAKE_KEYPRESS
1@ = 0xB73458
005A: 1@ += 0@  // (int)
0A8C: write_memory 1@ size 1 value 255 virtual_protect 0
0AB2: ret 0
 

Fr0z3n

Well-known member
Joined
Nov 20, 2019
Messages
301
Reaction score
36
Location
Srbija
The wait opcode is pausing the loop until it reaches 80000 ms and then proceeds to loop back, when you are pressing the key in "freezed" loop the if condition will not work. Here is the code using game timer
JavaScript:
{$CLEO .cs}
{$USE bitwise}
0000:

wait 5000

while true

    if 0ab0: is_key_pressed 192
    then
        repeat
        wait 0
        until 8ab0: 192 //anti-spam
     
        0B12: 31@ = 31@ XOR 1 //if 0 then returns 1 | if 1 then returns 0
     
        if 31@ == 1
        then
            32@ = 0 //timera
            30@ = 1
            0ACD: show_text_highpriority "activated" time 2500
        else
            0ACD: show_text_highpriority "deactivated" time 2500
        end
    end
 
    if 31@ == 1 //while true
    then
        if 30@ == 1 //activate FAKE_KEYPRESS
        then
            0AB1: @FAKE_KEYPRESS 1 _OFFSET_KEY_ 0x22
            30@ = 0
        end
     
        if 32@ >= 80000 //wait 80 sec
        then
            30@ = 1
            32@ = 0
        end
    end
END {while}


:FAKE_KEYPRESS
1@ = 0xB73458
005A: 1@ += 0@  // (int)
0A8C: write_memory 1@ size 1 value 255 virtual_protect 0
0AB2: ret 0

He said without SF
 
Last edited:
Top