Thread: NPC Animation Cache Reader/Writer/Editor

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


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,163
    Thanks given
    1,458
    Thanks received
    2,333
    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 .

    [Only registered and activated users can see links. ]



    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

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     


  2. #2  

    Global's Avatar
    Join Date
    Dec 2008
    Posts
    1,665
    Thanks given
    629
    Thanks received
    283
    Rep Power
    578
    Very nice. Downloaded just incase if I needed it for later use
    [Only registered and activated users can see links. ]
    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  
    Registered Member
    Nando's Avatar
    Join Date
    Feb 2009
    Age
    20
    Posts
    3,469
    Thanks given
    2,279
    Thanks received
    971
    Rep Power
    4803
    cool nice
    Reply With Quote  
     

  5. #5  
    The Javatar


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

    Project Insanity Help & Assistance

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #6  
    Registered Member
    natsu's Avatar
    Join Date
    Apr 2007
    Age
    23
    Posts
    2,884
    Thanks given
    974
    Thanks received
    567
    Rep Power
    593
    thanks galkon i needed this



    Reply With Quote  
     

  7. #7  
    The Javatar


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,163
    Thanks given
    1,458
    Thanks received
    2,333
    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

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2008
    Age
    22
    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
    18
    Posts
    2,618
    Thanks given
    185
    Thanks received
    256
    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
    24
    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? [Only registered and activated users can see links. ]
    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)

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
  •