The online racing simulator
Countdown button
I wanted to make a countdown button to activate between race end and racerestart and tried this method

Quote :
openPrivButton( "tclos",90,105,20,5,1,10,0,"RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,10,16,"" );
openPrivButton( "clos",96,111,8,11,1,10,32,"^3%cpt%" );


It sort of worked, but missed a couple of # in the countdown. After searching around I found that this is a bug, so I tried several different approaches.

Many of them failed

Finally I came up with this for a test private button:
Part 1
Quote :CASE "!test":
MyTest();
IF( UserIsAdmin( $userName ) == 1 )
THEN
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^310", SC1 );

ELSE
privMsg( langEngine( "%{main_notadmin}%" ) );
ENDIF
BREAK;

Part 2
Quote :
Sub SC1( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^39", SC2 );
EndSub
Sub SC2( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^38", SC3 );
EndSub
Sub SC3( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^37", SC4 );
EndSub
Sub SC4( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^36", SC5 );
EndSub
Sub SC5( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^35", SC6 );
EndSub
Sub SC6( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^34", SC7 );
EndSub
Sub SC7( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^33", SC8 );
EndSub
Sub SC8( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^32", SC9 );
EndSub
Sub SC9( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
openPrivButton( "clos",96,111,8,11,1,2,32,"^31" );
EndSub

I had to repeat the lines:

openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );

every iteration to make sure all text and buttons finished exactly at the same time.

I have a couple of questions:
1. Is there a more elegant way of coding this?
2. Where abouts do I put this code so it will be visible between races? (races already restart automatically with $AutoRestartRaceSec = 10; )
There is a much shorter way (see below) but the problem is, it just runs the whole for-loop at once. I can't figure out how to make it wait a little while, but maybe someone else can finish it:


CASE "!counter":
openPrivButton( "tclos",90,105,20,5,1,2,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,2,16,"" );
FOR ($i=10;$i>0;$i=$i-1)
$remaining_time=$i;
openPrivButton( "clos",96,111,8,11,1,2,32,"^3" . $remaining_time );
privmsg("Debug: " . $remaining_time);
ENDFOR
BREAK;

Thanks for the heads up on the FOR loop.
I have tried several ways to create a delay but it seems you cannot break out of a loop to backcall a sub. The backcall still works but only AFTER the loop has finished.
Have messed about with DelayedCommand with no good results.
Yisc's is a more elegant solution, but why didn't you do something like

Quote :
Sub SC1( $KeyFlags,$id )
openPrivButton( "tclos",90,105,20,5,1,-1,0,"^7RACE STARTS IN:" );
openPrivButton( "bclos",95,110,10,13,1,-1,16,"" );
openPrivButton( "clos",96,111,8,11,1,1,32,"^39", SC2 );
EndSub
Sub SC2( $KeyFlags,$id )
openPrivButton( "clos",96,111,8,11,1,1,32,"^38", SC3 );
EndSub
Sub SC3( $KeyFlags,$id )
openPrivButton( "clos",96,111,8,11,1,1,32,"^37", SC4 );
EndSub
Sub SC4( $KeyFlags,$id )
..........

Sub SC9( $KeyFlags,$id )
closePrivButton( "tclos&bclos&clos");
openPrivButton( "clos",96,111,8,11,1,1,32,"^1RESTARTING", SC10 );
EndSub
Sub SC10( $KeyFlags,$id )
cmdLFS( "/msg restart);
EndSub

My sub numbering and cmdLFS might be wrong.

The -1 in the button time in Sub SC1 keeps it open until you close the buttons at end (Sub SC9).

And if you're doing timer for restart, shouldn't you be using global buttons (openGlobalButton) rather than private buttons?

Also, maybe a neat thing to do, would be having the countdown text move on same line from left to right, right to left, left to right, etc, and change text colour every time you change text direction?

39
--38
----37
------36
--------35
------34
----33
--32
31
--30

Start of with

openGlobalButton( "bclos",50,110,100,13,1,-1,16,"" ); # increase width of button

and have countdowns like

openGlobalButton( "clos",51,111,8,11,1,1,32,"^39", SC2 );
......
openGlobalButton( "clos",59,111,8,11,1,1,32,"^38", SC3 ); # move button 1 button width right from previous button
......openGlobalButton( "clos",67,111,8,11,1,1,32,"^37", SC4 ); # move button 1 button width right from previous button
......
openGlobalButton( "clos",75,111,8,11,1,1,32,"^36", SC5 ); # move button 1 button width right from previous button
......openGlobalButton( "clos",83,111,8,11,1,1,32,"^35", SC6 ); # move button 1 button width right from previous button
......
openGlobalButton( "clos",75,111,8,11,1,1,32,"^24", SC7 ); # move button 1 button width left from previous button and change font colour
......
Ah yes , I should have thought of leaving all the buttons open during the count then close them all at the end. Was so wrapped up trying to get them all to timout at the same time I forgot about that feature :tired::doh:

The only reason I wasnt using global buttons for the test was that I didnt want to annoy the visitors on my test server with constant timers popping up, but still wanted them there to comment on other aspects of the lapper functions I had implemented.

I'm still struggling to delay the FOR loop so the countdown doesnt happen all at once tho'.
Hi,

You can try something like this.


$delay=30;
openGlobalButton ("test1",55,0,20,3,3,$delay,32,"^3Next Race in^2 (%cpt%) ^3second(s)" );
DelayedCommand( $delay+1, start_race );

Sub start_race()
cmdLFS( "/restart" );
EndSub

UPDATE:

Ok, I have managed to get a working timer that counts down evenly and does not miss any numbers.
Quote :
Sub start_countdown()
openGlobalButton( "cdt",89,113,20,4,1,-1,0,"^7RACE RESTARTS IN:" );
openGlobalButton( "cdb",90,110,25,10,1,-1,16,"" );
openGlobalButton( "cdc",108,111,6,8,1,-1,32,"" );
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^310", SC1 );
EndSub
Sub SC1( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^39", SC2 );
EndSub
Sub SC2( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^38", SC3 );
EndSub
Sub SC3( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^37", SC4 );
EndSub
Sub SC4( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^36", SC5 );
EndSub
Sub SC5( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^35", SC6 );
EndSub
Sub SC6( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^34", SC7 );
EndSub
Sub SC7( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^23", SC8 );
EndSub
Sub SC8( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^22", SC9 );
EndSub
Sub SC9( $KeyFlags,$id )
openGlobalButton( "cdn",108,111,6,8,1,2,32,"^21", SC10 );
EndSub
Sub SC10( $KeyFlags,$id )
closeGlobalButton( "cdt&cdb&cdc&cdn" );
# cmdLFS( "/restart" );
EndSub

The problem with the above method is that, as backcalls use keyflags, the mouse shows on the racing screen while the buttons are active.

So I tried a different method.
Quote :
Sub start_countdown2()
openGlobalButton( "cdt",89,113,20,4,1,-1,0,"^7RACE RESTARTS IN:" );
openGlobalButton( "cdb",90,110,25,10,1,-1,16,"" );
openGlobalButton( "cdc",108,111,6,8,1,-1,32,"" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^310" );
DelayedCommand( 1, SC1a );
EndSub
Sub SC1a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^39" );
DelayedCommand( 1, SC2a );
EndSub
Sub SC2a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^38" );
DelayedCommand( 1, SC3a );
EndSub
Sub SC3a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^37" );
DelayedCommand( 1, SC4a );
EndSub
Sub SC4a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^36" );
DelayedCommand( 1, SC5a );
EndSub
Sub SC5a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^35" );
DelayedCommand( 1, SC6a );
EndSub
Sub SC6a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^34" );
DelayedCommand( 1, SC7a );
EndSub
Sub SC7a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^23" );
DelayedCommand( 1, SC8a );
EndSub
Sub SC8a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^22" );
DelayedCommand( 1, SC9a );
EndSub
Sub SC9a()
closeGlobalButton( "cdn" );
openGlobalButton( "cdn",108,111,6,8,1,-1,32,"^21" );
DelayedCommand( 1, SC10a );
EndSub
Sub SC10a()
closeGlobalButton( "cdt&cdb&cdc&cdn" );
EndSub

This solved the problem of the mouse cursor showing, but the timing is very poor. Some numbers stay visible longer than others during the countdown.

QUESTIONS:
1. Is it possible to show globalbuttons using backcalls and not have the mouse cursor visible?

2. Is it possible to use the delayedcommand method without the timing issues?

3. I have called this event from:-
Quote :
Event OnFinish( $userName ) # Player event
$delay=60;
DelayedCommand( $delay, start_countdown );
EndEvent

But although it starts the countdown from the first racer to finish, it also starts a new countdown for anyone else finishing withing the 60 seconds. Anyway to fix that?

Sorry for my noobness, but I AM trying.
Quote from Austin Hedley :UPDATE:
1. Is it possible to show globalbuttons using backcalls and not have the mouse cursor visible?

I think pressing Shift+Z should solve that
You have LFS Z28? (just to confirm)
I do indeed have Z28.
Let me clarify whats happening.
When in race and the timer is NOT showing, the mouse remains hidden.
When in race and timer IS showing , because the countdown button has a backcall, the mouse becomes visible and the button is clickable until timer runs out, then the mouse returns to its hidden state. The mouse will not hide while the button is active.
SHIFT+Z shows and hides the mouse normally once the buttons are closed.
As player, the only thing I know is that I can hide my mouse while having buttons in my screen. Are two or more types of buttons?
That's because buttons were initialy created to click on, so you need a mouse for that. In Lapper you can have buttons on which clicking isn't needed, so it would be nice if insim (that's something Scawen has to add) would have an option which indicates a button doesn't need clicking.
Quote from Yisc[NL] :it would be nice if insim (that's something Scawen has to add) would have an option which indicates a button doesn't need clicking.

That option already exists, been around since buttons were first introduced.
Quote from filur :That option already exists, been around since buttons were first introduced.

Ah, I didn't know that.
In that case it's something Gai-Luron has to add to Lapper buttons then
Quote from Austin Hedley :

QUESTIONS:
1. Is it possible to show globalbuttons using backcalls and not have the mouse cursor visible?

2. Is it possible to use the delayedcommand method without the timing issues?

3. I have called this event from:-


But although it starts the countdown from the first racer to finish, it also starts a new countdown for anyone else finishing withing the 60 seconds. Anyway to fix that?

Sorry for my noobness, but I AM trying.

Hi,

1: When a button is clickable ( when you use -1 ) and using a backcall you always get the mouse cursor.

2: I use the delayedcommand method in mine scripts and mostly it works ok, very some time it skips a number but mine server is not the fasted one.(P4 1.5Gz 512Mb) so maybe its that why it skips sometimes a number at mine server.

3: In case of using the Event OnFinish( $userName ) you have to use
Event OnResult( $userName,$flagConfirm ) # Player event
IF(GetCurrentPlayerVar("FinishedPos")==1)
THEN
$delay=60;
DelayedCommand( $delay, start_countdown );
ENDIF
EndEvent

If you want to start the restart counter as the last driver finish the race you have to count all drivers at the start of race and when someone leave the race its number of drivers - 1 .
At the end of the race just count how many people are finisished the race and by the last start the restart counter. ( and set no mid race join )
Quote from Tim NL :
1: When a button is clickable ( when you use -1 ) and using a backcall you always get the mouse cursor.

I think a non clickable button (or a flag to state clickable on/off in global and private buttons that use backcalls) might be usefull, will post into the request thread.

Quote :
2: I use the delayedcommand method in mine scripts and mostly it works ok, very some time it skips a number but mine server is not the fasted one.(P4 1.5Gz 512Mb) so maybe its that why it skips sometimes a number at mine server.

I'm running a quad core 2.8Ghz with almost no unnecessary tasks running on startup and I still get the odd number missing or uneven timing in the countdown delay scripts or %cpt% functions . I think it has to do with the way lapper handles time.

Quote :
3: In case of using the Event OnFinish( $userName ) you have to use
Event OnResult( $userName,$flagConfirm ) # Player event
IF(GetCurrentPlayerVar("FinishedPos")==1)
THEN
$delay=60;
DelayedCommand( $delay, start_countdown );
ENDIF
EndEvent


Thank you for your replies, they are most welcome. I was close to getting it right, after finishing reading all the changelog.txt and playervars.txt. The only thing I was missing was the $flagconfirm , what is this for? I cannot find any reference to it in any of the files I have other than where it is used in lpr files.
Hi,

You can use the $flagConfirm to be sure that who won is really the winner.

1. Event OnResult now receive the confirm flags
CONF_MENTIONED 1
CONF_CONFIRMED 2
CONF_PENALTY_DT 4
CONF_PENALTY_SG 8
CONF_PENALTY_30 16
CONF_PENALTY_45 32
CONF_DID_NOT_PIT 64

Example:
If a player have a 30 second penalty the $flagConfirm must be 16 (CONF_PENALTY_30) + 2 (CONF_CONFIRMED) = 18
If a player have a 45 second penalty the $flagConfirm must be 32 (CONF_PENALTY_45) + 2 (CONF_CONFIRMED) = 34

Event OnResult( $userName,$flagConfirm ) # Player event

SWITCH( GetCurrentPlayerVar("FinishedPos") )
CASE 1:
IF( $flagConfirm == 2 || $flagConfirm == 18 || $flagConfirm == 34 )
THEN
show and give points


FGED GREDG RDFGDR GSFDG