Thread: Digging (handled)

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Digging (handled) 
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Make a class called DiggingHandler, put this in it (NOTE: Uses Graham's event manager):

    Code:
    /**
    * Digging Handler
    *  Made by Filth
    * WHERE ARE YOUR CONVENTIONS NOW!?
    **/
    
    public class DiggingHandler {
    
    	public int absX = -1;
    	public int absY = -1;
    	public int playerId = -1;
    	public int weapon = -1;
    	public int catche = 0;
    	public int emoteTime = 490;
    	public int actionTimer = 0;
    
    	public void dig(int player) {
    	final client c = (client) server.playerHandler.players[player];
    		playerId = c.playerId;
    		absX = c.absX;
    		absY = c.absY;
    		if (actionTimer == 0) {
    		actionTimer = 3;
    		if (c.playerEquipment[c.playerWeapon] != 952) {
    			weapon = c.playerEquipment[c.playerWeapon];
    		}
    		c.updateRequired = true;
    		c.appearanceUpdateRequired = true;
    		c.playerEquipment[c.playerWeapon] = 952;
    		animation(831);
    		c.updateRequired = true;
    		c.appearanceUpdateRequired = true;
    
    		/* Reset Weapon */
    
    			EventManager.getSingleton().addEvent(new Event() {
    					public void execute(EventContainer x) {
    						c.playerEquipment[c.playerWeapon] = weapon;
    						if (actionTimer > 0) {
    							actionTimer--;
    						} else {
    						x.stop();
    					}
    				}
    			}, emoteTime);
    			c.updateRequired = true;
    			c.appearanceUpdateRequired = true;
    
    			/* Add digging things here */
    			if (absX == 5000 && absY == 5000) {
    				c.sendMessage("ROW ROW FITE DA POWA");
    			}
    			if (area(2607, 3098, 2605, 3096)) {
    				c.sendMessage("LOL NICE! DIS ARE TEST");
    			} else if (area(5000, 5000, 2000, 2000)) {
    				c.sendMessage("U DID IT AGAIN WTF");
    			} else {
    				c.sendMessage("Nothing interesting happens.");
    			}
    		}
    	}
    
    	public boolean area(int X, int Y, int X2, int Y2) {
    	client c = (client) server.playerHandler.players[playerId];
    		if (c.absX <= X && c.absY <= Y && c.absX >= X2 && c.absY >= Y2) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    
    	public void animation(int emote) {
    	client c = (client) server.playerHandler.players[playerId];
    		c.pEmote = emote;
    		c.updateRequired = true;
    		c.appearanceUpdateRequired = true;
    		c.animationReset = System.currentTimeMillis() + emoteTime;
    	}
    }
    In server.java add

    Code:
    	public static DiggingHandler DiggingHandler = null;
    and in main method

    Code:
    		DiggingHandler = new DiggingHandler();
    In client.java inside of case 122 put:

    Code:
    			if (ItemID == 952) { // Spade
    				server.DiggingHandler.dig(playerId);
    			} else {
    				if (System.currentTimeMillis() - lastAction >= 850) {
    					buryItem(ItemID, ItemSlot);
    					lastAction = System.currentTimeMillis();
    					actionTimer = 10;
    				}
    			}
    Nao ur gun dig. BTW u mite want to make weapon save incase teh person r disconnect, so when tey log in and tey r has dig, giv tem tere wepon

    Why make a handler? Because I hate adding stuff to client.java That's all.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Jun 2008
    Posts
    734
    Thanks given
    8
    Thanks received
    14
    Rep Power
    148
    i dont think this need a handler but anyway nice job
    btw. In server.java add
    Code:
    public static DiggingHandler DiggingHandler = null;
    and in main method
    Code:
    DiggingHandler = new DiggingHandler();
    make that code this:
    Code:
    public static DiggingHandler DiggingHandler = new DiggingHandler();
    S Quare Quxx: Raul > paladin end of the story
    Reply With Quote  
     

  3. #3  
    Shelton
    Guest
    public int absX = -1;
    public int absY = -1;
    public int playerId = -1;
    public int weapon = -1;
    public int catche = 0;
    public int emoteTime = 490;
    public int actionTimer = 0;

    can be used simply as client.var = yadayada

    also

    why do you need to reset the weapon? Does the spade replace your main hand? (Not criticizing just wondering)
    Reply With Quote  
     

  4. #4  
    Registered Member

    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    31
    Posts
    12,467
    Thanks given
    156
    Thanks received
    4,812
    Rep Power
    5000
    A bit of a waste of time putting it into a 'handler' when you could just put it with the other packet 122 stuff.

    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Quote Originally Posted by Shelton View Post
    public int absX = -1;
    public int absY = -1;
    public int playerId = -1;
    public int weapon = -1;
    public int catche = 0;
    public int emoteTime = 490;
    public int actionTimer = 0;

    can be used simply as client.var = yadayada

    also

    why do you need to reset the weapon? Does the spade replace your main hand? (Not criticizing just wondering)
    Since you'd use absX and absY alot, I figured it would save the lazy people some time. I put playerId, so I can call it in the other methods like animation, instead of saying animation(player, blah);

    weapon, catche, emotetime, and actiontimer need to be there.



    Quote Originally Posted by Luke132 View Post
    A bit of a waste of time putting it into a 'handler' when you could just put it with the other packet 122 stuff.
    Thats what they want you to do. They want you to have a big fat client.java when you can have a sexy handler. Handlers are betar
    Reply With Quote  
     

  6. #6  
    Member #35, most veteran member left? :D


    Join Date
    Jul 2006
    Age
    25
    Posts
    2,664
    Thanks given
    53
    Thanks received
    330
    Rep Power
    925
    There's no point in replacing the weapon, because the animation does that for you. Also, the animation you have now (831) is the looping dig animation. If you don't want it to loop, use 830.
    [Only registered and activated users can see links. ] - The easiest, quickest, and most efficient way to create dialogue for your server.

    Click to check out the most unique, fun, and promising server to date:
    [Only registered and activated users can see links. ]

    >>> [Only registered and activated users can see links. ]

    `Ex-global moderator x3 (resigned)
    Facts or didn't happen.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Quote Originally Posted by Runite View Post
    There's no point in replacing the weapon, because the animation does that for you. Also, the animation you have now (831) is the looping dig animation. If you don't want it to loop, use 830.
    Animation doesn't do I tried
    Reply With Quote  
     

  8. #8  
    Moderator
    Ramenryoko's Avatar
    Join Date
    Jul 2006
    Posts
    168
    Thanks given
    1
    Thanks received
    6
    Rep Power
    48
    I don't like this:

    Code:
    public void dig(int player) {
    You should have done:

    Code:
    public void dig(Player p) {
    My reason for this is when a player disconnects or logs in player IDs can end up messed up sometimes when player lists refresh. Use objects instead of playerId's to prevent problems. Not to mention it's just a better way of doing things.
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Quote Originally Posted by Linux View Post
    This is coded wrong.


    Why would you want to load the class on start up?

    You want to load the class when it need to load or it will use up space in the JVM.....

    Also do this



    to



    Learn from your mistakes
    Why client c?
    Reply With Quote  
     

  10. #10  
    Shelton
    Guest
    example:

    Code:
    protected class Digging {
    private client c;
    
        public Digging(client _c) {
             c = _c;
        }
        // now that we have client ready
        c.sendMessage("Lol ohai dint c u ther");
    }
    Now you don't have to do

    client c = (client) server.playerHandler.players[playerId];

    every time you feel like accessing it

    NOW: To load the class:

    Digging dig = new Digging(client); (or this depending on which you're in)

    then when you feel like nulling the dig class so don't waste JVM space or w/e

    dig = null;
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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

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