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.
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(type, sub)
{
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() == NULL) createSubPackage(type, type);
temp.file.loadLines("levels/" @ type @ "_" @ sub @ ".gupd");
if (!checkSubPackage("package_" @ type, type, sub) || temp.file.size() == NULL) createSubPackage(type, sub);
// Loading files in folder
temp.folder = (sub == NULL ? "levels/" @ type @ "/*" : "levels/" @ type @ "/" @ sub @ "/*");
temp.data.loadFolder(temp.folder, 0);
if (sub == NULL) sub = type;
// Clearing old file entries
temp.package.loadLines("levels/" @ type @ "_" @ sub @ ".gupd");
for (temp.i = 0; temp.i <= 6; temp.i ++) 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.file: temp.data) temp.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(package, type, sub)
{
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(package, type, sub)
{
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" ? 4 : 7), "SUBPACKAGE" SPC temp.checksum @ ".gupd");
temp.data.saveLines("levels/" @ package @ ".gupd", 0);
if (package == "basepackage") createSubPackage(type, type);
echo("Added sub package \"" @ type @ "\" to \"" @ package @ "\"");
}
function createSubPackage(type, sub)
{
temp.layout = {
"GRPKG001",
"NAME" SPC sub.substring(0, 1).upper() @ sub.substring(1),
"VERSION 1.00",
"PLATFORM any",
"DESCRIPTION",
sub.substring(0, 1).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 == NULL) sub = type;
temp.layout[1] = "NAME" SPC sub.substring(0, 1).upper() @ sub.substring(1);
temp.layout[5] = sub.substring(0, 1).upper() @ sub.substring(1);
temp.layout.saveLines("levels/" @ type @ "_" @ sub @ ".gupd", 0);
if (!checkSubPackage("package_" @ type, type, sub)) addSubPackage("package_" @ type, type, sub);
echo("New sub-sub package created \"" @ type @ "_" @ sub @ "\"!");
}
}
function getNewVersion(arg)
{
temp.var = arg.tokenize()[1] + 0.01;
return arg.tokenize()[0] SPC 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.version) package.update();
for (temp.subpackage: package.packages) printPackage(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!
