The online racing simulator
#1 - Krayy
[CODE] Car Reset Penalties **UPDATED**
NOTE: This code is for Lapper version 5.844, with the supplied Patch file applied
Hi all,

As a follow on from the Custom Penalties thread, here is the code to add penalties for racers who use Car Resets. This comprises a patch to the stock 5.844 source, along with the code below to be added at the bottom of the LFSLapper.lpr file.

The reasoning behind this patch is that we wanted to ensure that someone who used car resets during a race did not get an unfair advantage by having new tyres, damage repair etc over a racer who has run a clean race but who may be suffering from wear and tear of the tyres or car.

To that end, the code will allocate a Drive Through penalty when a reset is used during a race, but this is substituted with a 30 second time penalty on the last lap of a race as a Drive Through on the last lap is automatic disqualification.

The code also allows for different penalties if the racer uses the reset option too many times (the $MaxCarResets parameter in the LFSLapper.lpr file) where you can /spec them or whatever by changing the lfsCmd in the OnMaxCarResets Event.

To use the attached Patch file, you will either need to use TortoiseSVN and apply it, or just go through the source manually, as it's all pretty self explanatory.


# *** PUT THIS IN YOUR LFSLapper.lpr file ***

############################
#Actions to do on Car Reset#
############################

$MaxCarResets = 6; # Set to a positive number to limit number of race resets

Event OnMaxCarResets() # Spectate if player has used car reset more than the max
globalMsg( langEngine( "%{main_maxreset}%" , GetCurrentPlayerVar( "NickName" ) ) );
cmdLFS( "/spec " . GetCurrentPlayerVar( "Username" ) );
EndEvent

Event OnCarReset() # Do something when the car resets
globalMsg( langEngine( "%{main_oncarreset}%", GetCurrentPlayerVar( "NickName" ) ) );
IF( $ConfVar["MaxCarResets"] > 0 )
THEN
openPrivButton( "carres_warn",50,60,100,15,5,4,16, langEngine( "%{main_specwarn}%" ) );
openPrivButton( "carres_msg1",50,75,100,10,5,4,16,langEngine( "%{main_resetrest}%",($ConfVar["MaxCarResets"] - (GetCurrentPlayerVar( "NumCarResets" )+1))));
privdelayedcommand( 4, ApplyCarResetPenalty);
ELSE
privdelayedcommand( 1, ApplyCarResetPenalty);
ENDIF
EndEvent

Sub ApplyCarResetPenalty()
IF( getLapperVar( "RaceLapsLeft" ) <= 1 )
THEN
IF( (GetCurrentPlayerVar( "penaltynew") < 5))
THEN
cmdLFS( "/p_30 " . GetCurrentPlayerVar( "Username" ) );
ENDIF
ELSE
IF( (GetCurrentPlayerVar( "penaltynew") < 1))
THEN
cmdLFS( "/p_dt " . GetCurrentPlayerVar( "Username" ) );
ENDIF
ENDIF
EndSub

Attached files
Krayy_Lapper-5844_Patch.txt - 7.1 KB - 194 views
#2 - Krayy
Updated code to make it more user friendly for the drivers using Buttons:

See Post below

Great!

Please change your code in FSLapper.lpr file this this one


Please for next patch on LFSLapper use svn repository at

https://sourceforge.net/projects/lfslapper/

and tortoise SVN

Thank's

############################
#Actions to do on Car Reset#
############################

$MaxCarResets = 5; # Set to a positive number to limit number of race resets

Event OnMaxCarResets() # Spectate if player has used car reset more than the max
globalMsg( langEngine( "%{main_maxreset}%" , GetCurrentPlayerVar( "NickName" ) ) );
cmdLFS( "/spec " . GetCurrentPlayerVar( "Username" ) );
EndEvent

Event OnCarReset() # Do something when the car resets
globalMsg( langEngine( "%{main_oncarreset}%", GetCurrentPlayerVar( "NickName" ),GetCurrentPlayerVar( "LapsDone" )+1 ));
IF( $ConfVar["MaxCarResets"] > 0 )
THEN
openPrivButton( "carres_warn",50,60,100,15,5,4,16, langEngine( "%{main_specwarn}%" ) );
openPrivButton( "carres_msg1",50,75,100,10,5,4,16,langEngine( "%{main_resetrest}%",$ConfVar["MaxCarResets"] - GetCurrentPlayerVar( "NumCarResets" )));
privdelayedcommand( 4, ApplyCarResetPenalty);
ELSE
privdelayedcommand( 1, ApplyCarResetPenalty);
ENDIF
EndEvent

Lang "EN"
...

main_maxreset = "{0} spectated for exceeding max car resets";
main_oncarreset = "Car Reset by {0} on lap {1}";
main_specwarn = "^1Spectate Warning";
main_resetrest = "^2You have^3 {0} ^2car resets left";
...
EndLang

Lang "FR"
...
main_maxreset = "{0} mis en spectateur pour excès de reset de voiture";
main_oncarreset = "Reset de voiture par {0} au tour {1}";
main_specwarn = "^1Attention mise en spectateur";
main_resetrest = "^2Il vous reste^3 {0} ^2reset de voiture";
...
EndLang


Thanks for the new release Gai-Luron.
Thanks for the addon Krayy.
Thanks for the updated GUI Tim.
#5 - Krayy
Code updated to include handling of timed races as well as long races. The 30 second penalties will now be applied when a timed race has less than 5 minutes remaining:

CODE IN FIRST POST
#6 - Krayy
See updated lapper code and source patch file in first post.

FGED GREDG RDFGDR GSFDG