VM.Infected gamemode V0.4
Add: Playerstats : JoinedGames
Add: Playerstats : Times Survived
Update: !stats command: added the two new Playerstats Variables
Update: !help : added the two new Playerstats Variables
Fix: UserData file were filled with empty line after insim reboot
Fix: Minor Button misplacement
Fix: Couldn't drive away because of the falsestarts after a racerestart
Fix: GameMode didn't reset after last player left the race/game.
Sub Paging($UserName)
$MaxNrOfResults = 40;
$BtnHgt = 61;
$BtnWdt = 70;
$Counter = 0;
$MaxResultsOnPage = 15;
#Close all buttons that contains "Page_"
#Just to prevent overlapping buttons with different button ID's (actually this shouldn't happen within this code)
CloseButtonRegex ($username, "Page_*");
$StartNrOfResult = (Getplayervar($username,"Page") * $MaxResultsOnPage) - $MaxResultsOnPage;
openPrivButton( "Page_Prev",$BtnWdt,$BtnHgt+10,15,4,5,-1,32, "^7Prev Page",PrevPage);
openPrivTextButton( "Page_Sel",$BtnWdt+15,$BtnHgt+10,10,4,5,32,"Select page 1 - 8","^7Page ".Getplayervar($UserName,"Page"),1,SelectPage);
openPrivButton( "Page_Next",$BtnWdt+25,$BtnHgt+10,15,4,5,-1,32, "^7Next Page",NextPage);
FOR( $i = 0; $i <= ToNum($MaxNrOfResults); $i = $i + 1)
#Show 15 results on screen
#Start result from number $StartNrOfResult
#It stops showing results when $counter hits the limit or reached MaxNumberofResult
IF(($i >= ToNum($StartNrOfResult))&&(ToNum($Counter) < $MaxResultsOnPage)) THEN
openPrivButton( "Page_Button_".$Counter,$BtnWdt,$BtnHgt,5,4,5,-1,16, "".$i);
#Increase the buttonheight by 4 for each button.
$BtnHgt = $BtnHgt + 4;
$Counter = $Counter + 1;
ENDIF
ENDFOR
EndSub
#User Clicked on Next Page Button
Sub NextPage($keyflags,$id)
$UserName = GetCurrentPlayerVar("UserName");
$CurrPage = Getplayervar($UserName,"Page");
#Increase pagenumber by 1. And call 'paging' sub
Setplayervar($UserName,"Page",$CurrPage + 1);
Paging($UserName);
EndSub
#User Clicked on Prev Page Button
Sub PrevPage($keyflags,$id)
$UserName = GetCurrentPlayerVar("UserName");
$CurrPage = Getplayervar($UserName,"Page");
# Reset Playervar when pagenumber is below 1
# Otherwise decrease pagenumber by 1.
# And call 'paging' sub
IF($CurrPage <= 1) THEN
Setplayervar($UserName,"Page",1);
ELSE
Setplayervar($UserName,"Page",$CurrPage - 1);
ENDIF
Paging($UserName);
EndSub
getlisttopuser();
$value = ""; #NameOfStoredValue
$flagdesc = "";DESC (descending order ) or ASC (ascending order)
$flagNear = "FALSE"; #TRUE or FALSE
$StartPos = 1;
$toplist = getlisttopuser($value,$flagdesc,$flagNear,$StartPos); #Get List from stored database
#Possible variables
#$toplist["ListCount"] = Number of records saved for requested storedvalue
#$toplist[$pos,"UserName"]
#$toplist[$pos,"NickName"]
#$toplist[$pos,"Value"]
$GetMaxRecords = 1000;
FOR($pos = 0;$pos <= ToNum($GetMaxRecords); $pos = $pos + 1)
#Example
globalmsg($pos.": ".$toplist[$pos,"NickName"] ." (".$toplist[$pos,"UserName"]."): ".$toplist[$pos,"Value"]."");
ENDFOR
$ListOfPlayers = GetListOfPlayers("U");
$ListOfPlayers = GetListOfPlayers("U");
FOREACH( $Var IN $ListOfPlayers ) #Go Through each player in the arraylist $ListOfPlayers
$UserName = $Var["value"];
IF(GetPlayerVar($UserName,"OnTrack") == 1) THEN
#Player On Track
#Open Buttons
ELSE
#Player Spectating or in pit
#Close Buttons
ENDIF
ENDFOREACH
Sub BlahBlah($something,$something);
EndSub
CASE "!http":
$user = $argv;
http("http://localhost/Test/LFSLapper_Test.php?u=".$user);
BREAK;
<?php
$allowed_list = array(
"TechEdison" => "no",
"Androphp" => "yes",
"Bass-Driver" => "yes"
);
$username = $_GET["u"];
if (array_key_exists("".$username."",$allowed_list))
{
if($allowed_list[$username] == "yes")
{
echo 'WebReturn('.$username.',"Allowed");';
}
else
{
echo 'WebReturn('.$username.',"Not Allowed");';
}
}
else
{
echo 'WebReturn('.$username.',"Not Found");';
}
?>
Example
'privmsg('$username.',"something");';
'globalmsg("something");';
'YourOwnNamedFunction("Parameter");';
Sub WebReturn($User,$Allowed)
globalmsg("Player: ".$User." = ".$Allowed);
EndSub
Output:
Player: TechEdison = Not Allowed
Player: Androphp = Allowed
Player: 0 = Allowed (i have no idea why it returns a 0 when i'm in the server, this could be old lapperbug)
$allowed = http("http://localhost/script.php?u=".$userName);
IF($allowed == 0)
THEN
cmdLFS("/kick ".$userName);
GlobalMsg("Kicked: ".$userName.". Reason: Not Alowed");
ELSE
GlobalMsg("Welcome Back: ".$userName);
ENDIF
<?php
#################################################
#Single Field
#################################################
#DiscordChannel to receive this embed.
$DiscordChannel = "";
#Set Title/Description and color of the discord embed
$Title = "LFSLapper Embed Title";
$Desc = "Embed Description";
#Prefix must contain '0x' Followed by 6 chars 0-9 and A-F
$Color = "0xFF0000"; #RED
#Field Values
## Use %nf% to create a new field. (Add %nf% to $FieldValue and $FieldInline aswell) ##
## The amount of $FieldTitle and $FieldValue and $FieldInLine must be the same. Otherwise you will receive errors.
$FieldTitle = "Field_01 Title";
$FieldValue = "Field_01 Value";
$FieldInline = "True";
#Use %nf% to add a footer image URL !! Not an local(pc) image.
$Footer = "LFSLapper Footer: ".GetLapperVar("ShortTime")." %nf% https://velocitymsports.com/home/vmlogo.png ";
#Small Image URL on the right side of the Embed box.
$ThumbnailUrl = "https://velocitymsports.com/home/vmlogo.png";
#The Entire EmbedBox will fit to the same size as the ImageUrl.
$ImageUrl = "";
#Function to send Discord Embed
SendDiscordEmbed($DiscordChannel,$Title,$Desc,$Color,$FieldTitle,$FieldValue,$FieldInline,$Footer,$ThumbnailUrl,$ImageUrl);
#################################################
#Multiple Fields
#################################################
#DiscordChannel to receive this embed.
$DiscordChannel = "";
#Set Title/Description and color of the discord embed
$Title = "LFSLapper Embed Title";
$Desc = "Embed Description";
#Prefix must contain '0x' Followed by 6 chars 0-9 and A-F
$Color = "0xFF0000"; #RED
#Field Values
## Use %nf% to create a new field. (Add %nf% to $FieldValue and $FieldInline aswell) ##
## The amount of $FieldTitle and $FieldValue and $FieldInLine must be the same. Otherwise you will receive errors.
$FieldTitle =
"Field_01 Title"
."%nf%Field_02 Title"
."%nf%Field_03 Title"
."%nf%Field_04 Title";
$FieldValue =
"*Field_01 Value*\n*Field_01 Value*"
."%nf%Field_02 Value"
."%nf%```New BlockLine_01\nNew BlockLine_02\nNew BlockLine_03\nNew BlockLine_04\nNew BlockLine_05\nNew BlockLine_06\nNew BlockLine_07```"
."%nf%**Field_04 Value**\n**Field_04 Value**\n**Field_04 Value**\n**Field_04 Value**";
$FieldInline = "True%nf%True%nf%False%nf%False";
#Use %nf% to add a footer image URL !! Not an local(pc) image.
$Footer = "LFSLapper Footer: ".GetLapperVar("ShortTime")." %nf% https://velocitymsports.com/home/vmlogo.png ";
#Small Image URL on the right side of the Embed box.
$ThumbnailUrl = "https://velocitymsports.com/home/vmlogo.png";
#The Entire EmbedBox will fit to the same size as the ImageUrl.
$ImageUrl = "";
#Function to send Discord Embed
SendDiscordEmbed($DiscordChannel,$Title,$Desc,$Color,$FieldTitle,$FieldValue,$FieldInline,$Footer,$ThumbnailUrl,$ImageUrl);
?>
#1. Create a DiscordBot @ https://discord.com/developers/applications
Here is an tutorial how to setup your bot properly
https://www.ionos.com/digitalguide/server/know-how/creating-discord-bot/
#2. Once you've added your bot to your discord server, we can now configure LFSLapper to communicate with your discordbot.
#3. Open myInc.LPR (bin\default\includes\myInc.lpr) and fill in the 3 parameters
#####DISCORD API#####
$DiscordToken = ""; # Token to connect LFSLapper with Discord , This is a token with alot of characters
Example: NTY5MjU1234567890NTMy.G12345.36as1234lT9PcdFBd-9niSnIOabcDEFGHJ
$DiscordChannelReceive = ""; # This can be blank or you can add up to 5 discordchannels ID's for receiving LFSLapper messages, seperated with a comma "," .
The Discordchannel ID's can be found when you rightclick on the channel and click on "Copy Channel ID".
$DiscordBotStatus = "Powered by LFSLapper!";
#4. Start LFSLapper
When LFSLapper is connected to your LFS Server, you should see the message : "DiscordBot Connected" in your LFSLapper console.
This message also appears in the MSS log file. 'Bin/Default/Logs/xxx.xxx.xxx.xxx-yyyyy.LOG' if you do not have access to the console.
#5. To send message from LFSLapper to your Discord Server. You use the function: sendmessagetodiscord();
You can use this function in a command,sub or event.
Here's an example:
$DiscordChannel = "123456789012345457214";
$Message = "This is a test";
sendmessagetodiscord($DiscordChannel,$Message);
#6.1. To send an message from Discord To LFSLapper, you type a message in one of the discord channels
you've set @ step 3.
Those messagew will be executed in the LapperEvent named: OnReceiveDiscordMessage()
Open LFSLapper.LPR in the default folder and look for the event you see below.
Event OnReceiveDiscordMessage($ChannelID,$ChannelName,$UNameID,$UName,$Text)
#Your code
EndEvent
#6.2. Type and place the current line between Event and EndEvent
globalmsg("^3DiscordMsg: ^3".$Text);
#6.3. Write a message in the discordchannel and press enter.
You should see the message, you've written in your discordchannel.
CASE "!jrr":
$X_Axis = getcurrentplayervar("X"); #X axis SpawnPoint
$Y_Axis = getcurrentplayervar("Y"); #Y axis SpawnPoint
$Z_Axis = getcurrentplayervar("Z"); #Z axis SpawnPoint
$Flags = 128; #Move/Reset car (128) else (0)
$Heading = 0; #Heading of the players car at Spawnpoint
$UCID = 0; #Connection's unique id (0 = host)
$PLID = getcurrentplayervar("PLID"); #Player's unique id
$JRRAction = 4;
IF(GetPlayerVar($userName,"OnTrack") == 1)
THEN
IF ( GetCurrentPlayerVar( "InstantSpeed" ) < 1 )
THEN
$Message = " ```fix\n (". GetCurrentPlayerVar("UserName").") aracını yeniledi. >> (". GetLapperVar ( "LongTime" ) .") ``` ";
$DiscordChannel = "1206604043112157214";
sendmessagetodiscord($DiscordChannel,$Message);
privMsg( GetCurrentPlayerVar("NickName") . " ^7Araç yenileme başarılı.");
joinrequest($X_Axis , $Y_Axis , $Z_Axis , $Flags ,$Heading , $UCID , $PLID ,$JRRAction); #Send Data to LFS
ELSE
privmsg("^3Command abort: Stop the car!");
ENDIF
ELSE
privmsg("^1You cannot use this command in spectatormode");
ENDIF
BREAK;
2/13/2024 7:30:00 PM -> Syntax error: in file ".\default\.\includes\.\RallySystem\Scripts\NewTimes.LPR" at line #212
ERROR on Function: 'EditFile', ERROR on Function: 'EditFile', File is empty: [0] lines detected, you cant edit any lines.
Function 'writetofile' script aborted
Sub WriteToFile()
$SaveStageCount = arrayCount($SaveStageTimesStage);
Globalmsg("^4DEBUG: ^8Start WriteToFile() With ^3".$SaveStageCount." ^8Veh/Stage Combo's");
IF($SaveStageCount > 0) THEN
FOR ( $x = 0; $x < ToNum($SaveStageCount) ; $x = $x + 1)
$SaveTimeStage = $SaveStageTimesStage[ToNum($x)];
$SaveTimeVeh = $SaveStageTimesVeh[ToNum($x)];
Globalmsg("^2DEBUG: ^8[".$x."] ^8Vehicle: ".$SaveTimeVeh." / Stage: ". $SaveTimeStage);
IF(($SaveTimeStage != "") && ($SaveTimeVeh != "")) THEN
#Globalmsg("^3DEBUG: ^8WriteToFile() Loop ".$SaveTimeStage." / ".$SaveTimeVeh." || ^3".$CountTimesOfCar[ToNum($SaveTimeStage),$SaveTimeVeh]);
$StageDir = $StageTimes_Dir . "/Stage_" . $SaveTimeStage; #RallySystem\StageData\TrackConfig\NameOfTimeTable\Stage_X
#Verify if vehiclefile for current stage exist
IF (FileExist($StageDir,$SaveTimeVeh,".txt") == 1) THEN
#Get information about the vehicle file.
$TimeInfoFromFile = ReadFile($SaveTimeVeh,$StageDir,".txt");
$MaxFileRecords = $TimeInfoFromFile["NumberOfLines"];
$ArrayCount = ToNum($CountTimesOfCar[ToNum($SaveTimeStage),$SaveTimeVeh]);
globalmsg("^3DEBUG: Records in File [Stage ".$SaveTimeStage."/".$SaveTimeVeh."]: ^3".$MaxFileRecords." ^0/ ^6".$ArrayCount);
$RecordsWritten = 0;
$Deletedlines = 0;
FOR ( $Pos = 0; $Pos < ToNum($ArrayCount); $Pos = $Pos + 1)
$GetRecordInfo = $TimeOfCar[ToNum($Pos),ToNum($SaveTimeStage),$SaveTimeVeh,"Info"]."";
#Ignore if $getRecordInfo is empty. This line wont be saved to the timefile
IF($GetRecordInfo != "") THEN
$RecordsWritten = $RecordsWritten + 1;
globalmsg("^3DEBUG: WriteToFile() Write/Array ".$RecordsWritten." <> ".$MaxFileRecords);
IF(ToNum($RecordsWritten) > ToNum($MaxFileRecords))THEN
#If current list of records is larger than the list of records from current timefile, create a new line.
EditFile($SaveTimeVeh,$StageDir,$GetRecordInfo,-1,".txt"); #NewLine
globalmsg("^3DEBUG: ^8New Record ");
ELSE
#Overwrite every record.
EditFile($SaveTimeVeh,$StageDir,$GetRecordInfo,$RecordsWritten,".txt"); #NewLine
globalmsg("^3DEBUG: ^8Record Overwritten");
ENDIF
ELSE
globalmsg("^3DEBUG: Warning >> ^8NO DATA: ".$SaveTimeVeh." / ".$SaveTimeStage." / ".$Pos);
ENDIF
ENDFOR
IF( $RecordsWritten > 0) THEN
#Delete Records that exceed the maximum records for the current vehicle/stage combo (Records can be deleted by player in !times)
IF(ToNum($RecordsWritten) < ToNum($ArrayCount)) THEN
FOR ( $Line = $ArrayCount-1; $Line >= ToNum($TotalRecordsWritten) ; $Line = $Line - 1)
EditFile($SaveTimeVeh,$StageDir,-1,$Line,".txt"); #NewLine
$Deletedlines = $Deletedlines + 1;
ENDFOR
ENDIF
ENDIF
Globalmsg("^3DEBUG: ^8Total Lines Written/Deleted [Stage ".$SaveTimeStage."/".$SaveTimeVeh."]: ^2".$RecordsWritten."^0/^1".$Deletedlines);
ELSE
Globalmsg("^3ERROR: ^8Cannot save stagetime: ^3[Stage ".$SaveTimeStage."/".$SaveTimeVeh."], ^7Contact admin!");
ENDIF
ENDIF
ENDFOR
Globalmsg("^3DEBUG: ^8Clear/Reset $SaveStageTimesStage & $SaveStageTimesVeh Array + Counter");
UnSet($SaveStageTimesStage);
UnSet($SaveStageTimesVeh);
$SaveStageTimesCounter = 0;
#LogSystem
$ConvertShortDate = Replace(GetLapperVar( "ShortDate" ),"/","-");
$NewLine = StripLFSColor("".GetLapperVar( "ShortDate" )."-".GetLapperVar( "ShortTime" ) ."|TIMES| Scheduled task to save stagetimes to file");
EditFile($ConvertShortDate,$Insim_Log_Dir,$NewLine,-1,".txt"); #NewLine
#Globalmsg("^3DEBUG: ^8WriteToFile() Finished");
ENDIF
EndSub
at LFSLapper.LFSClient.cmdlfs(unionVal val, ArrayList args) = cmdLFS() function
at LFSLapper.LFSClient.managePacket(NCN newConnection) = Event OnConnect