PDA

View Full Version : Mainfile Preloader


ffcmike
03-20-2016, 07:05 PM
Here are an NPC and Weapon script which can be used to dynamically store and download mainfiles.

The database NPC is setup to only scan for mainfiles on first creation or when the NPC-Server is restarted.

The weapon script writes to a text file within the player's Graal folder once the first preload has completed, which will prevent future preloads while that text file remains within the Graal directory.

As this involves thousands of files and currently amounts to about 48 MB of filesize, it is strongly suggested to modify this script to an optional action (which can possibly list the total file size) as opposed to being an action carried out by every "fresh directory" login. Another possibility may be to split preloading in to different categories, particularly as the bulk of the file size is from old Classic images.

Also attached are categorised lists of the files which are currently preloaded. In the past it would have been possible to compile this in to a reliable GUPD, however the v6 client requires that the server directory of update package files matches the user's local Graal directory.

DB NPC:

function onCreated()
this.onInitialized();

function onInitialized() {

MainfilePreload = this;

if (this.cache != NULL)
return;

this.cache = new TStaticVar();
this.onScanDirectory("levels/mainfiles");
}

//Trigger event used to bypass max loop limit
function onScanDirectory(temp.dir) {
temp.files.loadfolder(temp.dir @ "/*", 0);

for (temp.file : temp.files) {
temp.ext = extractFileExt(temp.file);

if (temp.ext == ".txt")
continue;

if (temp.ext != "") {
this.cache.fileList.add(temp.file);
this.cache.totalFileSize += filesize(temp.file);
}
else
this.trigger("ScanDirectory", temp.dir @ "/" @ temp.file);

}

}

public function getFileList()
return this.cache.fileList;

public function getTotalFileSize()
return this.cache.totalFileSize;



Weapon:


function onActionServerside(temp.action) {

if (temp.action != "getFilenames")
return;

temp.files = MainfilePreload.getFileList();
player.triggerClient("gui", this.name, "preloadFiles", temp.files);
}

//#CLIENTSIDE
function onCreated() {
temp.preload = new TStaticVar();
temp.preload.loadvars("mainfile_preload.txt");

if (!temp.preload.hasPreloaded)
triggerServer("gui", this.name, "getFilenames");

}

function onActionClientside(temp.action, temp.files) {

if (temp.action != "preloadFiles")
return;

for (temp.file : temp.files)
if (!fileexists(temp.file))
fileupdate(temp.file);

temp.preload = new TStaticVar();
temp.preload.hasPreloaded = true;
temp.preload.savevars("mainfile_preload.txt", 0);
}

Alpho
08-28-2016, 05:11 AM
Very cool!

I am working on a new server project with a custom account login system. Would I potentially be able to use this to download majority of the server's assets to the client upon a successful login? Does the filetype matter? Is fileupdate the best method to download files onto a client for pre-loading?

Thanks!

ffcmike
08-28-2016, 05:25 AM
Very cool!

I am working on a new server project with a custom account login system. Would I potentially be able to use this to download majority of the server's assets to the client upon a successful login? Does the filetype matter? Is fileupdate the best method to download files onto a client for pre-loading?

Thanks!

This script was made specifically for default Graal mainfiles, but there's no reason you couldn't do something similar for a server's custom files if you wanted it to work dynamically. Usually on GtA I have pre-loaders setup within levels as the player progresses through the game, which just download the images/ganis/sounds etc for the content they are about to encounter.

fileupdate() perhaps isn't that efficient for mass downloading as it probably sends a request for every single file, but I'm not currently aware of any methods for mass file pre-loading except GUPD. The filetype does not matter so long as it is downloadable by the client and configured within folder config.