Thread: NPC Animation Cache Reader/Writer/Editor

Page 1 of 8 123 ... LastLast
Results 1 to 10 of 75
  1. #1 NPC Animation Cache Reader/Writer/Editor 
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Latest Update: May 22, 2011 - Added multiple attack animations support.

    Most servers use switch statements that become really large and unnecessary to find an NPCs attack, block, and death animation. I have now written a cache reader/writer/editor to store and change all of this data. This editor comes with a .dat file that contains an NPC list up to 602 NPCs. Not all animations have been added for each NPC!

    This tool allows you to edit the attack, block, and death animations of an NPC. If you want to add multiple attack, simply separate each ID with a comma(space or no space, doesn't matter). When you're done editing, simply hit "Build Cache". By default, NPCs will have human animation IDs. This editor shows each NPCs standAnimation and walkAnimation ID, so you can find the other animation IDs based on those. Stand and walk animations are uneditable so you don't accidentally screw up .

    Download the NPC Animation Editor!



    Here is the reader. You have to import your own Stream class, etcetera Also, you must replace "REPLACE PATH HERE" with your chosen location. But, this will read it and such:
    Code:
    package server.model.npcs;
    
    import java.io.RandomAccessFile;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    
    import galkon.server.util.Stream;
    import galkon.server.util.Misc;
    
    public class NPCAnimation {
    
    	public static String cacheLocation = "REPLACE PATH HERE";
    
    	public static void readCache() {
    		Stream stream = new Stream(readFile(cacheLocation));
    		totalNPCs = stream.readShort();
    		if(cache == null)
    			cache = new NPCAnimation[totalNPCs];
    		for(int j = 0; j < totalNPCs; j++) {
    			if(cache[j] == null)
    				cache[j] = new NPCAnimation();
    			cache[j].readValues(stream);
    		}
    	}
    
    	public static byte[] readFile(String name) {
    		try {
    			RandomAccessFile raf = new RandomAccessFile(name, "r");
    			ByteBuffer buf = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, raf.length());
    			try {
    				if (buf.hasArray()) {
    					return buf.array();
    				} else {
    					byte[] array = new byte[buf.remaining()];
    					buf.get(array);
    					return array;
    				}
    			} finally {
    				raf.close();
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return null;
    	}
    
    	private void readValues(Stream stream) {
    		do {
    			int var = stream.readUByte();
    			if(var == 0)
    				return;
    			if(var == 1) {
    				name = stream.readString();
    			} else if(var == 2) {
    				standAnimation = stream.readInt();
    			} else if(var == 3) {
    				walkAnimation = stream.readInt();
    			} else if(var == 4) {
    				attackAnimations = stream.readString();
    				if (attackAnimations == null) {
    					attackAnimations = Integer.toString(HUMAN_ATTACK);
    				}
    			} else if(var == 5) {
    				blockAnimation = stream.readInt();
    			} else if(var == 6) {
    				deathAnimation = stream.readInt();
    			} else {
    			}
    		} while(true);
    	}
    
    	public static int getAttackAnimation(int npcID) {
    		String[] animationString = cache[npcID].attackAnimations.split(",");
    		int[] animationIndex = new int[animationString.length];
    		for (int index = 0; index < animationString.length; index++) {
    			animationIndex[index] = Integer.parseInt(animationString[index]);
    		}
    		return animationString.length > 1 ? animationIndex[Misc.random(animationIndex.length) - 1] : animationIndex[0];
    	}
    
    	public void setDefaults() {
    		name = "null";
    		standAnimation = HUMAN_STAND;
    		walkAnimation = 808;
    		attackAnimation = HUMAN_ATTACK;
    		blockAnimation = HUMAN_BLOCK;
    		deathAnimation = HUMAN_DEATH;
    	}
    
    	public NPCAnimation() {
    	}
    
    	public static NPCAnimation cache[];
    	public static int npcs;
    	public static int totalNPCs;
    	public String name;
    	public int standAnimation;
    	public int walkAnimation;
    	public String attackAnimations;
    	public int attackAnimation;
    	public int blockAnimation;
    	public int deathAnimation;
    	public final static int HUMAN_STAND = 808;
    	public final static int HUMAN_ATTACK = 806;
    	public final static int HUMAN_BLOCK = 404;
    	public final static int HUMAN_DEATH = 2304;
    
    }
    Also;
    Code:
    readShort() = readUnsignedWord()
    readUByte() = readUnsignedByte()
    Implementation and usage
    You can read the cache on startup by simply calling 'NPCAnimation.readCache();" on startup (most likely in Server.java). Then you can use things like:
    Code:
    int attackAnimation = NPCAnimation.getAttackAnimation(NPCHandler.npcs[i].id);
    int blockAnimation = NPCAnimation.cache[NPCHandler.npcs[i].id].blockAnimation;
    int deathAnimation = NPCAnimation.cache[NPCHandler.npcs[i].id].deathAnimation;
    or whatever it is in your server.

    Multiple animation support has been added and it automatically uses a random animation when you use "NPCAnimation.getAttackAnimation(NPCID);".
    Last edited by Galkon; 06-17-2011 at 01:06 PM.
    Attached image
    Reply With Quote  
     


  2. #2  
    🍥🍥🍥


    Join Date
    Dec 2008
    Posts
    1,702
    Thanks given
    664
    Thanks received
    293
    Rep Power
    621
    Very nice. Downloaded just incase if I needed it for later use
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    Nikita's Avatar
    Join Date
    Aug 2008
    Age
    29
    Posts
    822
    Thanks given
    180
    Thanks received
    89
    Rep Power
    86
    Very nice, willing to use this thanks!

    RoonScape
    Reply With Quote  
     

  4. #4  
    Registered Member
    Nando's Avatar
    Join Date
    Feb 2009
    Age
    29
    Posts
    3,517
    Thanks given
    2,439
    Thanks received
    1,108
    Rep Power
    5000
    cool nice


    Reply With Quote  
     

  5. #5  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Thanks .
    Attached image
    Reply With Quote  
     

  6. #6  
    Registered Member
    natsu's Avatar
    Join Date
    Apr 2007
    Age
    32
    Posts
    3,435
    Thanks given
    1,084
    Thanks received
    676
    Rep Power
    1096
    thanks galkon i needed this
    Reply With Quote  
     

  7. #7  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    No problem.
    Attached image
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Mar 2008
    Posts
    2,591
    Thanks given
    71
    Thanks received
    7
    Rep Power
    1741
    this is epic
    Reply With Quote  
     

  9. Thankful user:


  10. #9  
    #1 footwear

    Shoes's Avatar
    Join Date
    Aug 2009
    Age
    27
    Posts
    2,612
    Thanks given
    185
    Thanks received
    255
    Rep Power
    579
    Nice job on this, hopefully it will inspire some good habits.


    Spoiler for different picture now:
    Reply With Quote  
     

  11. #10  
    Registered Member Nicholas's Avatar
    Join Date
    May 2011
    Posts
    416
    Thanks given
    160
    Thanks received
    65
    Rep Power
    37
    Cool beans, stored in case I need it sometime
    Reply With Quote  
     

Page 1 of 8 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Dragonkk Cache Editor/Reader Lib
    By dragonkk in forum Downloads
    Replies: 56
    Last Post: 07-11-2011, 08:00 PM
  2. New Engine Cache Reader
    By Sean in forum Downloads
    Replies: 23
    Last Post: 08-21-2010, 09:11 PM
  3. Item cache writer
    By Koinzell in forum Requests
    Replies: 0
    Last Post: 08-15-2010, 09:05 PM
  4. Replies: 94
    Last Post: 05-21-2010, 09:16 PM
  5. Replies: 10
    Last Post: 05-16-2010, 08:45 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •