Quantcast

Jump to content

» «
Photo

help with a timer

6 replies to this topic
sixace
  • sixace

    Player Hater

  • Members
  • Joined: 29 Feb 2012

#1

Posted 29 April 2012 - 10:49 AM

Hello everyone.

I created this mod with a timer that uses 014E, so it uses global variable and gives me the generic number countdown display on screen. It works nicely, though i thought the number countdown display was kinda lame, so i thought it would be cool to use a status bar to show timer progress instead of the numbers.

So in my search i found this:

CODE
{$VERSION 3.1.0027}
{$CLEO .cs}

//-------------MAIN---------------
0000: NOP
9@ = 100.0


:NONAME_12
wait 0
if
  Player.Defined(0)
jf @NONAME_213
if and
044B:   actor $PLAYER_ACTOR on_foot
  not Actor.Driving($PLAYER_ACTOR)
jf @NONAME_213

:NONAME_52
wait 0
gosub @NONAME_220

if or
80E1: not player 0 pressed_key 9
00E1:   player 0 pressed_key 8
jf @NONAME_165
if or
80E1:   not player 0 pressed_key 8
00E1:   player 0 pressed_key 9
jf @NONAME_117
jump @NONAME_158

:NONAME_117
9@ += 5.0
if
 9@ > 750.0
jf @NONAME_158
9@ = 749.9

:NONAME_158
jump @NONAME_206

:NONAME_165
9@ -= 5.0
if
 5.0 > 9@
jf @NONAME_206
9@ = 5.0

:NONAME_206
jump @NONAME_52

:NONAME_213
jump @NONAME_12

:NONAME_220
0087: 3@ = 9@ // (float)
3@ /= 750.0
3@ *= 58.0
0087: 10@ = 3@ // (float)
10@ /= 2.0
10@ += 547.6
03F0: enable_text_draw 1
038E: draw_box_position 576.6 400.0 size 62.0 8.0 RGBA 0 0 0 255
038E: draw_box_position 576.6 400.0 size 58.0 5.1 RGBA 255 255 255 255
038E: draw_box_position 10@ 400.0 size 3@ 5.0 RGBA 255 0 0 255
return


I like how the bar looks and it's position, so i wanted to use it (i don't need the key presses though). My question is, how can i make the bar work with a timer (instead of the key presses ) where the bar decreases as the timer counts down? And if possible, how can i make a variable timer where whether the timer is set for 1 minute or 10 minutes, the bar will display the countdown correctly? I hope someone can point me to the right direction. Still learning my way around cleo. Many thanks in advance.

Ashwin.Star
  • Ashwin.Star

    Back for Next ♪♫

  • Members
  • Joined: 14 Nov 2010
  • India

#2

Posted 29 April 2012 - 11:00 AM

use this for timer
CODE
04F7: status_text $8801 0 line 3 'none'

Use 2nd perimeter for toggle Bar & digit

sixace
  • sixace

    Player Hater

  • Members
  • Joined: 29 Feb 2012

#3

Posted 29 April 2012 - 12:39 PM

QUOTE (Ashwin the new boy @ Sunday, Apr 29 2012, 11:00)
use this for timer
CODE
04F7: status_text $8801 0 line 3 'none'

Use 2nd perimeter for toggle Bar & digit

Using what you gave me as it is (with a "0") gave me a number countdown like i already have.
Toggling the second parameter as you said "0" to "1" does not give me a display at all. Or did i misunderstand? Thanks for the reply btw.

sixace
  • sixace

    Player Hater

  • Members
  • Joined: 29 Feb 2012

#4

Posted 30 April 2012 - 05:03 AM Edited by sixace, 30 April 2012 - 05:07 AM.

Ok my bad...i didn't realize my stalker hud mod was messing with the bar display.

Anyway, thanks for the tip, i got it working somewhat...

I understand that i have to use integers to properly display the bar. My question is how to make the time variable yet still display on the bar correctly?

i'll use ZAZ's example:
CODE
:Status2_1
thread 'STATUS2'
0004: $time1 =  100  // integer values
0004: $time2 = 1000    // integer values
04F7: status_text $time1 type 1 line 1 GXT 'fem_ok' // global_variable  // Score
04F7: status_text $time2 type 0 line 2 GXT 'fem_on' // global_variable  // Score

:Status2_2
wait 0
$time2 -= 1
0084: $time1 = $time2
$time1 /= 10
if
$time2 == 0
jf @Status2_2
0151: remove_status_text $time1
0151: remove_status_text $time2
00BA: show_text_styled GXT 'fem_off' time 1000 style 1
0A93: end_custom_thread


In the above example, if i change the value of $time2 to say 500, then i only get half a bar to start with. How can i make it so regardless of the value of time2, the bar will display it correctly? I can't seem to get my brain wrapped on the computation. suicidal.gif

Deji
  • Deji

    Coding like a Rockstar!

  • Feroci Racing
  • Joined: 24 Dec 2007
  • None

#5

Posted 30 April 2012 - 06:05 PM

Global variables not defined in CustomVariables.ini are evil, stay away.

Use this method instead: http://sannybuilder....?pid=9135#p9135

sixace
  • sixace

    Player Hater

  • Members
  • Joined: 29 Feb 2012

#6

Posted 30 April 2012 - 10:35 PM Edited by sixace, 30 April 2012 - 10:50 PM.

QUOTE (Deji @ Monday, Apr 30 2012, 18:05)
Global variables not defined in CustomVariables.ini are evil, stay away.

Use this method instead: http://sannybuilder....?pid=9135#p9135

Thanks for the reply Deji.

I appreciate the link, i will try and wrap my head around it. I'm still a novice scripter and that looks pretty advanced for what i already know. Going to that link made me feel like i opened my learning book to chapter 30...i'm still on chapter 5. You know what i mean? biggrin.gif

Though i understand what you mean by staying away from global variables, i'm still just in the process of understanding how a basic variable timer can be displayed on a statusbar correctly instead of a number countdown. Global or not, i just want to see how it's put together so i can understand it. Or if it is even possible in the first place, I have yet to see a working example of it though i'm still searching around. I don't really want to divert too far from what i am trying to learn (that's like putting more food on my plate than i can eat at this moment).

If someone could give me an example of this using 04F7 that would really help a lot..

It just amazes me how easy i can implement a variable 014E timer with a couple lines, though i didn't realize wanting to display the number countdown in a statusbar instead might actually end up being more complicated than the script i am making it for. I'm getting this feeling that my idea is faaaaaar from being simple. sarcasm.gif

Deji
  • Deji

    Coding like a Rockstar!

  • Feroci Racing
  • Joined: 24 Dec 2007
  • None

#7

Posted 30 April 2012 - 11:18 PM

04F7 and 014E both only support global variables (R* decided to implement this command in a pretty weird way). The only way to use the built-in timer and counter functions with local variables is through the link I posted.

Alternatively, you could just create something that looks like a timer/counter using text draw (some stuff about that here and a long way down here - and of course, the Draw category of the OpcodeDB contains a lot of text draw related opcodes). It requires quite a bit of math to do correctly, though.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users