Hello,
While supporting/pre dev an Lapper cruiseserver : [SC] Cruise Server, i have saw many things the developers are dealing with.
One of them are the stringlengths. Its limited by Insim to a maximum of 128 characters.
So if you type/sent 140 characters with privmsg(); or globalmsg(); LFS will only display 128 characters.
So i came up with a script that gives the possibility to split the string in 2 seperated strings.
In this script you need to type a command to activate the function to split the string.
You may allowed to change the command to your own purposes.
Do not change any of the code in the SplitText() function.
Make sure to add the following lines into addonsused.lpr
include ("./SplitString.lpr");
And change the file extension to .LPR
SplitString.txt to SplitString.LPR
The code look like this:
Some example of some inputs and outputs.
While supporting/pre dev an Lapper cruiseserver : [SC] Cruise Server, i have saw many things the developers are dealing with.
One of them are the stringlengths. Its limited by Insim to a maximum of 128 characters.
So if you type/sent 140 characters with privmsg(); or globalmsg(); LFS will only display 128 characters.
So i came up with a script that gives the possibility to split the string in 2 seperated strings.
In this script you need to type a command to activate the function to split the string.
You may allowed to change the command to your own purposes.
Do not change any of the code in the SplitText() function.
Make sure to add the following lines into addonsused.lpr
include ("./SplitString.lpr");
And change the file extension to .LPR
SplitString.txt to SplitString.LPR
The code look like this:
<?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