The online racing simulator
basic RegisterNodeAction problem
Hi, i juste discovered LFS lapper and airio and i choose to use the lapper! I want to do something very simple, but i must miss something. I have : RegisterNodeAction( "BL1" , 300 , DisplaySpeed,ExitDisplaySpeed ); that call's: DisplaySpeed and ExitDisplaySpeed.

I want that in the first use of the function DisplaySpeed, only the speed is displayed, for the other DisplaySpeed using i want to compare the speed and the top speed to set topSpeed and display a message accordingly.

Here what i did:

Quote :Sub DisplaySpeed( $userName )
----------$speed = GetCurrentPlayerVar( "InstantSpeed" );
IF($i==1)
THEN
----------$topSpeed = $speed;
----------privMsg( "^7>Vitesse: ( ^3" . $speed . " ^7) km/h");
----------$i = $i +1 ;
ELSE IF ($speed > $topSpeed)
THEN
----------$ancien = $topSpeed;
----------$topSpeed = $speed;
----------privMsg( "^7>Nouveau Top speed1 ( ^3" . $TopSpeed . " ^7) km/h");
ELSE
----------privMsg( "^7>Vitesse: ( ^3" . $speed . " ^7) km/h");
ENDIF
EndSub

I'll use the $ancien (previous top speed) after resolving this..
The problem is that i dont know where to instance my $i variable ($i represent the # of times the function have been called) so it can be set outside the DisplaySpeed function otherwise it get's overwrited. I tryed to instance the $i in many places in the LFSlapper.lpr. Never got it working. (i tryed privMsg( "^7>( ^3" . $i . " ^7) "); to chek the $i value and it was ( ), empty)

I would need help please.
I think ill be able to code some very great ideas as soon as i figure out some details about the lapper.

ty

Olivier, Canada
Hi

Good on you for using Lapper!

I'm no good at arrays, but few points.

Hopefully the ---------- lines in your code are only meant to signify spaces that are there. Not sure how lapper would cope with them if they were real.

I think you have to use FOR - ENDFOR when using arrays.

While ago, Krayy (one of our great lapper programmers) made public a bit of code for giving different messages depending on car and acceleration times, all using arrays.

I've attached it, so have look thru it, and see if it helps to show how arrays should be used.

Good luck.



PS Not sure you should use the "km/h" part - I use the imperial mph measurement myself
Attached files
krayy_acceleration.txt - 3.8 KB - 223 views
Hello,

you can use player var for topspeed. First, you need to set in "onconnect" event.
...
setCurrentPlayerVar( "topSpeed",0 )
...

Theorically in your code you can put


...
$speed = toint( GetCurrentPlayerVar( "InstantSpeed" ) );
$topspeed = toint( GetCurrentPlayerVar( "topSpeed" ) );
IF ($speed > $topSpeed)
THEN
setCurrentPlayerVar( "topSpeed", $speed );
privMsg( "^7>Nouveau top speed: ( ^3" . $speed . " ^7) km/h");
ELSE
privMsg( "^7>Vitesse: ( ^3" . $speed . " ^7) km/h");
ENDIF
...

bye

Gai-Luron
hi there
is there a function to make a delay with milliseconds???
Thanks a lot sinanju for the arrays tip! It would be very nice if you could post a zipped file of all the sample that you have, cause i cant find any.

Gai-Luron said:
Quote :There are another functions, look in config file

It seems that i cant find the descriptionand usage of the other functions, where should i look?

Now i want to compare all the current player topSpeed
I'dd use a for loop like:

for($i = 0, $i < getLapperVar( totalPlayers ), $i = $i +1)
{
$topSpeed = 0;
$playerTopSpeed = GetPlayer[i]Var("topSpeed");
IF($playerTopSpeed > $topSpeed)
{
$playerName = GetPlayerVar( player[i], "NickName" )
$newTopSpeed = $playerTopSpeed;
}
}
IF($newTopSpeed>globalTopSpeed)
{
setLapperVar( "GlobaltopSpeed",$newTopSpeed );
globalMsg( langEngine( "N o u v e a u T o p S p e e d: {0} driver: {1}", $newTopSpeed,$playerName));
}

It know that those: getLapperVar( totalPlayers ), player[i], getPlayer[i]Var("topSpeed"), GetPlayerVar( player[i], "NickName" ) and setLapperVar( "GlobaltopSpeed",$newTopSpeed ), does not exist, i dont know where to find informations on the right syntax to use.

What is the good syntax?/ Where should i look to find my answers?

Thanks Gai-Luron!
I appreciate the lapper a lot.

Olivier
Hello

using FOREACH and GetListOfPlayers()
This is the functions to use not the functionnal code.



$ListOfPlayers = GetListOfPlayers();
$CurrTopSpeed = GetStoredValue( "GlobaltopSpeed" );
FOREACH( $CurrUname IN $ListOfPlayers )
....
$currTopSpeed = getPlayerVar( $CurrUname,"topspeed" );
....
SetStoredValue( "GlobaltopSpeed", $newTopSpeed );
....
ENDFOREACH



Gai-Luron
#507 - sju
Hi.

I've server in 500 servers. I installed lfslapper to it. I made all? configs what are needed. Lapper connect to server, but no welcome message and it doesn't answer to any commands. All what it do is telling: LFSLapper go in Work State. There is not any errors in logs.
Any ideas to get it work?

sju
Attached images
lapper.jpg
sju said:
Quote :Any ideas to get it work?

Did you set the insim to the specified port? (by defaut 29999)

You need to be admin of the server and type:
/insim 29999

While in-game.

Hope it solve your problem!

Olivier
#509 - sju
Port is correct.
the port and ip are good because the insim connects to the server.

did u change something on LFSLapper.LPR?? or other files
if uso: check the errorfile of lapper (192.168.0.xxx-29999-ERR)
else
check: (192.168.0.xxx-29999-MSS) for error with connecting or loading the insim.

U will find these files in:
\bin\default\logs
sju said:
Quote :All what it do is telling: LFSLapper go in Work State.

From LapperInstance.cs
else if (infos.autoStart == infoInstance.autoStartVal.AUTO_WORK)
{
#region workMode
openStbMode();
SendMsg("[B][SIZE=3]LFSLapper go in Work State[/SIZE][/B]");
...
}

I think you gotta wait for Gai-Luron's help for this

I also have 3 little questions for you Gai-Luron !

Event OnRaceStart( $NumP ) # Lapper event
SetStoredValue( "GlobaltopSpeed", 0 );
$ListOfPlayers = GetListOfPlayers();
FOREACH( $CurrUname IN $ListOfPlayers )
{
[SIZE=3][B]setPlayerVar( $CurrUname, "topSpeed",0 );[/B][/SIZE]
}
ENDFOREACH
EndEvent

1. Does the overload: setPlayerVar( $CurrUname, "topSpeed",0 ); exist?

EDIT: A simple

FOREACH( $CurrUname IN $ListOfPlayers )
{
...
}
ENDFOREACH

Give's me Errors Illegal character <{> and <}> ?? What is the problem?

I also tryed

FOREACH( $CurrUname IN $ListOfPlayers )
...
BREAK;
ENDFOREACH

And it does not go pass the loop.

2. What language am i coding (in LFSLapper.lpr)?? Python, php...? (as you can see im a beginner in programming)

3. Does LFS was made in c# ?


To everybody else: I'v found where to look for to find all functions, look in
scriptFunctions.cs

To Gai Luron: As i saw your from Paris, France you can pm/write me in french, je suis Québecois!

I started studing computer science last year and i think that what im doiing on this give's me great skills for my next years at school.
I really appreciate you help Gai Luron.

Olivier
Quote from sju :Hi.

I've server in 500 servers. I installed lfslapper to it. I made all? configs what are needed. Lapper connect to server, but no welcome message and it doesn't answer to any commands. All what it do is telling: LFSLapper go in Work State. There is not any errors in logs.
Any ideas to get it work?

sju

Hello,
Port seem good, take a look in log folder
Gai-Luron
Hello,

Quote :1. Does the overload: setPlayerVar( $CurrUname, "topSpeed",0 ); exist?

What you mean by overload

Quote :FOREACH( $CurrUname IN $ListOfPlayers )
...
BREAK;
ENDFOREACH

BREAK; exit the loop at first pass. For this work var $ListOfPlayers must be set first with GetListOfPlayers function. You can see if this var is set using command dumpVar( $ListOfPlayers ); this display on console the content of any var

1. GetListOfPlayer accept an optional argument to sort the list og player
Example:
$list = GetListOfPlayers("U"); # List sorted by userName
Or
$list = GetListOfPlayers("N"); # List sorted by nickName

Dont use { and } in a block structure this is not required

Language you are coding in LFSLapper.lpr is a home made language GLScript ( Gai-Luron Script :razz

LFS is in C++
LFSLapper in C#
#514 - sju
Quote from Gai-Luron :Hello,
Port seem good, take a look in log folder
Gai-Luron

Here is log file
6/6/2010 12:35:00 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:00 -> InSImReceive Thread Started...
-----------------------------------------------------------------------------
6/6/2010 12:35:02 PM
-----------------------------------------------------------------------------
6/6/2010 12:35:02 PM -> Parsing config file...6/6/2010 12:35:05 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:05 -> InSImReceive Thread Started...
6/6/2010 12:35:10 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:10 -> InSImReceive Thread Started...
6/6/2010 12:35:15 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:15 -> InSImReceive Thread Started...
6/6/2010 12:35:21 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:21 -> InSImReceive Thread Started...
6/6/2010 12:35:26 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:26 -> InSImReceive Thread Started...
6/6/2010 12:35:31 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:31 -> InSImReceive Thread Started...
6/6/2010 12:35:38 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:38 -> InSImReceive Thread Started...
6/6/2010 12:35:42 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:42 -> InSImReceive Thread Started...
-----------------------------------------------------------------------------
6/6/2010 12:35:45 PM
-----------------------------------------------------------------------------
6/6/2010 12:35:45 PM -> Parsing config file...6/6/2010 12:35:47 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:47 -> InSImReceive Thread Started...
6/6/2010 12:35:52 PM -> Connecting to 127.0.0.1 / 17560
Connection OK
06/06/2010 12:35:52 -> InSImReceive Thread Started...
-----------------------------------------------------------------------------
6/6/2010 12:35:55 PM
-----------------------------------------------------------------------------

And there is no error log, only that MSS.log
Strange?
Hi, something is strange, take a look at the picture and the code.


[SIZE=2]Sub DisplaySpeed( $userName )[/SIZE]
[SIZE=2]$topSpeed = GetCurrentPlayerVar("topSpeed");[/SIZE]
[SIZE=2]$instantSpeed = GetCurrentPlayerVar("InstantSpeed");[/SIZE]
[SIZE=2]globalMsg ("^7DEBUG: current player topSpeed = " . $topSpeed);[/SIZE]
[SIZE=2]globalMsg ("^7DEBUG: current player instant Speed = " . $instantSpeed);[/SIZE]
[SIZE=2]globalMsg ("^7DEBUG: IF " . $topSpeed . " is zero : display first pass");[/SIZE]
[SIZE=2]IF ($topSpeed == 0)[/SIZE]
[SIZE=2]THEN[/SIZE]
[SIZE=2]setCurrentPlayerVar( "topSpeed",$instantSpeed );[/SIZE]
[SIZE=2]$topSpeed = GetCurrentPlayerVar("topSpeed");[/SIZE]
[SIZE=2]privMsg( langEngine( "First Pass: ^3{0} ^7{1} " , $instantSpeed,GetCurrentPlayerVar("UnitSpeed") ) );[/SIZE]
[SIZE=2]ENDIF[/SIZE]
[SIZE=2]globalMsg ("^7DEBUG: ^7IF " . $topSpeed . " not zero and (" . $instantSpeed . " > " . $topSpeed .") : display New" );[/SIZE]
[SIZE=2]IF ($topSpeed != 0 && $instantSpeed > $topSpeed)[/SIZE]
[SIZE=2]THEN[/SIZE]
[SIZE=2]$difference = $instantSpeed - $topSpeed;[/SIZE]
[SIZE=2]setCurrentPlayerVar( "topSpeed",$instantSpeed );[/SIZE]
[SIZE=2]$topSpeed = GetCurrentPlayerVar("topSpeed");[/SIZE]
[SIZE=2]privMsg( langEngine( "New top speed: ^3{0} ^7{1} ^2+{2}",$topSpeed,GetCurrentPlayerVar("UnitSpeed"),$difference));[/SIZE]
[SIZE=2]ENDIF[/SIZE]
[SIZE=2]globalMsg ("^7DEBUG: IF " . $topSpeed . " not zero and (" . $instantSpeed . " < " . $topSpeed . ") : display Speed" );[/SIZE]
[SIZE=2]IF ($topSpeed != 0 && $instantSpeed < $topSpeed)[/SIZE]
[SIZE=2]THEN[/SIZE]
[SIZE=2]$difference = $topSpeed - $instantSpeed;[/SIZE]
[SIZE=2]privMsg( langEngine("Speed: ^3{0} ^7{1} ^1-{2}",$instantSpeed,GetCurrentPlayerVar("UnitSpeed"),$difference));[/SIZE]
[SIZE=2]ENDIF[/SIZE]
[SIZE=2][SIZE=2]EndSub[/SIZE]
[/SIZE]

(Ignore the fastess speed trap thing)


Speed is displayed but it should be New top speed!

I'v tryed :

IF ()
THEN
...
ELSE IF ()
THEN
...
ENDIF

With or without the space between the ELSE and the IF, had no result.

Any ideas?

EDIT: As soon as the instant speed is higher then 100 it does this bug.

Olivier
Try using the ToNum function inside your IF statements to cast the operands to numerics. Lapper has a tendancy to assume that vars are strings rather than numbers when doing compares. i.e:


<?php 
...
IF ( 
ToNum($topSpeed) != && ToNum($instantSpeed) > ToNum($topSpeed) )
THEN
...
?>

...OR...
Do the casts when your first do the variable retrievals:

<?php 
...
$topSpeed ToNum(GetCurrentPlayerVar("topSpeed"));
$instantSpeed ToNum(GetCurrentPlayerVar("InstantSpeed"));
...
?>

Quote from Krayy :Try using the ToNum function inside your IF statements to cast the operands to numerics. Lapper has a tendancy to assume that vars are strings rather than numbers when doing compares.

Thank's a lot for this tip! It should be in LFSlapper.lpr commentary headers?

Now im making something similar and i have another problem.

I want to use GetCurrentPlayerVar("Split1") in time format like minutes:seconds.therest when comes the time to display it.
Right now my variable is something like 29410.
I tryed a splitToArray but i have no token to use.
I also tried variableName[$i] like in c but had no results.

How should i do this?


<?php 
Event OnSplit1
$userName # Player event
IF(ToNum(GetCurrentPlayerVar("sp1")) == 0)
THEN
setCurrentPlayerVar
"sp1",ToNum(GetCurrentPlayerVar("Split1")));
$tData SplitToArrayToNum(GetCurrentPlayerVar("sp1")),"?");
dumpVar($tData);
ENDIF
IF (
ToNum(GetCurrentPlayerVar("sp1")) != && ToNum(GetCurrentPlayerVar("Split1")) > ToNum(GetCurrentPlayerVar("sp1")))
THEN
$difference 
ToNum(GetCurrentPlayerVar("Split1")) - ToNum(GetCurrentPlayerVar("sp1"));
setCurrentPlayerVar"sp1",ToNum(GetCurrentPlayerVar("Split1")) );
privMsglangEngine"^7First split difference: ^2-{0}",ToNum($difference)));
ENDIF
IF (
ToNum(GetCurrentPlayerVar("sp1")) != && ToNum(GetCurrentPlayerVar("Split1")) < ToNum(GetCurrentPlayerVar("sp1")))
THEN
$difference 
ToNum(GetCurrentPlayerVar("sp1")) - ToNum(GetCurrentPlayerVar("Split1"));
privMsglangEngine"^7First split difference: ^1+{0}",ToNum($difference)));
ENDIF
?>

