• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OpenTibia Replace autowalk with walkinterval on NPC .xml files

ilveoncaffiene

New Member
Joined
Jun 12, 2008
Messages
19
Reaction score
0
The newer versions of TFS 0.2 have changed the autowalk value in the NPC .xml files to walkinterval.
I have way too many NPCs to rename all of that for - and, sensing that I wouldn't be the only one - I wrote a quick script in Java to replace autowalk with walkinterval in all .xml files in your directory.


MAKE A BACKUP BEFORE DOING ANYTHING! Only TFS uses this value at the moment, opentibia still uses 'autowalk'
(Personally, I don't know why it changed.. It means the exact same thing)
If you need the file to replace the other way around, I'm sure even a novice hex editor could find the 2 values in the .class file after extracting the .jar as a .zip file (Or simply compile the source with the values swapped haha)

Simply open up cmd prompt or create a shortcut, whatever suits you, and run it as such
THIS WILL WORK ON LINUX! Java is system independent and I used nothing that binds this script to Windows.

Command Line:
C:\whatever>java -jar Replacer.jar C:\directory to otserv\data\npc

Shortcut:
- Right click 'Replacer.jar' and click 'Create Shortcut'
- Right click the shortcut you just made and click 'Properties'
- In the 'Target:' box, after you see "C:\some directory\Replacer.jar", change it to: "C:\some directory\Replacer.jar" C:\directory to otserv\data\npc

NOTE:
'whatever' and 'some directory' denote any directory on your computer.
'directory to otserv' denotes the directory your .exe is located in

Relative paths are acceptable as a parameter, but remember they are relative to the .jar's directory

DOWNLOAD:
http://rapidshare.com/files/132515288/Replacer.jar

Source:
Java:
import java.util.*;
import java.io.*;

public class QuickReplace {
    static String ROOT_REPLACE_DIR;

    private static final void printf(String f, Object... args) {
        System.out.printf(f,args);
    }

    public static void main(String[] argv) {
        printf("Caff's quick replacer for autowalk->walkinterval\n");
        if(argv.length<1) {
            printf("Usage: Replacer.jar <REPLACE_DIR>\n");
            System.exit(0);
        } else {
            boolean first=true;
            for(String s:argv) {
                if(first) {
                    ROOT_REPLACE_DIR=s;
                    first=false;
                } else
                    ROOT_REPLACE_DIR+=" "+s;
            }
        }
        printf("Replacing files in directory: %s\n",ROOT_REPLACE_DIR);
        new QuickReplace();
    }

    public QuickReplace() {
        try {
            final File ROOT_DIR=new File(ROOT_REPLACE_DIR);
            File[] all_files=ROOT_DIR.listFiles();
            for(File f:all_files) {
                int end_period_i=f.getName().lastIndexOf(".");
                if(end_period_i==-1)
                    continue;
                String ext=f.getName().substring(end_period_i+1);
                if(!ext.equalsIgnoreCase("xml"))
                    continue;
                else {
                    String FILE_NAME=f.getName();
                    long len=f.length();
                    if(len>Integer.MAX_VALUE)
                        printf("File %s is too big...\n",FILE_NAME);
                    else {
                        printf("Reading from %s ...",FILE_NAME);
                        FileInputStream fis=new FileInputStream(f);
                        byte[] buf=new byte[(int)len];
                        fis.read(buf);
                        fis.close();
                        String contents=new String(buf);
                        printf("Replacing values...");
                        contents=contents.replaceFirst("autowalk=\"([0-9]+)\"","walkinterval=\"$1\u0030\u0030\u0030\"");
                        FileWriter fw=new FileWriter(f,false);
                        printf("Writing data...");
                        fw.write(contents,0,contents.length());
                        fw.close();
                        printf("DONE!\n");
                    }
                }
            }
            printf("Finished replacing files in %s\n",ROOT_REPLACE_DIR);
        }catch(Exception e){e.printStackTrace();System.exit(0);}
    }
}
 
Last edited by a moderator:
Minor change... It turns out that walkinterval is in milliseconds while autowalk was in seconds.

Fixed in source and in .jar lol (<3 regex :D )
 
Last edited:
You could do it easier using php. Just open file and then str_replace AUTOWALK= to WALKINTERVAL=.

Anyway, good code.

PS: Oh, yep. We have to modify values too :D. But I don't think before it was in seconds, cause I used 25 and it was like 2500. oO

Yours,
Rafael Hamdan;
 
Last edited:
Hey thanks heaps for this script. Yeh, I could have used notepad++ but when I have over 200 NPC files that makes my puter a bit laggy opening them all up and ctrl-h and replacing all.....

Yeh, so for me this was a pwnage fix in a min.

Cheers.
 
Back
Top