Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-13-2009, 01:16 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Mass text replacer in files

This is a tool I made to replace filenames in levels on a large scale, considering half of Maloria's levels were filled with (what I considered) badly named files.
  • Uses
    • Replace filenames
    • Replace links
    • etc...

For example, I wanted to replace all occurrences of the text "malinn_sign.gif" from all levels with the text "mal_malinn-sign.gif":

PHP Code:
replaceTxt("malinn-sign.gif""mal_malinn-sign.gif"); 
Starting scan on 1903 files...
Replaced text 1 times in levels/levels/overworld/mal-g06.nw!
Done! Replaced text a total of 1 times!

  • In order for the script to work in all instances, I had to make a check so it won't replace the sent text if it's found with "mal_" in front of it. This is to avoid a never ending while loop that would break the script and cause major server lag. I suggest changing temp.header to suit your needs.
  • It will only alter the first occurrence of the file found, so if you have duplicate names, it won't touch more then one of them.

For this to work, you need to give (npcserver) rw to the submitted folder, as well as it's subfolders.

PHP Code:
function replaceTxt(prepast)
{
  
temp.header "mal_"// Anti never ending while (...) loop
  
temp.allowedExt = { ".nw" }; // Will skip all files but these
  
temp.folderPath "levels/levels/"// Base folder
  
temp.checkSubs true// Scan through subfolders too?

  
temp.folder.loadFolder(temp.folderPath "*"temp.checkSubs);
  echo(
"Starting scan on" SPC temp.folder.size() SPC "files...");
  
  
temp.var2 NULL;
  for (
temp.filetemp.folder) {
    if (!(
extractfileext(temp.filein temp.allowedExt)) continue;
    
temp.file findfiles(extractfilename(temp.file), true)[0];
    
    
temp.lines "";
    
temp.lines.loadString(temp.file);
    
    
temp.var = NULL;
    while (
temp.lines.pos(pre) > -1) {
      
temp.pos temp.lines.pos(pre);
      if (
temp.lines.substring(temp.pos temp.header.length(), temp.header.length()) == temp.header) break;
      
      
temp.lines temp.lines.substring(0temp.pos) @ past temp.lines.substring(temp.pos pre.length());
      
temp.var ++;
      
temp.var2 ++;
    }
    
    if (
temp.var != NULL) {
      echo(
"Replaced text" SPC temp.var SPC "times in" SPC temp.file "!");
      
temp.lines.savestring(temp.filefalse);
    }
  }
  echo(
"Done! Replaced text a total of" SPC temp.var2 SPC "times!");


__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto

Last edited by xXziroXx; 02-13-2009 at 06:11 PM..
Reply With Quote
 


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 04:30 PM.


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