Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-20-2016, 07:05 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Mainfile Preloader

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:
PHP Code:
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:

PHP Code:
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.actiontemp.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);

Attached Files
File Type: txt mainfiles_bodies.txt (232 Bytes, 150 views)
File Type: txt mainfiles_fonts.txt (566 Bytes, 148 views)
File Type: txt mainfiles_ganis.txt (843 Bytes, 137 views)
File Type: txt mainfiles_gifs.txt (68.9 KB, 763 views)
File Type: txt mainfiles_heads.txt (12.6 KB, 285 views)
File Type: txt mainfiles_heads_info.txt (14.9 KB, 343 views)
File Type: txt mainfiles_music.txt (530 Bytes, 265 views)
File Type: txt mainfiles_shields.txt (31.7 KB, 274 views)
File Type: txt mainfiles_swords.txt (18.8 KB, 143 views)
File Type: txt mainfiles_wavs.txt (789 Bytes, 150 views)
Reply With Quote
  #2  
Old 08-28-2016, 05:11 AM
Alpho Alpho is offline
Registered User
Alpho's Avatar
Join Date: Dec 2011
Location: California, USA
Posts: 80
Alpho will become famous soon enough
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!
Reply With Quote
  #3  
Old 08-28-2016, 05:25 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Alpho View Post
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.