View Full Version : Custom penalties?
Sjoenne
10th July 2009, 10:50
HI everybody!
How can I do custom penalties during race?
Running Dedicated server with LFS lapper.
Is it possible to do something like /p_sg racername +extra time
The 10 sec stop n go is waay to short a period.
We're arranging a 6 hour race, and want to allow reset momentarily by admin - triggering(auto or by admin) a stop n go at around 2-3 mins
Can it be done?:thumb:
Sjoenne
11th July 2009, 23:08
Maybe it isn't possible at all to alter the built in penalties?
bunder9999
11th July 2009, 23:44
it is possible to trigger penalties... its been a while since i did it, but i had one coded for pitting early... what i did was make a variable and set it to 1 if they pitted early, then on split1 if the driver has that variable, dish out the penalty (and reset all the variables).
you can't give a double penalty though, or modify the existing penalties... if you wanted a worse penalty than a single S+G, you could make it give out a second S+G after the first one.
cheers
Krayy
12th July 2009, 06:04
I've just finished creating a custom penalty system for car resets. The way it works is that if a racer uses a car reset, it allocates a Drive Through, however if they are on the final lap, it adds a 30 sec penalty, as a DT on the last lap would effectively DQ them, as they wouldn't have enough race time to do it.
Things I have noticed are that allocating a penalty using cmdLFS( "/p_dt " . GetCurrentPlayerVar( "Username" ) ); give the race mesage "Drive through penalty, Penalty given by Administrator". There doesnt seem to be any way of overriding the message or creating a custom penalty outside the standard insim ones.
The only thing I could suggest is to maybe add additional time to the racers final time at the end of the race in the OnResult or OnFinish functions.
Code for car resets is using v5.843 base:
NB: I am rewriting the RaceLaps function to account for timed races as well as races over 100 laps, so will post that when done.
LFSLapper.lpr:
###########################
#Actions to do on Car Reset#
###########################
$MaxCarResets = 3; # Set to a positive number to limit number of race resets
Event OnMaxCarResets() # Penalty if player has used car reset more than the max
globalMsg( "Max car resets reached for" . GetCurrentPlayerVar( "NickName" ) );
globalMsg( "Race Laps: " . GetCurrentPlayerVar( "LapsDone" ) . "/" . getLapperVar( "RaceLaps" ) );
IF( GetCurrentPlayerVar( "LapsDone" ) >= (getLapperVar( "RaceLaps" )-1) )
THEN
cmdLFS( "/p_30 " . GetCurrentPlayerVar( "Username" ) );
ELSE
cmdLFS( "/p_dt " . GetCurrentPlayerVar( "Username" ) );
ENDIF
EndEvent
Event OnCarReset() # Do something when the car resets
globalMsg( "Car Reset for " . GetCurrentPlayerVar( "NickName" ) . " on lap " . (GetCurrentPlayerVar( "LapsDone" )+1) . " of " . getLapperVar( "RaceLaps" ) );
IF( (GetCurrentPlayerVar( "LapsDone" )+1) >= getLapperVar( "RaceLaps" ) )
THEN
cmdLFS( "/p_30 " . GetCurrentPlayerVar( "Username" ) );
ELSE
cmdLFS( "/p_dt " . GetCurrentPlayerVar( "Username" ) );
ENDIF
EndEvent
managePacket.cs:
...
void managePacket(InSim.Decoder.CRS crs)
{
infoPlayer currInfoPlayer;
currInfoPlayer = listOfPlayers.getPlayerByPLID(crs.PLID);
if (currInfoPlayer == null)
return;
if( currRace.inRace ) {
if ( newCfg.varsLapper.MaxCarResets > 0 ) {
currInfoPlayer.NumCarResets++;
if (currInfoPlayer.NumCarResets >= newCfg.varsLapper.MaxCarResets)
newCfg.executeFunction("OnMaxCarResets", currInfoPlayer, null);
else
newCfg.executeFunction("OnCarReset", currInfoPlayer, null);
} else
newCfg.executeFunction("OnCarReset", currInfoPlayer, null);
}
}
infoPlayer.cs:
public class infoPlayer
...
public int NumCarResets = 0;
...
readCfg.cs
...
OnResult,
OnCarReset,
OnMaxCarResets,
...
parseEvents.cs:
...
// Numeric return
case "numcarresets":
val.typVal = GLScript.typVal.num;
val.fval = currInfoPlayer.NumCarResets;
break;
case "laps":
...
listPlayers.cs:
...
(currInfoPlayer as infoPlayer).NbFastDriveOnPit = 0;
(currInfoPlayer as infoPlayer).NumCarResets = 0;
...
Sjoenne
12th July 2009, 09:04
Thanks for your replies guys - but sadly it seems like we have to live with time penalties or short stop n go's.
We're doing our first small "endurance" race, and it would be perfect to get all cars home and safe. We will have a race-admin surveilling the post-reset penalty-pitstops(user has to beg admin for /canreset=yes first hehe), and time them, så that they stay as long as laid out in our rules instead.
PS. Great reset function Krayy! ;)
Krayy
12th July 2009, 09:14
Thanks for your replies guys - but sadly it seems like we have to live with time penalties or short stop n go's.
We're doing our first small "endurance" race, and it would be perfect to get all cars home and safe. We will have a race-admin surveilling the post-reset penalty-pitstops(user has to beg admin for /canreset=yes first hehe), and time them, så that they stay as long as laid out in our rules instead.
PS. Great reset function Krayy! ;)
I'll be sure to post an update once I've redone the RaceLaps functions and we've had a chance to fully test it.
Our reasoning is that some of our racers are more serious than others, so we wanted to allow resets if you want them, but also not to provide a competitive advantage. This system allows us to recover from crashes, gravel traps or other mishaps and a Drive Through is a good compromise for us time-wise.
Enduros are a special case too in that tyre wear is repaired in a reset, so maybe a stop/go would be more appropriate. If it is, then we just change the LFSLapper.lpr file to reflect that. I might chuck in a function to LFSLapper to configure Car Reset behavior by setting some internal vars.
BTW, what's you base version?
Sjoenne
12th July 2009, 09:33
Hmmm.. I'm not exactly sure that I understand waht you mean.
We want to change the stop and go time, so a reset(maybe with a max of 3 total) will autotrigger a S&G penalty that last around what a semi-slow lap time is. It should be a pain in the ays to sit there in the pits doing nothing for a lap hehe.
What's my base version? I don't know? I'm new to all this serverthingy sorry.
Gai-Luron
12th July 2009, 17:04
I've just finished creating a custom penalty system for car resets.
I include your code in LFS Lapper, but some part are not present in your released code, like CRS in insim4.cs and raceLaps....
I create it. I also modify your GLScript code to work in multilanguage mode
All work fine here. Tell me when you have finished coding ;) and i release the modified version ;)
Happy to see some coder add features in LFSLapper and have courage to read my code :)
###########################
#Actions to do on Car Reset#
###########################
$MaxCarResets = 3; # Set to a positive number to limit number of race resets
Event OnMaxCarResets() # Penalty if player has used car reset more than the max
globalMsg( langEngine( "%{main_maxreset}%" , GetCurrentPlayerVar( "NickName" ) ) );
globalMsg( langEngine( "%{main_maxreset1}%" , GetCurrentPlayerVar( "LapsDone" )+1, getLapperVar( "RaceLaps" ) ) );
IF( GetCurrentPlayerVar( "LapsDone" ) >= (getLapperVar( "RaceLaps" )-1) )
THEN
cmdLFS( "/p_30 " . GetCurrentPlayerVar( "Username" ) );
ELSE
cmdLFS( "/p_dt " . GetCurrentPlayerVar( "Username" ) );
ENDIF
EndEvent
Event OnCarReset() # Do something when the car resets
globalMsg( langEngine( "%{main_oncarreset}%", GetCurrentPlayerVar( "NickName" ),GetCurrentPlayerVar( "LapsDone" )+1,getLapperVar( "RaceLaps" ) ) );
IF( (GetCurrentPlayerVar( "LapsDone" )+1) >= getLapperVar( "RaceLaps" ) )
THEN
cmdLFS( "/p_30 " . GetCurrentPlayerVar( "Username" ) );
ELSE
cmdLFS( "/p_dt " . GetCurrentPlayerVar( "Username" ) );
ENDIF
EndEvent
Lang "EN"
...
main_maxreset = "Max car resets reached for {0}";
main_maxreset1 = "Race Laps: {0}/{1}";
main_oncarreset = "Car Reset for {0} on lap {1} of {2}";
...
EndLang
Gai-Luron
Krayy
12th July 2009, 23:15
I include your code in LFS Lapper, but some part are not present in your released code, like CRS in insim4.cs and raceLaps....
I create it. I also modify your GLScript code to work in multilanguage mode
All work fine here. Tell me when you have finished coding ;) and i release the modified version ;)
Gai-Luron
Thanks for that Gai-Luron.
The reason that I didn't include those bits was that I'm rewriting it as my current version didn't take into account timed races. This will override the RaceLaps parameter (although keeping the RaceLaps info in the currRace data will remain).
I'll be writing a function called "isLastLap" and will calc either actual laps remaining vs the current players laps, or if it is a timed race, try to track their avg lap speed and compare that to the amount of time remaining.
Then I'll throw in some extra lapper functions to allow for changing maxCarResets and maybe the penalties on the fly.
I'll have this done in a couple of days when I get time and post it then.
Sjoenne
13th July 2009, 01:45
I guess there's no way to do custom penalties like a 2 min stop n go?
Krayy
13th July 2009, 03:02
I guess there's no way to do custom penalties like a 2 min stop n go?
I can't see how your racers would accept a 2 min standing penalty. My regulars would rage quit in an instant.
Gai-Luron
13th July 2009, 09:44
Thanks for that Gai-Luron.
The reason that I didn't include those bits was that I'm rewriting it as my current version didn't take into account timed races. This will override the RaceLaps parameter (although keeping the RaceLaps info in the currRace data will remain).
I'll be writing a function called "isLastLap" and will calc either actual laps remaining vs the current players laps, or if it is a timed race, try to track their avg lap speed and compare that to the amount of time remaining.
Then I'll throw in some extra lapper functions to allow for changing maxCarResets and maybe the penalties on the fly.
I'll have this done in a couple of days when I get time and post it then.
For the function who change maxCarResets is better to do a generic function who can change some config parameter in varslapper ( i planed to write this function). The better way is to have a list of parameter can be changed on the fly because all parameter can't be changed in this way.
For the average laptime you have ETime in LAP packet and LapsDone in same packet.
Gai-Luron
Sjoenne
13th July 2009, 10:36
I can't see how your racers would accept a 2 min standing penalty. My regulars would rage quit in an instant.
The alternative to being reset, is to leave the race - and they know that before race-start.
IRL endurance racing doesn't have a magical reset function :D
Sjoenne
13th July 2009, 10:39
For the function who change maxCarResets is better to do a generic function who can change some config parameter in varslapper ( i planed to write this function). The better way is to have a list of parameter can be changed on the fly because all parameter can't be changed in this way.
For the average laptime you have ETime in LAP packet and LapsDone in same packet.
Gai-Luron
You seem like you are one of those guys who knows the ins and outs of LFS...:thumb:
Could you please set this straight: Is it possible to change the stop n go period from 10 sec to what admin defines?
Krayy
13th July 2009, 21:31
For the function who change maxCarResets is better to do a generic function who can change some config parameter in varslapper ( i planed to write this function)...
You mean this one:
public void setLocalVar(string idVar, string value )
{
// TODO
}
Yep, I can do that.
Krayy
14th July 2009, 21:20
Hey there Gai-Luron,
In writing the setPlayerVar function, I've come up with a solution that I need to get you to vet.
Instead of writing a huge case statement like the getPlayerVar function and defining the return types etc, why not cast the type in a HashTable that is defined from within the LFSLapper.lpr file so that anyone creating vars and using them in context are in the same place.
To do this, I'd use a function to define the var and add it to the HashTable in the lpr file like this:
definePlayerVar("accelerationendspeed", "num");
definePlayerVar("accelerationstartspeed", "num");
definePlayerVar("accelerationtime", "num");
definePlayerVar("anglevelocity", "num");
definePlayerVar("authlevel", "str");
definePlayerVar("avgspeed", "num");
...etc
The definePlayerVar function pseudo-code is:
HashTable PlayerVars;
definePlayerVar(name, type) {
if type == "num" then
PlayerVars.Add(name, GLScript.typVal.num)
else if type == "str" then
PlayerVars.Add(name, GLScript.typVal.str)
end if
}
That way, the var type is defined in the has table for easy reference in GetPlayerVar and SetPlayerVar:
GetPlayer(VarGLScript.unionVal val, string idVar, string userName)
...
case "nickname":
val.typVal = PlayerVars(idvar);
val.sval = quote(currInfoPlayer.nickName);
break;
...
SetPlayerVar(VarGLScript.unionVal val, string idVar, string userName) {
typVal = PlayerVars(idvar);
CheckType(val, typVal) else return
if typVal = num then
val.fval=val
else if typval = str then
val.sval = val
endif
The pseudo code is very loose, but thats the genral idea...thoughts?
Gai-Luron
14th July 2009, 21:39
Hello,
setPlayerVar already exist and create a GLScript var associated to player in GLScript!, but no change on builtin var, for now it's normal and i don't think it's really important. Give me an example of a builtin var for player it's interesting to change.
I think about setConfVar to change some config var in GLScript like maxCarReset,MaxFloodLines,MinAngleVelocity, etc...
setConfVar( idvar,value );
for now we can have read access to confvar with $confVar["idvar"] but i think this can be removed and replace it with getConfVar( idvar,value );
I have installed a SVN repository here and you can use tortoisesvn to retreive source and update.
https://lfslapper.svn.sourceforge.net/svnroot/lfslapper
Gai-Luron
Krayy
14th July 2009, 22:33
I should learn to read....of course I was referring to the
public void setLocalVar(string idVar, string value )
{
// TODO
}
and retreiveVarLapper (sp?) functions, so the hashtable would be for localvars
Sjoenne
14th July 2009, 23:21
Does this have anything to do with the topic?
I feel like I have to repeat myself over and over again: So it's not possible to change the stop-n-go length? ;););)
Krayy
14th July 2009, 23:29
Does this have anything to do with the topic?
I feel like I have to repeat myself over and over again: So it's not possible to change the stop-n-go length? ;););)
No you cannot change the times of the penalties. Valid penalties are:
PENALTY_DT, // Drive through
PENALTY_SG, //stop/go
PENALTY_30, // 30 seconds
PENALTY_45, // 45 seconds
and thats it.
Sjoenne
14th July 2009, 23:32
THANKS! finally:spin::)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.