<?php
#==================================================================================#
#Scriptname: SplitString.LPR
#Author: Bass-Driver
#Version: 1.0
#VersionDate: 09-12-2017
#Description: Split a string with a max amount of characters in 2 strings.
# Choose between return a Global or a Private Message.
# Split a string by the choosen delimiter.
#==================================================================================#
CatchEvent OnLapperStart()
GlobalVar $MaxLen; $MaxLen = 120; #Max length of first string.
GlobalVar $StartIndex; $StartIndex = 0; #StartIndex to read the firststring or total text
GlobalVar $ReadMaxCharsForDelimiter; $ReadMaxCharsForDelimiter = 5; #How many chars to read back from the first string. (IF delimiterchar is set)
EndCatchEvent
CatchEvent OnMSO( $userName, $text ) # Player event
$text = Tolower( $text );
$idxOfFirstSpace = indexOf( $text, " ");
IF( $idxOfFirstSpace == -1 ) THEN
$command = $text;
$argv = "";
ELSE
$command = subStr( $text,0,$idxOfFirstSpace );
$argv = trim( subStr( $text,$idxOfFirstSpace ) );
ENDIF
SWITCH( $command )
CASE "!spst":
CASE "!splitstring":
$Privmsg = 1; #Set return message in a privatemessage = 1 or a globalmsg = 0;
$Player = $userName; #Set username if you have set a private message
$Text = $argv; #Text
$Delimiter = ","; #Set a char that will split the string for more precision.
#Keep empty to split the text after a maximum of chars.
#Call Sub
SplitText($Privmsg,$Player,$Text,$Delimiter);
BREAK;
ENDSWITCH
EndCatchEvent
Sub SplitText($privmsg,$userName,$Text,$Delimiter)
#SplitText variables
$LoT = StrLen($Text); #Get Length of total text
#When Textlength is higher than Maximumlength
IF ($LoT > $MaxLen) THEN
$FirstString = substr( $Text, $StartIndex, $MaxLen);
$SecondString = substr( $Text,$MaxLen,$LoT-$MaxLen );
#Find Delimiters variables
IF (($Delimiter != "")&&(contains($FirstString,$Delimiter) == 1)) THEN
#From where to start read string to find delimiter
$IndexOfDelimiterCheck = $MaxLen - $ReadMaxCharsForDelimiter;
#Get String between MaxLength of first string and StartFind delimiter
$StringDelimiterCheck = substr( $FirstString, $IndexOfDelimiterCheck, $ReadMaxCharsForDelimiter);
#Get Index of Delimiter
$IndexOfDelimiter = indexOf( $StringDelimiterCheck, $Delimiter);
#Delimiter is found
IF ($IndexOfDelimiter != -1) THEN
#Calculate the startindex of second string
$StartIndexSecondString = ($MaxLen - $ReadMaxCharsForDelimiter) + ($IndexOfDelimiter+1);
#Calculate the length of the second string
$LenghtOfSecondString = $LoT-$StartIndexSecondString;
#Get First string and Second string
$SecondString = substr( $Text, $StartIndexSecondString, $LenghtOfSecondString );
$FirstString = substr( $Text, $StartIndex, $StartIndexSecondString-1); #$StartIndexSecondString-1 = Remove Delimiter
ENDIF
ENDIF
#Return message is a privatemessage or a globalmessage
IF ($privmsg == 1) THEN
privmsg( $userName,"" . $FirstString );
privmsg( $userName,"" . $SecondString );
ELSE
globalmsg("" . $FirstString );
globalmsg("" . $SecondString );
ENDIF
#Text doesnt exceed textlength limit
ELSE
#Return message is a privatemessage or a globalmessage
IF ($privmsg == 1) THEN
privmsg( $userName, "" . $Text );
ELSE
globalmsg("" . $Text);
ENDIF
ENDIF
EndSub
?>
#==================================================
#EXAMPLES
#==================================================
Settings: (max length is 10)
$Privmsg = 1;
$Player = $userName;
$Text = $argv;
$Delimiter = "";
Input:
!spst hellohello
Output:
hellohello
Input:
!spst hellohelloblah
Output:
hellohello
blah
#==================================================
$Privmsg = 1;
$Player = $userName;
$Text = $argv;
$Delimiter = ",";
Input:
!spst hellohello
Output:
hellohello
Input:
!spst hello,helloblah
Output:
hello
helloblah
Input:
!spst h,ellohelloblah
Output:
hellohello
blah
<?php
public void TestFunction(GLScript.unionVal val, ArrayList args)
{
infoPlayer currInfoPlayer = newCfg.getCurrInfoPlayer();
string ident = val.nameFunction;
string text = "^J☆";
SendMsgToConnection(currInfoPlayer.UCID, text);
//SendMsg(args[0].ToString());
}
void SendMsgToConnection(int UCID, string msg)
{
if (msg.Length > 0)
{
if (UCID != -1)
{
byte[] outMsg = myEncoder.MTC(UCID, 0, msg);
insimConnection.Send(outMsg, outMsg.Length);
}
}
}
?>

