The online racing simulator
LFSLapper: Code Examples
Hello,

After getting many scriptrequests on PM and ingame. i think creating this thread is a nice idea for new Lapperusers.
In This thread you will find some examplecode that might be usefull for your lapper project.

You can request more code samples in this subforum: https://www.lfs.net/forum/455-General-Support

List of code samples:
This is a code sample how to create a loop within a Sub routine.
With displaying your current speed.



<?php 
###################################
#Event triggered when lapper start#
###################################
Event OnLapperStart()
    
#Create Global variables
        
Globalvar $Loop_On$Loop_On 0;
EndEvent

#################
#Command actions#
#################
Event OnMSO$userName$text # Player event

    
$idxOfFirtsSpace indexOf$text" ");

    IF( 
$idxOfFirtsSpace == -THEN
      $command 
$text;
      
$argv "";
    ELSE
      
$command subStr$text,0,$idxOfFirtsSpace );
      
$argv trimsubStr$text,$idxOfFirtsSpace ) );
    ENDIF
    
    SWITCH( 
$command )
        
        
#Stop loop & close button for all players
        
CASE "!loopoff":
            
$Loop_On 0;
            
            
#Get list of players sorted by Username
                
$Racers GetListOfPlayers("U");
            
            
#FOREACH Loop
                
FOREACH( $Var IN $Racers )
                    
closeButton$Var["value"], "speed");
                ENDFOREACH
        BREAK;
        
        
#Start loop
        
CASE "!loopon":
            
$Loop_On 1;
            
globalmsg("execute sub Set_Loop()");
            
Set_Loop(); #Goto Set_Loop Sub-routine
        
BREAK;

    ENDSWITCH
EndEvent

Sub Set_Loop
()
    IF (
$Loop_On == 1THEN
        
#Get list of players sorted by Username    
        
$Racers GetListOfPlayers("U");                  
        FOREACH( 
$Var IN $Racers #For each player in the server
        #$Var["value"] = Username
            
openButton$Var["value"], "speed",175,124,25,5,5,2,96,"^7" GetPlayerVar$Var["value"], "InstantSpeed") . " " GetPlayerVar$Var["value"], "UnitSpeed")."^8 (".GetPlayerVar$Var["value"], "Car").")");
            
DelayedCommand1Set_Loop); #1 second delay
        
ENDFOREACH
    ENDIF
EndSub
?>


This thread is closed

FGED GREDG RDFGDR GSFDG