Thread: NPC Animation Cache Reader/Writer/Editor

Page 1 of 7 123 ... LastLast
Results 1 to 10 of 67
  1. #1 NPC Animation Cache Reader/Writer/Editor 
    The Javatar

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,128
    Thanks given
    1,417
    Thanks received
    2,289
    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.
    "I would rather have a mind opened by wonder than one closed by belief." - Gerry Spence

    Project Insanity Help & Assistance

    www.PIhelpline.org
    www.insanityassist.org
    Reply With Quote  
     


  2. #2  

    Global's Avatar
    Join Date
    Dec 2008
    Posts
    1,593
    Thanks given
    597
    Thanks received
    263
    Rep Power
    577
    Very nice. Downloaded just incase if I needed it for later use
    Reply With Quote  
     

  3. #3  
    Registered Member
    Nikita's Avatar
    Join Date
    Aug 2008
    Age
    19
    Posts
    805
    Thanks given
    163
    Thanks received
    85
    Rep Power
    86
    Very nice, willing to use this thanks!
    Life for today, party tonight.
    Reply With Quote  
     

  4. #4  
    Donator


    Join Date
    Feb 2009
    Posts
    3,444
    Thanks given
    2,255
    Thanks received
    916
    Rep Power
    4503
    cool nice
    Reply With Quote  
     

  5. #5  
    The Javatar

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,128
    Thanks given
    1,417
    Thanks received
    2,289
    Rep Power
    5000
    Thanks .
    "I would rather have a mind opened by wonder than one closed by belief." - Gerry Spence

    Project Insanity Help & Assistance

    www.PIhelpline.org
    www.insanityassist.org
    Reply With Quote  
     

  6. #6  
    Registered Member
    natsu's Avatar
    Join Date
    Apr 2007
    Age
    22
    Posts
    2,746
    Thanks given
    933
    Thanks received
    513
    Rep Power
    497
    thanks galkon i needed this





    Reply With Quote  
     

  7. #7  
    The Javatar

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,128
    Thanks given
    1,417
    Thanks received
    2,289
    Rep Power
    5000
    No problem.
    "I would rather have a mind opened by wonder than one closed by belief." - Gerry Spence

    Project Insanity Help & Assistance

    www.PIhelpline.org
    www.insanityassist.org
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2008
    Age
    21
    Posts
    2,571
    Thanks given
    642
    Thanks received
    511
    Rep Power
    0
    this is epic
    Reply With Quote  
     

  9. Thankful user:


  10. #9  
    #1 footwear

    Shoes's Avatar
    Join Date
    Aug 2009
    Age
    17
    Posts
    2,618
    Thanks given
    185
    Thanks received
    257
    Rep Power
    562
    Nice job on this, hopefully it will inspire some good habits.


    Spoiler for different picture now:
    Reply With Quote  
     

  11. #10  
    Registered Member
    Join Date
    May 2011
    Age
    23
    Posts
    388
    Thanks given
    143
    Thanks received
    59
    Rep Power
    0
    Cool beans, stored in case I need it sometime
    R-S Admin Response  Albert Einstein
    If you can't explain it simply, you don't understand it well enough.


    Gay? Proud? Join the club!
    Reply With Quote  
     

Page 1 of 7 123 ... LastLast

Thread Information
Users Browsing this Thread

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

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
  •