CLEO Help Timer help

CLEO related
Status
Not open for further replies.

Noname123

New member
Joined
Jul 15, 2017
Messages
4
Reaction score
0
Hi,
I'm starting with CLEO and I have some question / problem. 
How to make timer with countdown on screen?
I tried something like this, but it probably does not work:
Code:
{$CLEO .cs}
0000: NOP
//-------------MAIN---------------
:1
REPEAT
    WAIT 0
UNTIL 0AFA:  SAMP_IS_READY 

:2
WHILE TRUE
      
WAIT 0
IF
    0AB0:   key_pressed 191 // /
    THEN
    3@ = 18
    2@ = TRUE
    END
    
    IF
        2@ == TRUE
        THEN
         0ACD: show_text_highpriority 3@ time 1500
    WAIT 1000
    3@ -= 1 
    END
  END
Is it possible to make this code working?
 

Noname123

New member
Joined
Jul 15, 2017
Messages
4
Reaction score
0
I want to make a loop when key pressed and show dynamic text on screen.
3@ = 18 -> 18 (time)
0ACD: show_text_highpriority 3@ time 1500 -> Countdown
WAIT 1000 -> wait 1s
3@ -= 1 -> -1 time
and again, but show 18/17/16... without key (2@ == TRUE)
how to make it?
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
151
hi, you could check these out, the first one seems shorter but it loops and prevents other code from executing, the second code doesn't stop other code from executing so you could add other stuff within the "WHILE TRUE - END" loop

[shcode=cpp]{$CLEO .cs}
0000:


REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

// 32@ and 33@ variables are different from the 0@ - 31@ variables because they are timers. After you set 32@ or 33@ to some value they will automatically increase by 1 each milisecond

1@ = 10 // 1@ = amount of seconds for the timer
31@ = 191 // key

32@ = 0 //just initialising

WHILE TRUE
WAIT 0
    if 0AB0:   key_pressed 31@ // /
    then
        0085: 0@ = 32@ // (int)
        0085: 2@ = 1@ // 2@ becomes a copy of 1@ (2@ will be manipulated, 1@ will be kept the same, that's the point of copying it)
        2@ *= 1000 // 2@ seconds turns into miliseconds
        005A: 0@ += 2@ // current time (0@) + amount of countdown time in miliseconds (2@)
        
        while 0AB0:   key_pressed 31@
        wait 0
            0085: 2@ = 0@
            0062: 2@ -= 32@ // 2@ becomes amount of time that is left (in miliseconds)
            2@ /= 1000
            if 001B:   0 > 2@
            then
                0AD1: show_formatted_text_highpriority "The countdown just finished" time 2000 2@
                wait 2000
                break           
            else
                0AD1: show_formatted_text_highpriority "%d" time 1000 2@
            end           
        end
    end
END[/shcode]

[shcode=cpp]
{$CLEO .cs}
0000:

REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

// 32@ and 33@ variables are different from the 0@ - 31@ variables because they are timers. After you set 32@ or 33@ to some value they will automatically increase by 1 each milisecond

1@ = 10 // 1@ = amount of seconds for the timer
3@ = 191 // key

32@ = 0 //just initialising

WHILE TRUE
WAIT 0
    call @Timer 5 timingVariable 32@ amountOfSeconds 1@ booleanNeededForLogicControl 2@ key 3@ endingTimeVar 5@ _returnedbooleanNeededForLogicControl 2@ _returnedResult 4@ _returnedendingTimeVar 5@
    if 4@ == 1
    then
    //timer has been cancelled by releasing the button
    end
    
    if 4@ == 2
    then
    //timer successfully finished the countdown
    end   
END








//functions

:Timer
if 0AB0:   key_pressed 3@ // /
then
    if 2@ == false
    then
        2@ = true
        call @StartTimer 2 timingVariable 0@ amountOfSeconds 1@ _returnedEndingTime_ms 4@
        //chatmsg "started timer" -1
    end
else
2@ = false
ret 3 2@ 1 4@
end
    
if 2@ == true
then
call @ManageTimer 2 timingVariable 0@ endingTime_ms 4@ _isFinished 2@ _timeLeft 29@
//chatmsg "%d %d %d %d" -1 0@ 4@ 2@ 29@
    if 2@ == true
    then
        0AD1: show_formatted_text_highpriority "%d" time 100 29@    
    else
        0AD1: show_formatted_text_highpriority "The countdown just finished" time 2000
        wait 2000   
        ret 3 2@ 2 4@
    end
end
ret 3 2@ 0 4@


:StartTimer
1@ *= 1000 // 2@ seconds turns into miliseconds                      
005A: 0@ += 1@ // current time (0@) + amount of countdown time in miliseconds (2@)
ret 1 0@

:ManageTimer   
0062: 1@ -= 0@
1@ -= 1
1@ /= 1000
1@ += 1
if 001B:   1 > 1@
then
ret 2 false 0
end
ret 2 true 1@[/shcode]
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
227
Location
( ͡° ͜ʖ ͡°)
Code:
{$CLEO .cs}
0000:


REPEAT
    WAIT 0
UNTIL 0AFA:  SAMP_IS_READY
0@ = FALSE
1@ = 10 // The lenght of the countdown by seconds
1@ *= 1000 // converting it to milliseconds