EDIT: I'm learning a lot doiing this!

Olivier
To get the actual times, use this: NumToMSH(GetCurrentPlayerVar( "Split1" ))
I also recommend to have a look at pitboard.lpr which can be found in the 'includes' folder, since that uses a lot of features related to times.
Quote from iOL(Qc) :EDIT: I'm learning a lot doiing this!

<?php 
Event OnSplit1
$userName # Player event
IF(ToNum(GetCurrentPlayerVar("sp1")) == 0)
THEN
setCurrentPlayerVar
"sp1",ToNum(GetCurrentPlayerVar("Split1")));
$tData SplitToArrayToNum(GetCurrentPlayerVar("sp1")),"?");
dumpVar($tData);
ENDIF
IF (
ToNum(GetCurrentPlayerVar("sp1")) != && ToNum(GetCurrentPlayerVar("Split1")) > ToNum(GetCurrentPlayerVar("sp1")))
THEN
$difference 
ToNum(GetCurrentPlayerVar("Split1")) - ToNum(GetCurrentPlayerVar("sp1"));
setCurrentPlayerVar"sp1",ToNum(GetCurrentPlayerVar("Split1")) );
privMsglangEngine"^7First split difference: ^2-{0}",ToNum($difference)));
ENDIF
IF (
ToNum(GetCurrentPlayerVar("sp1")) != && ToNum(GetCurrentPlayerVar("Split1")) < ToNum(GetCurrentPlayerVar("sp1")))
THEN
$difference 
ToNum(GetCurrentPlayerVar("sp1")) - ToNum(GetCurrentPlayerVar("Split1"));
privMsglangEngine"^7First split difference: ^1+{0}",ToNum($difference)));
ENDIF
?>

