#==================================================================================# #Scriptname: HealthBar.LPR #Author: Bass-Driver #Version: 1.0 #VersionDate: 25-12-2017 #Description: HealthBar, With automatic colored chars calculation #==================================================================================# 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 "!hb": #Check is Argv is a numeric value IF (IsNum($argv) == 1) THEN $Health = $argv; $HealthBar = "IIIIIIIIIIIIIIIIIIII"; #Kind of chars for the bar (count even chars) 10/20/40/50/100) $CurrentHealth = "".CalculateHealth($Health,$HealthBar);#Get Calculated string #IF health is equal or below 15% , it will blink. IF (ToNum($Health) <= 15) THEN openButton($userName,"statusbar",178,100,22,4,5,-1,80,"^0Health: ".$HealthBar." ^0(".$Health."%) %at%^0Health: ".$CurrentHealth." ^0(".$Health."%)"); ELSE openButton($userName,"statusbar",178,100,22,4,5,-1,80,"^0Health: ".$CurrentHealth." (".$Health."%)"); ENDIF ENDIF BREAK; ENDSWITCH EndCatchEvent Sub CalculateHealth($Health,$HealthBar) #Get length of the healthbar #Calcalate how many chars need be colored ((LenghtOfChars/100%) * Health) $LengthOfBar = StrLen( $HealthBar ); $GetStatus = ToNum(Round((($LengthOfBar/100)*$Health),0)); #Get length of string that need to be colored. $GetString = substr( $HealthBar,0,$GetStatus ); #And rhe rest of the string $GetOtherChars = substr( $HealthBar,$GetStatus,$LengthOfBar-$GetStatus ); #Which color need the calculate string have at a particular Health% IF (ToNum($Health) >= 50) THEN $NewHealth = "^2".$GetString; ENDIF IF (ToNum($Health) >= 20 && ToNum($Health) < 50) THEN $NewHealth = "^3".$GetString; ENDIF IF (ToNum($Health) < 20) THEN $NewHealth = "^1".$GetString; ENDIF #Calculate how many chars are colored , the rest will be black. Total chars = 20, Health = 50% = 10 colored chars, rest of the 10 chars will be black. $GetLength = StrLen( $NewHealth ); $NewHealthBar = Insert($NewHealth,$GetLength,"^0".$GetOtherChars); #Create new string when health is below 5 % IF (ToNum($Health) < 5) THEN $NewHealthBar = "^1".$HealthBar; ENDIF #Return value/string. Return($NewHealthBar.""); EndSub