The online racing simulator
Automatic layout changer
I'm working on a drift server and am in need of a way to automatically change the layout after a specified time.

This can't be that difficult; just a timer and a list of layouts..

Any takers?
The latest set_schedule and schedule modules, can change layouts as well, so you could use those scripts. But it might be a bit to heavy for the job. Making a smaller module for the task, shouldn't be too complicated.
set_schedule would probably work but wouldn't that require setting up scheduled events for every time... or is there a way to loop it?
<?php

GlobalVar $highest = 10;

SetStoredValue("layout_1", "layout name");
SetStoredValue("layout_2", "layout name");
SetStoredValue("layout_3", "layout name");
SetStoredValue("layout_4", "layout name");
SetStoredValue("layout_5", "layout name");.... etc

GlobalVar $layout_number = 1;

==some loop that runs every 6hr==
change layout to GetStoredValue("layout_".$layout_number);

$layout_number++;

IF($layout_number == $highest)
THEN
$layout_number = 1;
ENDIF
==end of some loop==

?>

basically all I need is that
I have made something quick.

Be aware. This script isnt tested and may be unstable.

This script uses the new function i have implemented a while ago in LFSLapper.

<?php 
getlistoflayouts
($Filter,$Sort,$TypeSort);
?>

This retreives all the layouts of the current loaded track. From a layoutfolder you have set.
The list with layouts must also exist in the default layoutfolder of your LFS directory.

Download the script below and change the extension of the file to .LPR and add the following line in addonsused.lpr in your 'includes' folder


<?php 
# UserToplist
include( "./AutoLayoutChanger.lpr");
?>

See the code below


<?php 
$LayoutFolder 
"";      #LFSLapper must be on the same machine as the LFS Server.
                        #Set Path to the layoutfolder of your LFSServer
                        #$LayoutFolder = ""; #Example : C:\LFS_0.6R\data\layout
                        #The layouts in your Layoutfolder must also exist in the default Layoutfolder of your LFS directory.

CatchEvent OnLapperStart()

    
GlobalVar $Timelimit$Timelimit 90;      #This is the time in minutes
    
GlobalVar $ElapsedTime$ElapsedTime 0;    #Reset Value to (re)start the timer.
    
GlobalVar $NrOfLayout$NrOfLayout 1;        #Reset Value to start from the top of the layout list.
    
    #ss mm hh dayOfWeek dd MM YYYY
    
RegisterScheduleAction"0 * * * * * *"RSA_Time ); #Execute this action each minute
    
EndCatchEvent
                        
Sub RSA_Time
() # Lapper Event
    
$ElapsedTime $ElapsedTime 1;
    
    
#IF $ElapsedTime is bigger or equal than the timelimit
    #Reset $ElapsedTime and goto Load layout sub
    
IF ($ElapsedTime >= $TimelimitTHEN
        $ElapsedTime 
0;
        
LoadLayout();
    ENDIF
EndSub

Sub LoadLayout
()
#The vars below are needed to retreive the layout from the layoutfolder
    
$Filter "";
    
$Sort "LAYOUTNAME";
    
$TypeSort "ASC";

    
#Try to retreive the layouts from the layoutfolder you have set above
    
$layoutlist getlistoflayouts($Filter,$Sort,$TypeSort);
    
    
#Get numberoflayouts from the current track
    
$MaxNumberOfLayouts $layoutlist["NumberOfLayouts"];

    
#Load the layout
    
privmsg("Loading Layout:".$layoutlist[$NrOfLayout,"LayoutName"]);
    
cmdLFS("/axload ".$layoutlist[$NrOfLayout,"LayoutName"]);
    
    
#Set numberoflayout for the next action
    
$NrOfLayout $NrOfLayout 1;
    
#IF $NrOfLayout is bigger or equal than the number of layouts in your layoutfolder
    #Reset $NrOfLayout
    
IF ($NrOfLayout >= $MaxNumberOfLayoutsTHEN
        $NrOfLayout 
1;
    ENDIF
EndSub                        
?>


Attached files
AutoLayoutChanger.txt - 2.1 KB - 251 views
Quote from Bass-Driver :I have made something quick.

Be aware. This script isnt tested and may be unstable.

This script uses the new function i have implemented a while ago in LFSLapper.

<?php 
getlistoflayouts
($Filter,$Sort,$TypeSort);
?>

This retreives all the layouts of the current loaded track. From a layoutfolder you have set.
The list with layouts must also exist in the default layoutfolder of your LFS directory.

This is perfect man thanks!

Quick question though. I run my server on a linux machine using wine/mono. How do paths work in lapper this way? Can I use a linux path or relative paths (such as ../../s2_server/data/layouts/)?

If there is no easier way to do this and it has to be absolute, I can just stick my server directory in the virtual wine C: drive.
tbh, i do not have any experience with Wine/Mono at all. So all i can say is : try it out, and tell us your experience.
I'll give it a go and do a report back here. I know a lot of hosts run Linux, and the performance is probably better on a small VPS compared to Windows Server.

Edit:

Actually I think I'll just try it with the virtual C: drive in Wine.
Is the scheduled action in cron format? If so, it appears that would cause an issue the way it's written, and should instead be * * * * *?
Nice find.
its indeed RegisterScheduleAction( "0 * * * * * *", RSA_Time );

This is fixed now.
This thread is closed

FGED GREDG RDFGDR GSFDG