Thread: Job Holders (Slaves)

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1 Job Holders (Slaves) 
    Registered Member
    Stanaveli's Avatar
    Join Date
    Aug 2014
    Posts
    1,490
    Thanks given
    184
    Thanks received
    653
    Rep Power
    1338
    Job Holders / Slaves (Something like Miscellanious)
    Reputation and Thank's is appreciated as I'd love to build some reputation on here

    Let me start by apologizing for the title, some of you might take it offending. Honestly the npc names are called slaves, and that's why I based the title off it, this way everybody will know exactly what this system is about.

    Just like my previous releases, I will not provide a top to toe, fully programmed system, there will be bugs you have to fix yourself while using this. Ofcourse, anybody could do this in like 30 minutes, i'm just here to save you those precious 30 minutes which you could use to finish what this system needs.

    Spoiler for What this includes:
    - Easy to use
    - Quick / Average / Slow Workers
    - Random messages for each worker
    - Documented
    - Clean
    - More that I can't think of atm


    Spoiler for What it needs:
    - Checks, this wasn't made for your server.
    - Saving, because when you logout, you'd want this to not stop.
    - I've included a small ' Anti leech ', basically the cycle event never ends once it's called, I think you should fix that.


    I could of fixed and done what it needed, but I want you guys to put some work in this that way you'll learn how to do something similar the next time, and while you are figuring out how to do it, you will be studying the code which is another good thing.

    Alright, let's get started, this is the point where i'm going to explain you exactly what to put where and for what reason.

    1) You'd want to create a new class, I'd suggest creating it in it's own package, but that is up to you. once you've done that, you'd want to create a class inside it, name the class Worker and paste this inside it, the code is documented so you should be able to understand what each part does.

    Code:
    package server.game.players.workers;
    
    import server.event.*;
    import server.game.players.Client;
    
    /**
     * @author Stan : 15 / 08 / 2014
     * Represents an abstract class for workers (slaves)
     */
    
    public abstract class Workers {
    	
    	/**
    	 * The items the player belongs to
    	 */
    	private final Client player;
    	/**
    	 * The item id being worked for.
    	 */
    	private final int id;
    	
    	/**
    	 * The amount being worked for.
    	 */
    	private final int amount;
    	
    	/**
    	 * The amount it costs.
    	 */
    	private final int price;
    
    	/**
    	 * The amount of time it costs until it's finished.
    	 */
    	private final int time;
    	
    	/**
    	 * The flag which represents whether it has to process the payment
    	 */
    	private boolean check = false;
    	
    	/**
    	 * A protected void to handle the force messages of npcs
    	 */
    	protected abstract String randomMessage(String message);
    	
    	/**
    	 * A protected integer to hold the npcs npc id
    	 */
    	protected abstract int npcId(int id);
    	
    	/**
    	 * creates the worker
    	 * 
    	 * @param player
    	 * @param id
    	 * @param amount
    	 * @param price
    	 */
    	protected Workers(final Client player, final int id, final int amount, final int price, final int time, final boolean check) {
    		this.player = player;
    		this.id = id;
    		this.amount = amount;
    		this.price = price;
    		this.time = time;
    		this.check = check;
    	}
    	
    	/**
    	 * Gets the item id
    	 * @return the item id
    	 */
    	private final int getId() {
    		return id;
    	}
    
    	/**
    	 * Gets the amount
    	 * @return the amount
    	 */
    	private final int getAmount() {
    		return amount;
    	}
    
    	/**
    	 * Gets the price
    	 * This is static because we need to call it from a different class.
    	 * @return the price
    	 */
    	public static final int getPrice() {
    		return price;
    	}
    	
    	/**
    	 * Gets the amount of time is left
    	 * @return the amount of time
    	 */
    	public final int getTime() {
    		return time;
    	}
    	
    	/**
    	 * Gets whether the check is true or false
    	 * @return true or false
    	 */
    	public final boolean getCheck() {
    		return check;
    	}
    	
    	/**
    	 * handles the main timer class
    	 */
    	protected void handleTimer() {
    		CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
    			@Override
    			public void execute(CycleEventContainer container) {
    				if(check == false) {
    					return;
    				} else {
    				if(getTime() > 0) {
    					time--;
    				} else if(getTime() == 0) {
    					handleQWorker();
    					check = false;
    					stop();
    				}
    				System.out.println(""+getTime());
    			}
    			}
    			@Override
    			public void stop() {
    				time = -1;
    				return;
    			}
    		}, 2);
    	}
    	
    	/**
    	 * Gives the player the item.
    	 */
    	public void handleQWorker() {
    		player.getItems().addItem(getId(), getAmount());
    	}
    }
    Now that we have implemented the main class, we still need to handle the the instanceable classes (SlowWorker, AverageWorker, QuickWorker)

    Eclipse should auto generate an impl package in the new package you created, if this isn't the case, create your own impl package.

    2) Let's add the instanceable classes, inside your impl package make 3 classes, name them SlowWorker, AverageWorker, QuickWorker, paste the following inside SlowWorker

    Code:
    package server.game.players.workers.impl;
    
    import core.util.Misc;
    import server.game.players.Client;
    import server.game.players.workers.Workers;
    
    public class SlowWorker extends Workers {
    
    	public SlowWorker(Client player, int id, int amount, int price, int time, boolean check) {
    		super(player, id, amount, price, time, check);
    		handleTimer();
    	}
    
    	@Override
    	protected String randomMessage(String message) {
    		int chatType = Misc.random(5);
    		if(chatType == 0) {
    			message = "I'm soo old, should of retired already..";
    		} else if(chatType == 1) {
    			message = "This is soo not worth what i'm being paid for...";
    		} else {
    			message = "Ohhh, my back is about to collapse..";
    		}
    		return message;
    	}
    
    	@Override
    	protected int npcId(int id) {
    		return id;
    	}
    
    }
    now paste the following in AverageWorker

    Code:
    package server.game.players.workers.impl;
    
    import core.util.Misc;
    import server.game.players.Client;
    import server.game.players.workers.Workers;
    
    public class AverageWorker extends Workers {
    
    	public AverageWorker(Client player, int id, int amount, int price, int time, boolean check) {
    		super(player, id, amount, price, time, check);
    		handleTimer();
    	}
    
    	@Override
    	protected String randomMessage(String message) {
    		int chatType = Misc.random(5);
    		if(chatType == 0) {
    			message = "Work work work work.";
    		} else if(chatType == 1) {
    			message = "Put what you want here.";
    		} else {
    			message = "Boss wants me to do work, and i'm going to do it..";
    		}
    		return message;
    	}
    
    	@Override
    	protected int npcId(int id) {
    		return id;
    	}
    
    }
    Now paste the following inside QuickWorker

    Code:
    package server.game.players.workers.impl;
    
    import core.util.Misc;
    import server.game.players.Client;
    import server.game.players.workers.Workers;
    
    public class QuickWorker extends Workers {
    
    	public QuickWorker(Client player, int id, int amount, int price, int time, boolean check) {
    		super(player, id, amount, price, time, check);
    		handleTimer();
    	}
    
    	@Override
    	protected String randomMessage(String message) {
    		int chatType = Misc.random(5);
    		if(chatType == 0) {
    			message = "Quick quick quick quick...";
    		} else if(chatType == 1) {
    			message = "The faster I work the fitter I get.";
    		} else {
    			message = "Let's get this done! the faster the more money.";
    		}
    		return message;
    	}
    
    	@Override
    	protected int npcId(int id) {
    		return id;
    	}
    
    }
    Now you've got it set up, I'll show you an example of how to execute this piece of code.

    3) Open DialogueHandler class and paste the following dialogue inside it.

    Code:
    		case 10005:
    			c.getDH().sendOption2("Armadyl Godsword", "Dragon Claws");
    			c.dialogueAction = 10005;
    			break;
    		case 10006:
    			c.getDH().sendNpcChat1("Alright, that will be "+Workers.getPrice(), c.talkingNpc, "Commissioner");
    			c.nextChat = 10007;
    			break;
    		case 10007:
    			c.getDH().sendOption2("Sure, here you go", "I can't afford that");
    			c.dialogueAction = 10007;
    			break;
    Alright, this is also the part where you'd want to make a check whether the player has the price to pay, if not there is a different dialogue.

    Now let's open Clickingbuttons class, this part will assign what to do when the dialogue buttons are clicked

    find case 9157: and paste the following below it

    Code:
    				if(c.dialogueAction == 10005) {
    					new SlowWorker(c, 11694, 1, 100, 10, false);
    					c.getDH().sendDialogues(10006, actionButtonId);
    				}
    				if(c.dialogueAction == 10007) {
    					new SlowWorker(c, 11694, 1, 100, 10, true);
    					c.getPA().removeAllWindows();
    				}
    Alright, do you see how the first SlowWorker is set to false? This partially cancels the code to be executed so you can get the price of the Job and anything else you'd need from which should be instanced, if we didn't include that piece of code, your dialogue would display "This currently costs 0" as the price was never assigned towards the Job, now it is, and the job is cancelled at the same time.

    The second SlowWorker is set to true as you can see, basically this one DOES execute the code as the parameter was set to true.

    Heres a small explanation on how SlowWorker / AverageWorker / QuickWorker is instanced.

    Code:
    new Slow/Average/Quick-Worker(c, ITEMID, AMOUNT, PRICE, TIME, TRUE OR FALSE);
    As explained before, use true when you're going to execute the code, use false when you just want to show the price in a dialogue, sendmessage or anything else you'd want to display it on.

    now that that's done, you need to find how you want to assign the dialogue to a player, you could do this with NPCS, Objects or anything else that could assign an action, i'm just going to use a command. Heres a video on what exactly this does. Enjoy

    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    ~! Legit ~!

    Join Date
    Nov 2010
    Posts
    1,973
    Thanks given
    183
    Thanks received
    211
    Rep Power
    237
    Post a video of how it works
    [email protected]
    Spoiler for My Vouches:
    Quote Originally Posted by mattsforeal View Post
    I paid $5 went first, he fixed my problem and it worked. 100% legit would do it again.
    Quote Originally Posted by Mythic View Post
    Vouch for him, very smooth and fast trade, purchased his last 4m. Have fun with your new membership
    Quote Originally Posted by Harlan View Post
    Vouch, trustworthy guy.
    Quote Originally Posted by iPhisher™ View Post
    Vouch for Super-Man, he is a very legit and trustable guy.
    Reply With Quote  
     

  4. #3  
    Registered Member
    Stanaveli's Avatar
    Join Date
    Aug 2014
    Posts
    1,490
    Thanks given
    184
    Thanks received
    653
    Rep Power
    1338
    Quote Originally Posted by D R O View Post
    Post a video of how it works
    I can't really as it isn't finished yet, basically what this does is that you could hire a worker to get you items, you wouldn't get the items directly as there is a waiting timer.

    Edit: http://www.rune-server.org/runescape...est-2-0-a.html
    Reply With Quote  
     

  5. #4  
    Banned Job Holders (Slaves) Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    randomMessages() should be an abstract method in the Workers class
    Reply With Quote  
     

  6. #5  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    Quote Originally Posted by lare96 View Post
    randomMessages() should be an abstract method in the Workers class
    This.



    Also, there's no point using accessors (e.g. getPlayer) in the same class - just use the player field directly. Workers should be singular (so, Worker) and SWorker, AWorker etc are poor names (it's not immediately obvious) - SlowWorker, AverageWorker etc will do fine. You've also use block capitals for a normal field (you should only use CAPITAL_LETTER_UNDERSCORE_NAMING for constants). Your comments should be a little more descriptive and treat the method/field as an action, e.g.

    Code:
    /**
    	 * The constructor
    	 */
    to

    Code:
    /**
    	 * Creates the worker.
    	 * 
    	 * @param client The client.
    	 * @param item The item id to work for.
    	 * @param amount The amount of the item being worked for.
    	 * @param price The amount the item(?) costs.
    	 */
    and

    Code:
    	/**
    	 * Getter
    	 */
    to

    Code:
    	/**
    	 * Gets the whatever of this worker.
    	 *
    	 * @return The whatever.
    	 */
    Declaring parameters (and local variables) final is unpleasant in the vast majority of cases, and should be reserved for when people using your code really, really should not modify them - the more you use it, the less of a warning it becomes.


    This isn't supposed to be tearing your code apart (compared to what usually gets posted in this section, it isn't bad) - keep it up :-)
    Last edited by Major; 09-19-2014 at 04:21 PM.
    Reply With Quote  
     

  7. Thankful users:


  8. #6  
    Registered Member
    Stanaveli's Avatar
    Join Date
    Aug 2014
    Posts
    1,490
    Thanks given
    184
    Thanks received
    653
    Rep Power
    1338
    Quote Originally Posted by Major View Post
    This.



    Also, there's no point using accessors (e.g. getPlayer) in the same class - just use the player field directly. Workers should be singular (so, Worker) and SWorker, AWorker etc are poor names (it's not immediately obvious) - SlowWorker, AverageWorker etc will do fine. You've also use block capitals for a normal field (you should only use CAPITAL_LETTER_UNDERSCORE_NAMING for constants). Your comments should be a little more descriptive and treat the method/field as an action, e.g.

    Code:
    /**
    	 * The constructor
    	 */
    to

    Code:
    /**
    	 * Creates the worker.
    	 * 
    	 * @param client The client.
    	 * @param item The item id to work for.
    	 * @param amount The amount of the item being worked for.
    	 * @param price The amount the item(?) costs.
    	 */
    and

    Code:
    	/**
    	 * Getter
    	 */
    to

    Code:
    	/**
    	 * Gets the whatever of this worker.
    	 *
    	 * @return The whatever.
    	 */
    Declaring parameters (and local variables) final is generally considered an anti-pattern/generally unpleasant in the vast majority of cases, and should be reserved for when people using your code really, really should not modify them - the more you use it, the less of a warning it becomes.


    This isn't supposed to be tearing your code apart (compared to what usually gets posted in this section, it isn't bad) - keep it up :-)
    Thanks, these Posts always help me improve, thats the main reason I came here to post bits of my code. (Sorry for my grammar, auto correction is a b!tch sometimes)
    Reply With Quote  
     

  9. #7  
    Donator
    Holdover's Avatar
    Join Date
    Dec 2013
    Posts
    93
    Thanks given
    20
    Thanks received
    12
    Rep Power
    1
    enum pls ty bye
    Reply With Quote  
     

  10. #8  
    Banned Job Holders (Slaves) Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by Earwig View Post
    enum pls ty bye
    ... what are you talking about?
    Reply With Quote  
     

  11. Thankful users:


  12. #9  
    Registered Member
    Stanaveli's Avatar
    Join Date
    Aug 2014
    Posts
    1,490
    Thanks given
    184
    Thanks received
    653
    Rep Power
    1338
    Quote Originally Posted by lare96 View Post
    ... what are you talking about?
    I think he ment that I should of nested the enum inside an abstract class. That would be logical and a better way to do this I assume.

    Edit: Nvm, that's just plain stupid lol
    Keep your head up.



    Reply With Quote  
     

  13. Thankful user:


  14. #10  
    Banned Job Holders (Slaves) Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by Earwig View Post
    That.
    that still doesn't make any sense... why would he nest the enum within an abstract class?
    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)


User Tag List

Similar Threads

  1. Slave Hack!!
    By Soulevoker in forum PC
    Replies: 37
    Last Post: 09-26-2008, 07:52 PM
  2. School Or A Job?
    By Grim Line in forum Voting
    Replies: 12
    Last Post: 05-07-2008, 08:07 PM
  3. Flash Job Application...
    By Hooligan in forum Videos
    Replies: 1
    Last Post: 03-27-2008, 11:40 PM
  4. How to get an easy GFX Job :)
    By ownage in forum General
    Replies: 0
    Last Post: 01-18-2008, 08:32 PM
  5. Paint job
    By Jukk in forum Showcase
    Replies: 4
    Last Post: 06-02-2007, 05:34 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
  •