Allen Posted November 7, 2014 Share Posted November 7, 2014 (edited) This script will dump all local npcs in the format "npcid x y".It would benefit anyone making an OS private server(since one's in development maybe they'll come across this and use it). package com.kinztech.scripts.npcdump; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.ArrayList; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.*; import org.osbot.utility.Logger.MessageType; /** * A script to dump local NPC spawns. * @author Allen K. * */ @ScriptManifest(author = "Allen", info = "A script to dump npc spawn locations.", logo = "", name = "Npc Spawn Dump", version = 1.0) public class NpcDumpScript extends Script { /** * A cached list of the npcs, to keep from dumping multiple NPC's of the same reference. */ ArrayList<NPC> cachedNpcs = new ArrayList<NPC>(); @Override public int onLoop() throws InterruptedException { for(NPC npc : this.getNpcs().getAll()) { if(!cachedNpcs.contains(npc)) { addNpcToDump(npc); } } return 600; } /** * Add an npc to the file & cache it. * @param npc */ public void addNpcToDump(final NPC npc) { try { this.logger.log(MessageType.INFO, "Dumping Npc: " + npc.getId() + " Loc: " + npc.getPosition().getX() + "," + npc.getPosition().getY()); File file = new File("npc_spawns.txt"); if(!file.exists()) file.createNewFile(); BufferedWriter writer = new BufferedWriter(new FileWriter(file, true)); writer.newLine(); writer.write(npc.getId() + " " + npc.getPosition().getX() + " " + npc.getPosition().getY()); writer.flush(); writer.close(); cachedNpcs.add(npc); } catch (Exception e) { this.logger.error("ERROR dumping npc spawn for: " + npc.getId() + " Loc: " + npc.getPosition().getX() + "," + npc.getPosition().getY()); e.printStackTrace(); } } } JAR Download(open source): http://kinztech.com/downloads/scripts/NpcDumpScript.jar Enjoy EDIT: It will stay updated here: https://github.com/kinztechcom/OSBot/blob/master/src/com/kinztech/scripts/npcdump/NpcDumpScript.java Edited November 9, 2014 by Allen 1 Link to comment Share on other sites More sharing options...
Pandemic Posted November 7, 2014 Share Posted November 7, 2014 Cool idea, but this is absolutely terrible IO performance wise. Change the array list from npc to string, and just add npc.getId() + " " + npc.getPosition().getX() + " " + npc.getPosition().getY() to the array list in addNpcToDump. Then in onFinish (or whatever it's called), write all of those strings to a file. Opening, writing, and closing a file stream for EVERY npc is very, very slow. 4 Link to comment Share on other sites More sharing options...
Allen Posted November 7, 2014 Author Share Posted November 7, 2014 (edited) Cool idea, but this is absolutely terrible IO performance wise. Change the array list from npc to string, and just add npc.getId() + " " + npc.getPosition().getX() + " " + npc.getPosition().getY() to the array list in addNpcToDump. Then in onFinish (or whatever it's called), write all of those strings to a file. Opening, writing, and closing a file stream for EVERY npc is very, very slow. I considered doing this and having a UI button on the screen to dump/update the file. The method to write is also not called unless a new NPC appears in the scene that has not already been dumped. Regarding the string suggestion, yes it may be more efficient(although its just a list of references to the object) however, the npc's do walk. A more ideal alteration would be to save the npc index in an ArrayList<Integer> if I were not going to list NPC's. I also considered instantiating the writer upon start and writing to it when necessary(or on close/stop), and closing the writer on script finish, but I wasnt sure of how efficient that would be vs how it is now. i.e. this: https://gist.github.com/kinztechcom/3b0a2fa5cf284fe830bb edit: project is on github now so if more changes are made i don't have to keep submitting just the class: https://github.com/kinztechcom/OSBot/blob/master/src/com/kinztech/scripts/npcdump/NpcDumpScript.java Edited November 7, 2014 by Allen Link to comment Share on other sites More sharing options...
Th3 Posted November 7, 2014 Share Posted November 7, 2014 Newbs, npcs have an index as well. You can use that and not worry about adding the same one 50 times, Index only usually changes between f2p and p2p worlds or sometimes after large updates. Link to comment Share on other sites More sharing options...
Eliot Posted November 7, 2014 Share Posted November 7, 2014 Coolio. Nice work. Link to comment Share on other sites More sharing options...
Allen Posted November 7, 2014 Author Share Posted November 7, 2014 (edited) Newbs, npcs have an index as well. You can use that and not worry about adding the same one 50 times, Index only usually changes between f2p and p2p worlds or sometimes after large updates. I considered doing this and having a UI button on the screen to dump/update the file. The method to write is also not called unless a new NPC appears in the scene that has not already been dumped. Regarding the string suggestion, yes it may be more efficient(although its just a list of references to the object) however, the npc's do walk. A more ideal alteration would be to save the npc index in an ArrayList<Integer> if I were not going to list NPC's. I also considered instantiating the writer upon start and writing to it when necessary(or on close/stop), and closing the writer on script finish, but I wasnt sure of how efficient that would be vs how it is now. i.e. this: https://gist.github.com/kinztechcom/3b0a2fa5cf284fe830bb edit: project is on github now so if more changes are made i don't have to keep submitting just the class: https://github.com/kinztechcom/OSBot/blob/master/src/com/kinztech/scripts/npcdump/NpcDumpScript.java Although you're not going to see any difference in performance storing the reference to the NPC object over an Integer object with its index. In fact, it'd actually force to to add to the code because I'd have to reference to the NPC object from NPCS#getLocalNPC(index) when writing. Thanks for the suggestion though, all feedback is appreciated Edited November 7, 2014 by Allen Link to comment Share on other sites More sharing options...
Harry Posted November 8, 2014 Share Posted November 8, 2014 (edited) Learn something new everyday. Slowly learning more stuff about how RSPS's/RS in general and how they work - also as well as how you can make them better, thanks for this @Allen. :~) Edited November 8, 2014 by Adventurer Link to comment Share on other sites More sharing options...
Th3 Posted November 9, 2014 Share Posted November 9, 2014 Although you're not going to see any difference in performance storing the reference to the NPC object over an Integer object with its index. In fact, it'd actually force to to add to the code because I'd have to reference to the NPC object from NPCS#getLocalNPC(index) when writing. Thanks for the suggestion though, all feedback is appreciated I was referring to the global index of the npc, not the local index. 1 Link to comment Share on other sites More sharing options...
Czar Posted April 19, 2016 Share Posted April 19, 2016 NPC spawn dumper very useful for quest scripts, good job Link to comment Share on other sites More sharing options...