You are not logged in.
Pages: 1
Can somebody tell me how to create a timer in a costum mission ?
I want it to have a time to complete the mission or else you fail and second , just show how much time it took for the mission to complete?
Please i need both of them (i created a sphere i just need the timer)
Offline
32@, 33@ - aren't these two timers in mission thread?
Offline
32@, 33@ - aren't these two timers in mission thread?
Yes, there are. I will explain it.
The game supports opcodes to show automatic timers but it needs to insert global variables
and because global can cause bugs and crashes in Cleo I will show first how to display
timers in scripted variation.
This needs to calculate the values of 33@ or 32@ to show minutes and seconds,
for the text number display can be used text_draw opcodes, text_high_priority opcodes or text_style opcodes
I made a little script which invite you to run with your player_actor around the SF-garage in Doherty
Go into the red marker (not that to start the mission) then run to the next red marker and so on
A yellow blip on radar shows you where to run
The first script shows the simple value of 33@
text_draw opcodes are used to show the value
{$CLEO .cs} :Timeout_1// --- 32@ and 33@ are allways running as script timer in ms and you can catch its value thread 'Timeout' 018A: 1@ = create_checkpoint_at -2026.2032 139.4361 28.8 :Timeout_3//------------------------------------------------------- first loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Timeout_3 03F0: enable_text_draw 1 045A: text_draw_1number 500.0 200.0 'NUMBER' 33@ if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2026.2032 139.4361 28.83 radius 2.5 2.5 5.5 jf @Timeout_3 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2057.0911 139.3797 28.83 33@ = 0// set the timer to 0 :Timeout_5//------------------------------------------------------- second loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Timeout_repeat 03F0: enable_text_draw 1 045A: text_draw_1number 500.0 200.0 'NUMBER' 33@ if 33@ > 4000// check if timer is bigger than 4000ms jf @Timeout_7 jump @Timeout_repeat :Timeout_7 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2057.0911 139.3797 28.83 radius 2.5 2.5 5.5 jf @Timeout_5 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2063.8882 184.6683 28.843 33@ = 0// set the timer to 0 :Timeout_9//------------------------------------------------------- third loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Timeout_repeat 03F0: enable_text_draw 1 045A: text_draw_1number 500.0 200.0 'NUMBER' 33@ if 33@ > 5000// check if timer is bigger than 4000ms jf @Timeout_11 jump @Timeout_repeat :Timeout_11 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2063.8882 184.6683 28.843 radius 2.5 2.5 5.5 jf @Timeout_9 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2024.1184 180.6013 28.8359 33@ = 0// set the timer to 0 :Timeout_13//------------------------------------------------------- fourth loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Timeout_repeat 03F0: enable_text_draw 1 045A: text_draw_1number 500.0 200.0 'NUMBER' 33@ if 33@ > 5000// check if timer is bigger than 5000ms jf @Timeout_15 jump @Timeout_repeat :Timeout_15 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2024.1184 180.6013 28.8359 radius 2.5 2.5 5.5 jf @Timeout_13 00BA: show_text_styled GXT 'M_PASSD' time 5000 style 1 Marker.Disable(1@) 03F0: enable_text_draw 0 0A93: end_custom_thread//- end by success :Timeout_repeat//-----------------------refresh 00BA: show_text_styled GXT 'M_FAIL' time 5000 style 1 03F0: enable_text_draw 0 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2026.2032 139.4361 28.8 0002: jump @Timeout_3
The next script shows the calculated values of 33@ as seconds and 1/100 of a second
text_draw opcodes are used to show the time
Use the fxt below and insert it into your fxt file
Showt01 SHOWTime: ~1~:~1~
Run again around the SF-garage in Doherty
{$CLEO .cs} :Showtime_1 thread 'Showtime' 018A: 1@ = create_checkpoint_at -2026.2032 139.4361 28.8 :Showtime_3//------------------------------------------------------- first loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Showtime_3 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2026.2032 139.4361 28.83 radius 2.5 2.5 5.5 jf @Showtime_3 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2057.0911 139.3797 28.83 33@ = 0 26@ = 4000//----countdownt start value in ms :Showtime_5//------------------------------------------------------- second loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Showtime_repeat gosub @Showtime_text_draw//---------- gosub to the display setting if 33@ > 4000//-- must be equal to the previous countdownt start value jf @Showtime_7 jump @Showtime_repeat :Showtime_7 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2057.0911 139.3797 28.83 radius 2.5 2.5 5.5 jf @Showtime_5 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2063.8882 184.6683 28.843 33@ = 0 26@ = 5000//----countdownt start value in ms :Showtime_9//------------------------------------------------------- third loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Showtime_repeat gosub @Showtime_text_draw//---------- gosub to the display setting if 33@ > 5000//-- must be equal to the previous countdownt start value jf @Showtime_11 jump @Showtime_repeat :Showtime_11 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2063.8882 184.6683 28.843 radius 2.5 2.5 5.5 jf @Showtime_9 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2024.1184 180.6013 28.8359 33@ = 0 26@ = 5000//----countdownt start value in ms :Showtime_13//------------------------------------------------------- fourth loop wait 0 if 0256: player $PLAYER_CHAR defined jf @Showtime_repeat gosub @Showtime_text_draw//---------- gosub to the display setting if 33@ > 5000//-- must be equal to the previous countdownt start value jf @Showtime_15 jump @Showtime_repeat :Showtime_15 if 00FE: actor $PLAYER_ACTOR 1 (in-sphere)near_point -2024.1184 180.6013 28.8359 radius 2.5 2.5 5.5 jf @Showtime_13 00BA: show_text_styled GXT 'M_PASSD' time 5000 style 1 Marker.Disable(1@) 03F0: enable_text_draw 0 0A93: end_custom_thread//- end by success :Showtime_repeat//-----------------------refresh 00BA: show_text_styled GXT 'M_FAIL' time 5000 style 1 03F0: enable_text_draw 0 Marker.Disable(1@) 018A: 1@ = create_checkpoint_at -2026.2032 139.4361 28.8 0002: jump @Showtime_3 :Showtime_text_draw//------------------------------- subscript 0085: 31@ = 33@ // make a local equal to the timer 33@ 0085: 30@ = 33@ // make one more local equal to the timer 33@ 0085: 28@ = 26@ // make a local equal to the countdownt start value which show the seconds 28@ /= 1000 31@ /= 1000 0062: 28@ -= 31@ 0085: 27@ = 26@ // make one more local equal to the countdownt start value which show parts of seconds 27@ /= 10 30@ /= 10 0062: 27@ -= 30@ 03F0: enable_text_draw 1 0340: set_text_draw_RGBA 0 64 255 255 033F: set_text_draw_letter_size 0.5 3.0 0343: set_text_draw_linewidth 640.0 045B: draw_text_2numbers 450.0 200.0 GXT 'SHOWT01' numbers 28@ 27@ return
Instead text_draw opcodes can also be used text_high_priority opcodes
replace
03F0: enable_text_draw 1 0340: set_text_draw_RGBA 0 64 255 255 033F: set_text_draw_letter_size 0.5 3.0 0343: set_text_draw_linewidth 640.0 045B: draw_text_2numbers 450.0 200.0 GXT 'SHOWT01' numbers 28@ 27@
with
02FD: show_text_2numbers_lowpriority GXT 'Showt01' numbers 28@ 27@ time 10 flag 1
or use text_style opcodes and replace it with
036D: show_text_2numbers_styled GXT 'Showt01' numbers 28@ 27@ time 5 style 6
As I said above can also be used an automatic timer but it needs to use global variables
You need first to declare the value then start the timer.
Use stop timer at the end to remove the reference of the timer and of the variable
type 1 counts in descending order and type 0 counts in ascending order
{$CLEO .cs} :Timer_1 thread 'TIMER' 0004: $time2 = 90000 // integer values 014E: set_timer_to $time2 type 1 :Timer_2 wait 0 if $time2 == 0 jf @Timer_2 014F: stop_timer $time2 00BA: show_text_styled GXT 'fem_off' time 1000 style 1 0A93: end_custom_thread
For the timer exist also a version which show a text
replace
014E: set_timer_to $time2 type 1
with
03C3: set_timer_to $time2 type 1 GXT 'Showt01' // global_variable // Time
To make it complete I show also how to use the StatusText or StatusBar opcode
But it needs also to use global variables
At first the StatusText opcode which displays only a value as numbers
It displays not the time but it displays automaticly the value of the global variable
{$CLEO .cs} :Status_1 thread 'STATUS' 0004: $time2 = 1000 // integer values 03C4: set_status_text $time2 type 0 GXT 'Showt01' // global_variable // Score ~1~ :Status_2 wait 0 $time2 -= 1 if $time2 == 0 jf @Status_2 0151: remove_status_text $time2 00BA: show_text_styled GXT 'fem_off' time 1000 style 1 0A93: end_custom_thread
type 0 shows the value as numbers
type 1 shows the value as an bar
also there exist other opcodes to displays more StatusTexts or StatusBars
in more rows among each other
for the statusBar you must consider that a full bar have allways the value 100
and to show the correct bar needs to calculate the value relativ to 100
in other words: the bar shows percents
{$CLEO .cs} :Status2_1 thread 'STATUS2' 0004: $time1 = 100 // integer values 0004: $time2 = 1000 // integer values 04F7: status_text $time1 type 1 line 1 GXT 'Showt01' // global_variable // Score 04F7: status_text $time2 type 0 line 2 GXT 'Showt01' // 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
Offline
well, Seemann posted a code, that allows to show status-texts and timers without use of global variables. It's in russian SB help.
:AddStatusText 0AB1: call_scm_func @__VarToOffset 1 0@ 0@ 0AB1: call_scm_func @__LabelToOffset 1 2@ 2@ 0AA6: call_method 0x0044CDA0 struct 0x00BA1788 num_params 4 pop 0 ( LINE = 3@ GXT = 2@ TYPE = 1@ VARNUMBER = 0@ ) 0AB2: ret 0 :RemoveStatusText 0AB1: call_scm_func @__VarToOffset 1 0@ 0@ 0AA6: call_method 0x0044CE80 struct 0x00BA1788 num_params 1 pop 0 ( VARNUMBER = 0@ ) 0AB2: ret 0 :SetTimer 0AB1: call_scm_func @__VarToOffset 1 0@ 0@ 0AB1: call_scm_func @__LabelToOffset 1 2@ 2@ 0AA6: call_method 0x0044CD50 struct 0x00BA1788 num_params 3 pop 0 ( TYPE = 1@ GXT = 2@ VARNUMBER = 0@ ) 0AB2: ret 0 :StopTimer 0AB1: call_scm_func @__VarToOffset 1 0@ 0@ 0AA6: call_method 0x0044CE60 struct 0x00BA1788 num_params 1 pop 0 ( VARNUMBER = 0@ ) 0AB2: ret 0 :__VarToOffset 0A9F: 1@ = current_thread_pointer 0A8E: 2@ = 1@ + 0xDC // mission Flag 0A8D: 2@ = read_memory 2@ size 1 virtual_protect 0 if 2@ == 1 then 1@ = 0x00A48960 // mission locals else 1@ += 0x3C end 0@ *= 4 005A: 1@ += 0@ // address of the local variable 1@ -= 0xA49960 0AB2: ret 1 1@ :__LabelToOffset if 0@ == 0 then 0AB2: ret 1 0 end 0A9F: 1@ = current_thread_pointer 1@ += 0x10 0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0 // baseIP 0062: 1@ -= 0@ // label address 1@ += 3 0AB2: ret 1 1@ :StatusText 0900: 'BB_19' 0000:
An analogue of 03C4 for CLEO:
0AB1: call_scm_func @AddStatusText 4 VARNUMBER = 33 TYPE = 0 GXT = @StatusText LINE = 3
0151:
0AB1: call_scm_func @RemoveStatusText 1 VARNUMBER = 33
03C3:
0AB1: call_scm_func @SetTimer 3 VARNUMBER = 1 TYPE = 1 GXT = @StatusText
014F:
0AB1: call_scm_func @StopTimer 1 VARNUMBER = 1
VARNUMBER - index of a local variable.
GXT-ref transfers through label.
:StatusText 0900: 'BB_19' 0000:
Offline
Thanks for the codes guys,il try them out and reply if it works.
Offline
Pages: 1