Thread: Lottery Minigame

Results 1 to 6 of 6
  1. #1 Lottery Minigame 
    Registered Member Dds legend's Avatar
    Join Date
    Nov 2011
    Posts
    101
    Thanks given
    6
    Thanks received
    8
    Rep Power
    11
    Hey, Dds ledg here. Im going to be showing you a lottery minigame, This will be started by an admin, then people pay 75k to enter. The winner is then drawn when the admin draws the lottery, and the winner receives the gold.

    Pictures:









    OK first go into src -- org -- rscdaemon -- server and create a new folder called minigames. In that folder make a new class called Lottery.java

    Code:
    package org.rscdaemon.server.minigames;
    
    import org.rscdaemon.server.util.Formulae;
    import org.rscdaemon.server.model.Player;
    import org.rscdaemon.server.model.World;
    import org.rscdaemon.server.model.InvItem;
    import org.rscdaemon.server.event.DelayedEvent;
    import org.rscdaemon.server.event.SingleEvent;
    
    import java.util.ArrayList;
    
    public class Lottery {
    
    	 public static final World world = World.getWorld();
    	 static Player player;
    
    	 public static ArrayList<Player> players = new ArrayList<Player>();
    	 public static ArrayList<String> playersUsername = new ArrayList<String>();
    	 public static int entryFee = 75000;
    	 public static int lotteryReward = 0;
    	
    	 public static String findLotteryWinner() {
    		 if(players.size() <= 0) { // Shouldn't Happen
    			 return "No-one participated!";
    		 }
    		 Player p = players.get(Formulae.Rand(0, (players.size() - 1)));
    		 if((p != null) && (p.getUsername() != null)) {
    			 p.getActionSender().sendMessage("Congratulations! You have won the lottery!");
    			 InvItem coins = new InvItem(10);
    			 coins.setAmount(lotteryReward);
    			 p.getInventory().add(coins);
    			 p.getActionSender().sendInventory();
    			 p.getActionSender().sendMessage(lotteryReward + " coins has been added to your inventory!");
    			 world.sendToAll("The lottery has been drawn! The winner is: @or1@" + p.getUsername());
    			 endLottery();
    			 return p.getUsername();
    		 } else {
    			 players.remove(p);
    			 return findLotteryWinner();
    		 }
    	 }
    	
    	 public static void addLotteryEntry(Player p) {
    		 if(world.getLotteryStatus() == false) {
    			 p.getActionSender().sendMessage("The lottery isn't running at the moment!");
    			 return;
    		 }
    		 if(players.contains(p)) {
    			 p.getActionSender().sendMessage("You have already joined the lottery!");
    			 return;
    		 }
    		 if(p.getInventory().countId(10) >= entryFee) {
    			 if(p.getInventory().remove(10, entryFee) != -1) {
    				 players.add(p);
    				 playersUsername.add(p.getUsername());
    				 p.getActionSender().sendInventory();
    				 lotteryReward += entryFee;
    				 p.getActionSender().sendAlert("You have been entered successfully into the lottery! The current jackpot prize is: @or1@" + (lotteryReward > 1000 ? (lotteryReward / 1000) + "k" : lotteryReward) + "@whi@ coins!", false);
    				 return;
    			 }
    		 }
    		 p.getActionSender().sendMessage("It looks like you don't have enough money! You need 75K to join!");
    	 }
    	
    	 public static void endLottery() {
    		 world.setLotteryStatus(false);
    		 players = new ArrayList<Player>();
    		 playersUsername = new ArrayList<String>();
    		 lotteryReward = 0;
    	 }
    	
    	 public static void requestPrizeFund() {
    		 if(world.getLotteryStatus() == false) {
    			 player.getActionSender().sendMessage("The lottery is not running at the moment!");
    		 } else {
    			 player.getActionSender().sendMessage("The current lottery fund is: " + (lotteryReward > 1000 ? (lotteryReward / 1000) + "k" : lotteryReward));
    		 }
    	 }
    }
    Now in World.java (src -- org -- rscdaemon -- server -- model)
    First import:

    Code:
    import org.rscdaemon.server.minigames.Lottery;
    Then Add:

    Code:
    	/**
    	 * Lottery System @author Yong Min
    	 */
    	 public boolean lotteryStatus = false;
    	
    	 public void setLotteryStatus(boolean lotto) {
    		 lotteryStatus = lotto;
    	 }
    	
    	 public boolean getLotteryStatus() {
    		 return lotteryStatus;
    	 }
    Then in CommandHandler.java (src -- org -- rscdaemon -- server -- packethandler\client -- org -- client) First import:

    Code:
    import org.rscdaemon.server.minigames.Lottery;
    Then add:

    Code:
    		/**
    		 * Lottery System Commands
    		 *	   @author Yong Min
    		 */
    		 if((cmd.equalsIgnoreCase("start")) && (player.isAdmin())) {
    			 if(world.getLotteryStatus() == false) {
    				 world.setLotteryStatus(true);
    				 world.sendToAll("The lottery has been started. Use @or1@::lottery @whi@to enter!");
    			 } else {
    				 player.getActionSender().sendMessage("The lottery is already running!");
    			 }
    			 return;
    		 }
    		 if((cmd.equalsIgnoreCase("draw")) && (player.isAdmin())) {
    			 if((Lottery.players.size() <= 2) && (world.getLotteryStatus() == true)) {
    				 player.getActionSender().sendMessage("Please wait for more people to join before drawing the lottery!");
    			 } else if(world.getLotteryStatus() == false) {
    				 player.getActionSender().sendMessage("The lottery is not running at the moment!");
    			 } else {
    				 Lottery.findLotteryWinner();
    			 }
    			 return;
    		 }
    		 if(cmd.equalsIgnoreCase("lottery")) {
    			 Lottery.addLotteryEntry(player);
    		 }
    		 if(cmd.equalsIgnoreCase("fund")) {
    			 int lotteryReward = Lottery.lotteryReward;
    			 if(world.getLotteryStatus() == false) {
    				 player.getActionSender().sendMessage("The lottery is not running at the moment!");
    			 } else {
    				 player.getActionSender().sendMessage("The current lottery fund is: " + (lotteryReward > 1000 ? (lotteryReward / 1000) + "k" : lotteryReward));
    			 }
    			 return;
    		 }
    The Commands are easy to do and understand. Here is a breif explination of what they do:

    :tart *this will set the lottery status to 'true', meaning that people will be able to enter the lottery.
    :: draw *this will draw the lottery and declare the winner. You will only be able to draw the lottery once 3 or more people have entered.
    ::lottery *this will allow people to enter the lottery if they have the correct amount of cash to enter. You can alter the amount in the Lottery class.
    ::fund *this will display the current jackpot fund. This is worked out by all the entry fees added together. The winner will receive the full amount.
    Enjoy!
    Reply With Quote  
     

  2. #2  
    Java | JavaScript | Spark

    Join Date
    Sep 2008
    Posts
    868
    Thanks given
    104
    Thanks received
    83
    Rep Power
    21
    Good job, might use this if I don't know what to add to my server anymore...
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Nov 2011
    Posts
    23
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    Credits to yong min of course. You can't steal code and not credit people.
    Reply With Quote  
     

  4. #4  
    Donator

    ProFiles's Avatar
    Join Date
    May 2011
    Posts
    1,673
    Thanks given
    4
    Thanks received
    240
    Rep Power
    118
    Thnx, not going to use though.
    Reply With Quote  
     

  5. #5  
    Fuckin PRO Derek's Avatar
    Join Date
    May 2008
    Posts
    1,257
    Thanks given
    38
    Thanks received
    86
    Rep Power
    67
    Not job on this. Might test this out and fix bugs if there are any, thanks.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Pkbobby_'s Avatar
    Join Date
    Mar 2014
    Posts
    898
    Thanks given
    243
    Thanks received
    102
    Rep Power
    83
    Ty sir
    Reply With Quote  
     


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. Lottery help
    By x25xquinton in forum Help
    Replies: 1
    Last Post: 10-27-2011, 06:47 PM
  2. [PI] Lottery
    By OldskoolGaming in forum Requests
    Replies: 19
    Last Post: 05-13-2011, 01:04 PM
  3. Lottery?
    By americanboyg in forum Show-off
    Replies: 4
    Last Post: 06-16-2009, 03:39 AM
  4. My Lottery
    By Oxygen in forum Snippets
    Replies: 12
    Last Post: 06-01-2009, 09:12 PM
  5. Lottery
    By Eleclion in forum Tutorials
    Replies: 11
    Last Post: 10-18-2007, 10:26 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
  •