WHILE TRUE
    WAIT 0
    IF
    0AB0:   key_pressed 113 //f2
    THEN
        0@ = TRUE
        REPEAT
            WAIT 0
        UNTIL 8AB0:   key_pressed 113
        32@ = 0
    END
    IF
    0@ == TRUE
    THEN
        0085: 2@ = 1@ // (int)
        0085: 3@ = 32@ // (int)
        0062: 3@ -= 2@  // (int)

        3@ /= 1000
        
        3@ *= -1
        0AD1: show_formatted_text_highpriority "TIME_LEFT: %d" time 1000  3@
        
    
    
    
    END

    IF AND
    0@ == TRUE
    001D:   32@ > 1@  // (int)
    THEN
        0@ = FALSE
        0AD1: show_formatted_text_highpriority "! GO !" time 2000 0x0AD1
    END

END
 

Noname123

New member
Joined
Jul 15, 2017
Messages
4
Reaction score
0
monday said:
hi, you could check these out, the first one seems shorter but it loops and prevents other code from executing, the second code doesn't stop other code from executing so you could add other stuff within the "WHILE TRUE - END" loop

[shcode=cpp]{$CLEO .cs}
0000:


REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

// 32@ and 33@ variables are different from the 0@ - 31@ variables because they are timers. After you set 32@ or 33@ to some value they will automatically increase by 1 each milisecond

1@ = 10 // 1@ = amount of seconds for the timer
31@ = 191 // key

32@ = 0 //just initialising

WHILE TRUE
WAIT 0
    if 0AB0:   key_pressed 31@ // /
    then
        0085: 0@ = 32@ // (int)
        0085: 2@ = 1@ // 2@ becomes a copy of 1@ (2@ will be manipulated, 1@ will be kept the same, that's the point of copying it)
        2@ *= 1000 // 2@ seconds turns into miliseconds
        005A: 0@ += 2@ // current time (0@) + amount of countdown time in miliseconds (2@)
        
        while 0AB0:   key_pressed 31@
        wait 0
            0085: 2@ = 0@
            0062: 2@ -= 32@ // 2@ becomes amount of time that is left (in miliseconds)
            2@ /= 1000
            if 001B:   0 > 2@
            then
                0AD1: show_formatted_text_highpriority "The countdown just finished" time 2000 2@
                wait 2000
                break           
            else
                0AD1: show_formatted_text_highpriority "%d" time 1000 2@
            end           
        end
    end
END[/shcode]

[shcode=cpp]
{$CLEO .cs}
0000:

REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

// 32@ and 33@ variables are different from the 0@ - 31@ variables because they are timers. After you set 32@ or 33@ to some value they will automatically increase by 1 each milisecond

1@ = 10 // 1@ = amount of seconds for the timer
3@ = 191 // key

32@ = 0 //just initialising

WHILE TRUE
WAIT 0
    call @Timer 5 timingVariable 32@ amountOfSeconds 1@ booleanNeededForLogicControl 2@ key 3@ endingTimeVar 5@ _returnedbooleanNeededForLogicControl 2@ _returnedResult 4@ _returnedendingTimeVar 5@
    if 4@ == 1
    then
    //timer has been cancelled by releasing the button
    end
    
    if 4@ == 2
    then
    //timer successfully finished the countdown
    end   
END








//functions

:Timer
if 0AB0:   key_pressed 3@ // /
then
    if 2@ == false
    then
        2@ = true
        call @StartTimer 2 timingVariable 0@ amountOfSeconds 1@ _returnedEndingTime_ms 4@
        //chatmsg "started timer" -1
    end
else
2@ = false
ret 3 2@ 1 4@
end
    
if 2@ == true
then
call @ManageTimer 2 timingVariable 0@ endingTime_ms 4@ _isFinished 2@ _timeLeft 29@
//chatmsg "%d %d %d %d" -1 0@ 4@ 2@ 29@
    if 2@ == true
    then
        0AD1: show_formatted_text_highpriority "%d" time 100 29@    
    else
        0AD1: show_formatted_text_highpriority "The countdown just finished" time 2000
        wait 2000   
        ret 3 2@ 2 4@
    end
end
ret 3 2@ 0 4@


:StartTimer
1@ *= 1000 // 2@ seconds turns into miliseconds                      
005A: 0@ += 1@ // current time (0@) + amount of countdown time in miliseconds (2@)
ret 1 0@

:ManageTimer   
0062: 1@ -= 0@
1@ -= 1
1@ /= 1000
1@ += 1
if 001B:   1 > 1@
then
ret 2 false 0
end
ret 2 true 1@[/shcode]

Opcode.eXe said:
Code:
{$CLEO .cs}
0000:


REPEAT
    WAIT 0
UNTIL 0AFA:  SAMP_IS_READY
0@ = FALSE
1@ = 10 // The lenght of the countdown by seconds
1@ *= 1000 // converting it to milliseconds



WHILE TRUE
    WAIT 0
    IF
    0AB0:   key_pressed 113 //f2
    THEN
        0@ = TRUE
        REPEAT
            WAIT 0
        UNTIL 8AB0:   key_pressed 113
        32@ = 0
    END
    IF
    0@ == TRUE
    THEN
        0085: 2@ = 1@ // (int)
        0085: 3@ = 32@ // (int)
        0062: 3@ -= 2@  // (int)

        3@ /= 1000
        
        3@ *= -1
        0AD1: show_formatted_text_highpriority "TIME_LEFT: %d" time 1000  3@
        
    
    
    
    END

    IF AND
    0@ == TRUE
    001D:   32@ > 1@  // (int)
    THEN
        0@ = FALSE
        0AD1: show_formatted_text_highpriority "! GO !" time 2000 0x0AD1
    END

END


Always show 0 ;/
Opcode.eXe - Code working, but always TIMELEFT : 0 after 10s = GO
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
151
I just tested both scripts and both worked well, counting from 10 to 0 (using cleo 4.1, sampfuncs 5.3.1 and samp 0.3.7)
 
Status
Not open for further replies.
Top