The online racing simulator
HealthBar
Hello,

I've created a healthbar for several purposes. One of them is for Lapper CruiseInsims.

Features:

-Choose your type of character: I ,| or dots or whatever you like:
-Colorscheme is easy to adjust,
-Length of the bar ( length of the characters you used).

How to use it:

-Download the script:
-Rename the file to HealthBar.LPR with 'notepad' or other textediting applications
-Place the file in 'include' folder (Bin\Default\Includes)
-Add the following line in 'AddonsUsed.LPR' (Bin\Default\Includes\Addonsused.LPR)
include( "./HealthBar.LPR");
-Type command !hb <0-100> Example: !hb 25


<?php 
#==================================================================================#
#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 == -THEN
      $command 
$text;
      
$argv "";
    ELSE
      
$command subStr$text,0,$idxOfFirstSpace );
      
$argv trimsubStr$text,$idxOfFirstSpace ) );
    ENDIF

    SWITCH( 
$command )
        CASE 
"!hb":
            
#Check is Argv is a numeric value
            
IF (IsNum($argv) == 1THEN
                $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) <= 15THEN
                    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) >= 50THEN
                $NewHealth 
"^2".$GetString;
            ENDIF
            IF (
ToNum($Health) >= 20 && ToNum($Health) < 50THEN
                $NewHealth 
"^3".$GetString;
            ENDIF
            IF (
ToNum($Health) < 20THEN
                $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) < 5THEN
                $NewHealthBar 
"^1".$HealthBar;
            ENDIF    
        
#Return value/string.    
        
Return($NewHealthBar."");
EndSub
?>


Attached images
0-20%.jpg
20-49%.jpg
100%.gif
100%.jpg
colorHB.jpg
DotHB.jpg
Attached files
HealthBar.txt - 2.6 KB - 239 views
How do I put it to work with all players? with their health real values?
by the way really nice addon !!!
As first, when a new player joined the server. You need to set a new playervar for that player.

Event OnConnect($userName)
SetPlayerVar($userName,"Health",100);
EndEvent

Than you have to create code, that decrease the "Health" of the player. Most cruiseservers do this with distance. Every 1000 meters = Decreasing health with 2%.

Also a loop is required to get the PlayerVars for each player.
See the example below.

https://www.lfs.net/forum/thread/91285-LFSLapper%3A-Code-Examples.

And to display it to the players, you could use the code above as a base.
thanks!

FGED GREDG RDFGDR GSFDG