Olivier

Time to learn a bit more. As GLscript is an interpreted language, try to limit the number of system calls you do, specifically using the ToNum and GetCurrentPlayerVar functions in the above code. it is more efficient for the compiler to allocate a variable than do multiple calls, so try changing it to:


<?php 
Event OnSplit1
$userName # Player event
    
$sp1 ToNum(GetCurrentPlayerVar("sp1"));
    
$Split1 ToNum(GetCurrentPlayerVar("Split1"));
    IF(
$sp1 == 0)
    
THEN
        setCurrentPlayerVar
"sp1",$Split1);
        
$tData SplitToArray$sp1),"?");
dumpVar($tData);
ENDIF
IF (
$sp1 != && $Split1 $sp1)
THEN
$difference 
$Split1 $sp1;
setCurrentPlayerVar"sp1",$Split1);
privMsglangEngine"^7First split difference: ^2-{0}",ToNum($difference)));
ENDIF
IF (
$sp1 != && $Split1 $sp1)
THEN
$difference 
$sp1 $Split1;
privMsglangEngine"^7First split difference: ^1+{0}",ToNum($difference)));
ENDIF
?>

Reaction time
Great tips !
Quote from Yisc[NL] :To get the actual times, use this: NumToMSH()

Quote from Krayy :Time to learn a bit more. As GLscript is an
interpreted language, try to limit the number of system calls you do.

