Thread: 98% Mining for Emulous

Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1 98% Mining for Emulous 
    Registered Member
    Join Date
    Jul 2007
    Posts
    205
    Thanks given
    2
    Thanks received
    1
    Rep Power
    25
    Purpose: To add mining to your server.
    Features: random gems, mining emotes, multi player mining, etc.
    Difficulty: 1, find your rocks by yourself.

    Ya, I made this in about 4 hours with no reference... you must do my woodcutting tutorial first otherwise you'll be lost from the start. It's also recommended to do my other tutorial to change it to hashmap, but you don't have to.

    make a new class in server.players.Skills called mining.

    place this in there

    Code:
    package server.players.Skills;
    
    import server.players.Client;
    import server.Server;
    import server.util.Misc;
    
    /**
     * 
     * @author Livinglife
     * 
     * Initial Mining
     *
     */
    
    public class Mining implements Skill
    {
    
    	public static int skillX = 0;
    	public static int skillY = 0;
    	public int toadd = -1;
    	public int replace = 452;
    	public final static int VALIDAXE[] = { 1265, 1267, 1269, 1271, 1273, 1275 };
    	public final static int UNCUTS[] = { 1617, 1619, 1621, 1623, 1625, 1627, 1629, 1631, 6571 };
    	public int xp = 0;
    	public static int item = -1;
    	private Client c;
    
    
    	/**
    	 * 
    	 * @param c
    	 * @param object
    	 * @param type
    	 * @param x
    	 * @param y
    	 */
    	public Mining(Client c, int object, String type, int x, int y)
    	{
    		this.c = c;
    		readInput(this.c.playerLevel[14], type, this.c, x, y, object);
    	}
    	
    	public Mining(Client c) 
    	{
    	this.c = c;
    	}
    	
    	/**
    	 * 
    	 * @param level
    	 * @param type
    	 * @param c
    	 * @param objectx
    	 * @param objecty
    	 * @param objectid
    	 */
    	public void readInput(int level, String type, Client c, int objectx, int objecty, int objectid)
    	{
    		synchronized(this)
    		{
    		if (type.equals("TIN") && level >= 1)
    		{
    			xp = 18;
    			item = 438;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("COPPER") && level >= 1)
    		{
    			xp = 18;
    			item = 436;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("BLUR") && level >= 10)
    		{
    			xp = 18;
    			item = 668;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("ELEMENTAL") && level >= 20)
    		{
    			xp = 0;
    			item = 2892;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("GRANITE") && level >= 45)
    		{
    			int i = Misc.random(3);
    			if (i == 1)
    			{
    				xp = 50;
    				item = 6979;
    				this.c.canmine = true;
    			}
    			
    			else if (i == 2)
    			{
    				xp = 60;
    				item = 6981;
    				this.c.canmine = true;
    			}
    			
    			else if (i == 3)
    			{
    				xp = 75;
    				item = 6983;
    				this.c.canmine = true;
    			}
    		}
    		
    		else if (type.equals("CLAY") && level >= 1)
    		{
    			xp = 5;
    			item = 434;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("ESS") && level >= 1)
    		{
    			if (level >= 30)
    			{
    			xp = 5;
    			item = 1436; 
    			}
    			else
    			{
    			xp = 5;
    			item = 7936;
    			}
    		}
    		
    		else if (type.equals("IRON") && level >= 15)
    		{
    			xp = 35;
    			item = 440;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("SILVER") && level >= 20)
    		{
    			xp = 40;
    			item = 442;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("COAL") && level >= 30)
    		{
    			xp = 50;
    			item = 453;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("GOLD") && level >= 40)
    		{
    			xp = 65;
    			item = 444;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("MITH") && level >= 55)
    		{
    			xp = 80;
    			item = 447;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("ADDY") && level >= 70)
    		{
    			xp = 95;
    			item = 449;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("RUNE") && level >= 85)
    		{
    			xp = 125;
    			item = 451;
    			this.c.canmine = true;
    		}
    		
    		else if (type.equals("LIME") && level >= 10)
    		{
    			xp = 27;
    			item = 3211;
    			this.c.canmine = true;
    		}
    		
    		else
    		{
    			this.c.sendMessage("You need a higher mining level to extract ore from this rock!");
    			xp = 0;
    			item = -1;
    			this.c.canmine = false;
    		}
    	}
    			for (int id : VALIDAXE)
    			{
    				System.out.println(id);
    				System.out.println(c.playerEquipment[c.playerWeapon]);
    			if(id == c.playerEquipment[c.playerWeapon] && c.canmine && canminewithpick(c.playerEquipment[c.playerWeapon], c) || c.getItems().playerHasItem(id, 1) && c.canmine && canminewithpick(id, c))
    				{
    				System.out.println("Called");
    				switch (id)
    				{
    				case 1265:
    					c.mineanim = 625;
    					c.intervaldeduction = 0;
    				break;
    				case 1267:
    					c.mineanim = 626;
    					c.intervaldeduction = 1;
    					break;
    				case 1269:
    					c.mineanim = 627;
    					c.intervaldeduction = 2;
    					break;
    				case 1271:
    					c.mineanim = 628;
    					c.intervaldeduction = 3;
    					break;
    				case 1273:
    					c.mineanim = 629;
    					c.intervaldeduction = 4;
    					break;
    				case 1275:
    					c.mineanim = 624;
    					c.intervaldeduction = 5;
    					break;
    				}
    				try
    				{
    				this.c.sendMessage("You swing your pick at the rock.");
    				c.turnPlayerTo(objectx, objecty);
    				this.c.minetime = Misc.random(20 - c.intervaldeduction);
    				if (!type.equals("ESS"))
    				{
    				Server.worldObject.registerObject(1, objectx, objecty, objectid, replace, 30, 10, 0, objectid);
    				}
    				this.c.mn.doaction(c, item, -1, -1, objectx, objecty, objectid, xp);
    				}
    				catch(Exception e)
    				{
    					e.printStackTrace();
    				}
    				break;
    				}
    			else if (id == c.playerEquipment[c.playerWeapon] && c.canmine && !canminewithpick(c.playerEquipment[c.playerWeapon], c) || c.getItems().playerHasItem(id, 1) && c.canmine && !canminewithpick(id, c))
    			{
    				c.sendMessage("You need a higher mining level to use this pickaxe!");
    				c.canmine = false;
    				c.ismining = false;
    			}
    		}
    	}
    	/**
    	 * 
    	 * @param i - item id
    	 * @param c - Client object
    	 * @return
    	 */
    	private boolean canminewithpick(int i, Client c) {
    		switch (i)
    		{
    		case 1265:
    		case 1267:
    			if (c.playerLevel[14] >= 1)
    				return true;
    			break;
    		case 1269:
    			if (c.playerLevel[14] >= 6)
    				return true;
    			break;
    		case 1273:
    			if (c.playerLevel[14] >= 21)
    				return true;
    			break;
    		case 1271:
    			if (c.playerLevel[14] >= 31)
    				return true;
    			break;
    		case 1275:
    			if (c.playerLevel[14] >= 41)
    				return true;
    		break;
    		default:
    			return false;
    			
    		}
    		return false;
    	}
    
    	/**
    	 * @param s
    	 * @param c
    	 */
    	public void out(String s, Client c)
    	{
    	
    	}
    
    	/**
    	 * @param c
    	 * @param toadd
    	 * @param toremove
    	 * @param toremove2
    	 * @param x
    	 * @param y
    	 * @param objectid
    	 * @param xp
    	 * @return
    	 */
    	public boolean doaction(Client c, int toadd, int toremove, int toremove2, int x, int y, int objectid, int xp) 
    	{
    	if (true)
    	{
    		if (c.getItems().freeSlots() > 0)
    		{
    		this.toadd = toadd;
    		this.c.ismining = true;
    		this.xp = xp;
    		if (c.minetime <= 0)
    		{
    			if (Misc.random(20) == 1 || Misc.random(10) == 1 && toadd == 453)
    			{
    				this.c.getItems().addItem(UNCUTS[Misc.random(8)], 1);
    				this.c.sendMessage("You find a gem in the rock!");
    			}
    		if (!(toadd == 1436) && !(toadd == 7936))
    		{
    		Server.worldObject.reduceHealth(x, y);
    		}
    		if (!(toadd == 1436) && !(toadd == 7936))
    		{
    		this.c.sendMessage("You get some ore");
    		}
    		else
    		{
    			this.c.sendMessage("You get some essence");
    		}
    		System.out.println(c.intervaldeduction);
    		this.c.minetime = Misc.random(20 - c.intervaldeduction);
    		this.c.getItems().addItem(toadd, 1);
    		this.c.getPA().addSkillXP(xp, 14);
    		this.c.getPA().refreshSkill(14);
    		}
    	}
    		else
    		{
    		this.c.sendMessage("You've do not have enough room in your inventory.");
    		this.c.canmine = false;
    		this.c.ismining = false;
    		this.c.minetime = 0;
    		}
    	}
    	return true;
    	}
    
    	
    	
    }
    Your done, close out of that, open up server.world.worldobject and find

    Code:
    c.iscutting = false;
    c.cancut = false;
    place this below that code

    Code:
    c.ismining = false;
    c.canmine = false;
    c.startAnimation(65535);
    Done with that, now open up your client class and declare this somewhere

    Code:
    public boolean ismining;
    public int mineanim;
    public boolean canmine = false;
    public int minetime;
    public int minewait;
    public Mining mn = new Mining(this);
    public int intervaldeduction;
    and put this in process (yes I know I should use events blah blah blah, if you really want it as events do it yourself.)

    Code:
    if (minewait > 0)
    		{
    			minewait--;
    		}
    		
    		if (minetime > 0)
    		{
    			minetime--;
    		}
    		
    		if (ismining && canmine && minewait <= 0 && goodDistance(skillX, skillY, getX(), getY(), 1))
    		{
    			startAnimation(mineanim);
    			minewait = 5;
    		}
    		//3176 3368
    		if (minetime <= 0 && ismining && goodDistance(skillX, skillY, getX(), getY(), 1))
    		{
    			if (goodDistance(skillX, skillY, getX(), getY(), 1))
    			{
    				mn.doaction(this, mn.toadd, -1, -1, skillX, skillY, -1, mn.xp);
    			}
    			else
    			{
    				ismining = false;
    				canmine = false;
    			}
    		}
    Your done, save compile, good to go now some usage notes.

    Bugs: none?
    Changing the respawn object for like limestone granite, etc.: edit the brackets for it so like (I'll use limestone as an example) you'd do something like this

    Code:
    else if (type.equals("LIME") && level >= 10)
    		{
    			xp = 27;
    			item = 3211;
    			this.c.canmine = true;
                            replace = myreplacement;
    		}
    this can also be useful for specifying certain replacement objects like specifying a certain object id for a respawn like to make it perfect, which isn't hard and you should be able to figure it out yourself.


    Credits: Me.

    P.S. post compile errors and bugs.
    A Small price to pay... for a Muffin

    Livinglife
    Reply With Quote  
     

  2. #2  
    Registered Member Rabid Butterfly's Avatar
    Join Date
    Aug 2007
    Posts
    467
    Thanks given
    0
    Thanks received
    0
    Rep Power
    70
    Ha ha, perfect timing, because I JUST made a mining system from your woodcutting, and I JUST finished it. But I just forgot to add clay & granite, I totally forgot those were mine-able rocks.

    Well, thanks anyways. I am a fan of your work. :]
    cs508 - Coming soon.
    Reply With Quote  
     

  3. #3  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Good work
    Reply With Quote  
     

  4. #4  
    zynna
    Guest
    wow! dude your a beast...

    i tryed emulous but i failed....your codeing is great at explaining but i have a really hard time understanding =[

    huge fan though!
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jul 2007
    Posts
    205
    Thanks given
    2
    Thanks received
    1
    Rep Power
    25
    Thanks for the comments guys
    A Small price to pay... for a Muffin

    Livinglife
    Reply With Quote  
     

  6. #6  
    zynna
    Guest
    living life.....are you going to release a source with all the tuts your giving out??

    for emulous source?
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Jul 2007
    Posts
    205
    Thanks given
    2
    Thanks received
    1
    Rep Power
    25
    Probablly not, but i am making smithing right now
    A Small price to pay... for a Muffin

    Livinglife
    Reply With Quote  
     

  8. #8  
    GinGee
    Guest
    nice work I don't really get how to this but nice work maybe release a version with all your skills in
    Reply With Quote  
     

  9. #9  
    Уважение и любовь Market Banned Market Banned

    R0cky 0wnz's Avatar
    Join Date
    Mar 2008
    Age
    28
    Posts
    2,569
    Thanks given
    642
    Thanks received
    511
    Rep Power
    1716
    Quote Originally Posted by Livinglife View Post
    Probablly not, but i am making smithing right now
    Woooo..

    Hey, nice work you got there... Will be used for sure.
    Just after my specials will be fully finnished.

    Keep it up
    SELLING CREATIVESCAPE 2012 SOURCE

    [Only registered and activated users can see links. ]

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

  10. #10  
    Banned

    Join Date
    Jan 2009
    Posts
    778
    Thanks given
    74
    Thanks received
    61
    Rep Power
    0
    Code:
    .\server\players\Client.java:76: cannot find symbol
    symbol  : class Woodcutting
    location: class server.players.Client
            public Woodcutting wc = new Woodcutting(this);
                   ^
    .\server\players\Client.java:94: cannot find symbol
    symbol  : class Mining
    location: class server.players.Client
            public Mining mn = new Mining(this);
                   ^
    .\server\players\Client.java:76: cannot find symbol
    symbol  : class Woodcutting
    location: class server.players.Client
            public Woodcutting wc = new Woodcutting(this);
                                        ^
    .\server\players\Client.java:94: cannot find symbol
    symbol  : class Mining
    location: class server.players.Client
            public Mining mn = new Mining(this);
                                   ^
    4 errors
    Press any key to continue . . .
    Lulz ;D
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •