#==================================================================================# #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 */