Thread: NPC Animation Cache Reader/Writer/Editor

Page 1 of 7 123 ... LastLast
Results 1 to 10 of 64
  1. #1 NPC Animation Cache Reader/Writer/Editor 
    dont fukin ask me for client services

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    12
    Posts
    6,938
    Thanks
    1,275
    Thanked 2,040 Times in 716 Posts
    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.

    Reply With Quote  
     


  2. #2  
    Registered Member

    Join Date
    Aug 2009
    Posts
    1,443
    Thanks
    510
    Thanked 207 Times in 127 Posts
    Rep Power
    557
    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
    18
    Posts
    805
    Thanks
    163
    Thanked 85 Times in 48 Posts
    Rep Power
    86
    Very nice, willing to use this thanks!
    Life for today, party tonight.
    Reply With Quote  
     

  4. #4  
    Fuckin PRO

    Nando's Avatar
    Join Date
    Feb 2009
    Age
    18
    Posts
    3,311
    Thanks
    2,004
    Thanked 634 Times in 292 Posts
    Rep Power
    3790
    cool nice


    Reply With Quote  
     

  5. #5  
    dont fukin ask me for client services

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    12
    Posts
    6,938
    Thanks
    1,275
    Thanked 2,040 Times in 716 Posts
    Rep Power
    5000
    Thanks .

    Reply With Quote  
     

  6. #6  
    Registered Member
    natsu's Avatar
    Join Date
    Apr 2007
    Age
    22
    Posts
    2,118
    Thanks
    847
    Thanked 392 Times in 235 Posts
    Rep Power
    351
    thanks galkon i needed this





    Reply With Quote  
     

  7. #7  
    dont fukin ask me for client services

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    12
    Posts
    6,938
    Thanks
    1,275
    Thanked 2,040 Times in 716 Posts
    Rep Power
    5000
    No problem.

    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2008
    Age
    21
    Posts
    2,571
    Thanks
    642
    Thanked 511 Times in 304 Posts
    Rep Power
    0
    this is epic
    Reply With Quote  
     

  9. Thankful user:


  10. #9  
    #1 footwear

    Shoes's Avatar
    Join Date
    Aug 2009
    Age
    16
    Posts
    2,633
    Thanks
    187
    Thanked 257 Times in 156 Posts
    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 Nicholas's Avatar
    Join Date
    May 2011
    Age
    22
    Posts
    323
    Thanks
    104
    Thanked 57 Times in 35 Posts
    Rep Power
    15
    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
  •