Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-09-2008, 04:27 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Updage Package (.gupd) updater

Here's a nifty tool that I made that scans all files of a folder, and creates subpackages and sub-subpackages with all the files in.


First thing you want to do, is to give the (npcserver) rights to .gupd files.

PHP Code:
rw levels/ *.gupd 
(remove the space between / and *)

Also add it as a file in folder options.

PHP Code:
file    *.gupd 
Then, create a class named functions_updatepackages and join it to your Control-NPC as well as add a onRCChat function.

functions_updatepackages
PHP Code:
function updateGUPD(typesub)
{
  echo(
"Updating update packages...");
  
// Checks if subpackages exists, if not, creates them and
  // adds them to other packages.
  
temp.file.loadLines("levels/package_" type ".gupd");
  if (!
checkSubPackage("basepackage"type)) addSubPackage("basepackage"type);
  else if (
temp.file.size() == NULLcreateSubPackage(typetype);
  
temp.file.loadLines("levels/" type "_" sub ".gupd");
  if (!
checkSubPackage("package_" typetypesub) || temp.file.size() == NULLcreateSubPackage(typesub);

  
// Loading files in folder
  
temp.folder = (sub == NULL "levels/" type "/*" "levels/" type "/" sub "/*");
  
temp.data.loadFolder(temp.folder0);
  if (
sub == NULLsub type;
  
  
// Clearing old file entries
  
temp.package.loadLines("levels/" type "_" sub ".gupd");
  for (
temp.0temp.<= 6temp.++) temp.newpackage.add(temp.package[temp.i]);
  
temp.newpackage.saveLines("levels/" type "_" sub ".gupd"0);
  
  
// Saving file list
  
temp.package.loadLines("levels/" type "_" sub ".gupd");
  
temp.package[2] = getNewVersion(temp.package[2]);
  for (
temp.filetemp.datatemp.package.add("FILE" SPC (sub == NULL "levels/" type "/" "levels/" type "/" sub "/") @ temp.file);
  
temp.package.saveLines("levels/" type "_" sub ".gupd"0);

  echo(
"Done!");
  
sendToRC("/refreshfilelist");
}

function 
checkSubPackage(packagetypesub)
{
  if (
package == "basepackage"temp.checksum "package_" type;
  else if (
package.starts("package_")) temp.checksum type "_" sub;

  
temp.data.loadLines("levels/" package ".gupd");
  for (
temp.var: temp.data) {
    if (
temp.var == "SUBPACKAGE" SPC temp.checksum ".gupd") return true;
  }
}

function 
addSubPackage(packagetypesub)
{
  if (
package == "basepackage"temp.checksum "package_" type;
  else if (
package.starts("package_")) temp.checksum type "_" sub;

  
temp.data.loadLines("levels/" package ".gupd");
  
temp.data[2] = getNewVersion(temp.data[2]);
  
temp.data.insert((package == "basepackage" 7), "SUBPACKAGE" SPC temp.checksum ".gupd");
  
temp.data.saveLines("levels/" package ".gupd"0);
  
  if (
package == "basepackage"createSubPackage(typetype);
  echo(
"Added sub package \"" type "\" to \"" package "\"");
}

function 
createSubPackage(typesub)
{
  
temp.layout = {
    
"GRPKG001",
    
"NAME" SPC sub.substring(01).upper() @ sub.substring(1),
    
"VERSION 1.00",
    
"PLATFORM any",
    
"DESCRIPTION",
    
sub.substring(01).upper() @ sub.substring(1),
    
"DESCRIPTIONEND"
  
};
  if (
type == sub) {
    
temp.layout.add("USECHECKSUM false");
    
temp.layout.add("PROTECTOVERWRITE false");
    
temp.layout.add("FLAG popupforoptionalpackages=false");
    
temp.layout.saveLines("levels/package_" type ".gupd"0);
    
    echo(
"New sub package created \"package_" type "\"!");
  } else {
    if (
sub == NULLsub type;
    
temp.layout[1] = "NAME" SPC sub.substring(01).upper() @ sub.substring(1);
    
temp.layout[5] = sub.substring(01).upper() @ sub.substring(1);
    
temp.layout.saveLines("levels/" type "_" sub ".gupd"0);
    if (!
checkSubPackage("package_" typetypesub)) addSubPackage("package_" typetypesub);
    
    echo(
"New sub-sub package created \"" type "_" sub "\"!");
  }
}

function 
getNewVersion(arg)
{
  
temp.var = arg.tokenize()[1] + 0.01;
  return 
arg.tokenize()[0SPC temp.var;

Control-NPC
PHP Code:
function onCreated()
{
  
join("functions_updatepackages");
}

function 
onRCChat()
{
  if (
params[0] == "updategupd"updateGUPD(params[1], params[2]);

Then, upload this as a file named basepackage.gupd into your servers levels/ folder:

PHP Code:
GRPKG001
NAME Base Package
VERSION 1.00
PLATFORM any
USECHECKSUM false
PROTECTOVERWRITE false
FLAG popupforoptionalpackages
=false 

To use the tool, I will demonstrate an example. Say that I have 18 images in my levels/images/ folder, then I would say on RC:

/npcupdatepackages images

If I want to update a subfolder such as levels/images/gui/ instead, I'd do:

/npcupdatepackages images gui

Note that only one subfolder is supported at the moment. I haven't tried and use it on a sub-subfolder, but I doubt it would work. Whenever you update a package, it's version gets increased by 0.01, making it download automatically for players that logon (if you use the script provided below).


If you want the packages to be forced upon the client instead of optional, a script such as this could be added into a Weapon NPC:

PHP Code:
//#CLIENTSIDE
function onCreated() printPackage(getBasePackage());

function 
printPackage(package) {
  if (
package.localversion package.versionpackage.update();

  for (
temp.subpackagepackage.packagesprintPackage(temp.subpackage);


As always, please, use the forums reputation system. If you like this script, hey why not give me good rep? If not, pleaaaase give me bad rep. Crits and suggestions welcomed too, of course!
__________________
Follow my work on social media post-Graal:Updated august 2025.

Last edited by xXziroXx; 04-09-2008 at 05:29 PM..
Reply With Quote
  #2  
Old 04-09-2008, 05:23 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Nice
__________________
Reply With Quote
  #3  
Old 04-09-2008, 05:28 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
If you fail to understand it (I'm sure one or two of you won't), this tool is basically to update all your downloadable files and make them download for the client when he logs on.

If you upload new heads, for example, and then use this tool to update heads package - they will be downloaded for clients the next time they logon.

I find it very handy for the player to download everything once, instead of each time a new image/sound/gani is ecountered in-game and sorta "blips" out from nowhere if you have a slower connection.

This of course depend on that you use the tool to update the packages whenever you upload something, but I reccon it will become a habit.
__________________
Follow my work on social media post-Graal:Updated august 2025.
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 12:01 PM.


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