My scripting take's shape.

Now i want to process RT.

I was looking for something like:


<?php 
Event OnGreenLight
($UserName # Possible to make this as a player Event?
WHILE (ToInt(GetCurrentPlayerFunctionReturn(GasIsPressed())) != 1)
$reactionTime StartCounting();
ENDWHILE
...
?>

Is there another way to do this, should it be in the next release or am i dreaming?

Olivier
Quote from iOL(Qc) :

<?php 
Event OnGreenLight
($UserName # Possible to make this as a player Event?
WHILE (ToInt(GetCurrentPlayerFunctionReturn(GasIsPressed())) != 1)
$reactionTime StartCounting();
ENDWHILE
...
?>

Is there another way to do this, should it be in the next release or am i dreaming?

Olivier

Not in Lapper or any other InSim application I'm afraid as those are more like OutSim functions (InSim = run on the server, OutSim = run on your PC). You can see if someone is accelerating, and there is an event called OnAcceleration in the Lapper.lpr file that will get run when a user accelerates from 0 to 100km/h (configurable just above the function lines).

There is also a function OnRaceStart which runs when the race does a restart, but only runs when the grid is formed and not when the light goes green. That's a limitation of LFS, not Lapper.
Quote from iOL(Qc) :Great tips !




My scripting take's shape.

Now i want to process RT.

I was looking for something like:


<?php 
Event OnGreenLight
($UserName # Possible to make this as a player Event?
WHILE (ToInt(GetCurrentPlayerFunctionReturn(GasIsPressed())) != 1)
$reactionTime StartCounting();
ENDWHILE
...
?>

Is there another way to do this, should it be in the next release or am i dreaming?

Olivier

no but there is a way to do this... i can try and make up a little code when i have time
Hello,

not possible, the info it's not available in insim

Bye

Gai-Luron
hi there
where can i find the sub event : Myconfig() ??
thx
Quote from Bass-Driver :hi there
where can i find the sub event : Myconfig() ??
thx

MyConfig is a hard coded function inside the lapper .exe file. You can see what it does in the source code in the loop.cs file under the showConfigPlayer function
This thread is closed

Config help
(1112 posts, closed, started )
FGED GREDG RDFGDR GSFDG