Author Topic: [RESOURCE] Support_PreLoad - Updated 6/17/14  (Read 3056 times)

Use this to load a script file just as Blockland starts.

Code Here

This is still a very new script and I'm open to suggestions for improvements.

Changes:
 - Now looks for "preload.cs" in add-ons. No need to register scripts.
 - Make sure it is only run once.

This is the script created in config/main.cs:
Code: [Select]
///BEGIN PRE-LOAD SCRIPT LAUNCHER///
if(!$PreLoadScriptsRun)
{
%mask = "Add-Ons/*/preload.cs";
for(%file = findFirstFile(%mask); %file !$= ""; %file = findNextFile(%mask))
%fileList = setField(%fileList, getFieldCount(%fileList), %file);
%fileCount = getFieldCount(%fileList);
for(%fileIndex = 0; %fileIndex < %fileCount; %fileIndex ++)
{
%file = getField(%fileList, %fileIndex);
%path = filePath(%file);
%dirName = getSubStr(%path, strPos(%path, "/") + 1, strLen(%path));
if(strPos(%dirName, "/") == -1)
{
echo("\n\c4Pre-Loading Add-On:" SPC %dirName);
exec(%file);
}
}
$PreLoadScriptsRun = true;
$Pref::PreLoadScriptLauncherInstalled = true;
}
///END PRE-LOAD SCRIPT LAUNCHER///
« Last Edit: June 25, 2014, 09:26:53 AM by Greek2me »


This isn't even possible as a server sided add-on, what if other add-ons are executed before your script?

Fixed.

No add-ons are executed before the script. This is executed right after Blockland starts - meaning it's executed before all client add-ons and before all dedicated server add-ons. For integrated (non-dedicated) server add-ons, you don't need this anyway.

Aha - it isn't an add-on. However, as the code you would call addPreloadScript with is part of an add-on, this means it starts working the second time you start your game with the add-on enabled.

Aha - it isn't an add-on. However, as the code you would call addPreloadScript with is part of an add-on, this means it starts working the second time you start your game with the add-on enabled.

Right - and hopefully you would first ask your user if they want to do this.

You should just make it write to main.cs a script which executes all "add-ons/*/preLoad.cs" or something, similar to how server.cs and client.cs are executed.

You should just make it write to main.cs a script which executes all "add-ons/*/preLoad.cs" or something, similar to how server.cs and client.cs are executed.

Done! The OP has been updated.

Great!

Before I learnt about the main.cs thing, I was thinking about making an add-on that does this, but call it System_ReturnToBlockland so that it gets loaded first (or when RTB was still around, ask ephi to add this).