<?php
#Normal plain text from the sourcecode
SendMsgToConnection(currInfoPlayer.UCID, "Blah Blah");
#Get Player info that is saved.
SendMsgToConnection(currInfoPlayer.UCID, currInfoPlayer.nickName);
void SendMsgToConnection(int UCID, string msg)
{
if (msg.Length > 0)
{
if (UCID != -1)
{
byte[] outMsg = myEncoder.MTC(UCID, 0, msg);
insimConnection.Send(outMsg, outMsg.Length);
}
}
}
?>
//0x8199(HEX) 0x2606(DEC) #WHITE STAR


privmsg(GetPlayerVar($userName,"NickName"));
<?php
public byte[] MTC(int UCID, int PLID, string msg)
{
int msgLen = msg.Length > 127 ? 127 : msg.Length;
byte[] packet = new byte[136];
packet[0] = 136;
packet[1] = (byte)TypePack.ISP_MTC;
packet[2] = 0;
packet[3] = 0;
packet[4] = (byte)UCID;
packet[5] = (byte)PLID;
packet[6] = 0;
packet[7] = 0;
InSim.CodePage.GetBytes(msg, 0, System.Math.Min(127, msg.Length), packet, 8);
return packet;
}
?>
//Get last char of shorttrackname
string GetShortNameTrack = track.Substring(cp.Length - 1, 1);
//Read last char
if ((GetShortNameTrack == "X") || (GetShortNameTrack == "R") || (GetShortNameTrack == "Y"))
GetTrack = track.Substring(0, cp.Length - 1);
else
GetTrack = track.ToUpper();
$Number = 1;
$Racers = GetListOfPlayers("U");
FOREACH( $Var IN $Racers ) #For each player in the server
privmsg("^3[".$Number."] ^7".$Var["value"]); #Current Number + UserName of Player
$Number = $Number + 1;
ENDFOREACH
New event: OnNewJoinRequest # Player event (Thanks to LakynVonLegendaus)
#######################################
#Player sends a join request (Shift+J)#
#######################################
NOTE:
#To enable OnNewJoinRequest event, $ReceiveJoinRequest has to be set to 1.
#If enabled, LFS waits (cca 1 second) for a response from the Lapper on each join request.
#To respond to a join request - use joinrequest() function.
#The Player's unique ID (PLID Must be 0 to use the join request system)
#If no response is sent, LFS spawns the car normally (with a delay [because LFS waits for the join request response]).
#For more info see ..\LFS\docs\InSim.txt
$ReceiveJoinRequest = -1; #Enable (1) or disable (-1) for Receive JoinRequest.
Event OnNewJoinRequest( $userName ) # Player event
/*
$Flags = 0; #Move car (128) else (0)
$X_Axis = 0; #X axis SpawnPoint
$Y_Axis = 0; #Y axis SpawnPoint
$Z_Axis = 0; #Z axis SpawnPoint
$Heading = 0; #Heading of the players car at Spawnpoint
$UCID = GetCurrentPlayerVar("UCID"); #Connection unique ID
$PLID = 0; #GetCurrentPlayerVar("PLID"); #Player's unique ID
###$PLID MUST BE 0 TO USE JOIN REQUEST###
#$JRRAction = 0; # Reject join request.
$JRRAction = 1; # Allow join request.
joinrequest($X_Axis ,$Y_Axis ,$Z_Axis ,$Flags ,$Heading ,$UCID ,$PLID ,$JRRAction); #Send Data to LFS
*/
EndEvent
#New Lappervar:
-lapperversion //Returns the current version of LFSLapper.
(could be used to protect your script against older lapperversions).