Quote:
Originally Posted by xAndrewx
Hey Nas <3
Pretty cool- I suppose it only helps on server load up.
A plan for the future is to delete the levels if they are not being used and re-create the level when needed and keep the putnpcs (for houses / gang houses etc)
|
Levels are not loaded into server memory by default. They are simply in the server's HDD and load when a player enters (and they unload from memory like 5-10 minutes later), same as all level NPCs inside of them. In addition, all this.savelocally putnpc2's function the same.
This script addresses only the putnpc2's that aren't this.savelocally that exist inside of levels that are now deleted. You could expand the script (simply make it recursive) to check the this.savelocally ones, but I saw no need (as they are not in the server's memory anyway). I suppose that could help with file browser opening speed, though (or you can just not give yourself rw to that part of the file browser in the first place! ie "-rw npcs/*/*").
The putnpc2's that don't save locally load up when the NPC server is loaded and are loaded into your NC when you load into the server, so they do create lag in NC loadtimes and NPC server restarting. Additionally, I suspect that a lot of the putnpc2's that exist in defunct levels could likely be the result of corrupt ex-staff who added them to do possibly malicious things (Delete levels, add gralats, whatever).
As an aside, if you wanted to get "serious" with putnpc removal, you may couple this script with another script (or slightly modify it) to detect which levels have the most NPCs, via the same methodology.
Here is a (hack-ish) quick version I made with the script I posted above:
PHP Code:
// NaS
const npcFolder = "npcs/";
const prefix = "npclocalnpc";
const ext = ".nw";
const tempFolder = "";
function onCreated() {
temp.folder.loadfolder("npcs/npclocalnpc*", 0);
echo("local npcs:" SPC folder.size());
npcInfo();
}
function npcInfo() {
temp.folder.loadFolder(npcFolder @ prefix @ "*",0);
for (temp.fileName:folder) {
temp.file = removeescapesfromfilename(fileName);
temp.tokens = file.tokenize("_");
temp.endlen = tokens[tokens.size() - 1].length() + tokens[tokens.size() - 2].length() + 3;
temp.lvl = file.substring(prefix.length() + 1, file.length() - prefix.length() - endlen) @ ext;
if (!(lvl in temp.lvls)) {
temp.lvls.add(lvl);
}
temp.(@lvl)++;
}
temp.amount = 0;
temp.biggest = "";
for (temp.lvl: lvls) {
if (temp.(@lvl) > amount) {
amount = temp.(@lvl);
biggest = lvl;
}
}
echo(format("most putnpcs in %s with %i", biggest, amount));
}
Like I said, it's a "hack-ish" fix I threw together (not going for efficiency on this one, just functionality). You run it and it simply echos which level has the most putnpc's.
When I ran it on UN (we had 4k putnpc2's left yesterday when I ran the first script), it got 1.1k hits in 1 level from an old quest. We dumped that level and ran it again and got about 800 NPCs from a spar tourney viewer (the tourney viewers weren't destroying on the serverside properly). We fixed the glitch and dumped that level. We did that for about 5 things.
Then we saw the bulk of the putnpc's left (I checked npcs/ myself for them, which was now loadable!) were of the classes: gralats, gralats_death, newhatdrop, and epdrop.
Those are items players can drop and give to other players. So I simply added an onInitialized() destroy(); clause on them, and rebooted the NPC server; let's be real, that kind of stuff shouldn't be expected to persist a server restart anyway. In the rare event that we reboot the npc server while a player was dropping a hat, we have logging for that anyway.
The remaining NPCs were from the playerhouse system, so we added this.savelocally to those NPCs. All-in-all, we only had about 60 putnpc's left after all of that. I went through them all personally (took about 10-15 min) and they were old BS classes that just forgot to destroy (or just had no script in them), so I just deleted them manually.
In total, the whole project took about 1-1.5 hours, but lowered UN's putnpc2 count from ~6k to 0. But I figure if you just want a quick-fix to remove a bunch of putnpc2's that nobody is using anymore, that script up top is a one-press solution to at least a few thousand!