Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • SuperNativeZ: 2009SCAPE - Perfect Realistic Emulation. Play Runescape like it was in 2009. [link]
      February 18, 2020, 01:04:45 PM
    • SuperNativeZ: 2009SCAPE - Perfect Realistic Emulation. Play Runescape like it was in 2009. [link]
      February 18, 2020, 01:04:39 PM
    • SuperNativeZ: 2009SCAPE - Perfect Realistic Emulation. Play Runescape like it was in 2009. [link]
      February 18, 2020, 01:04:35 PM
    • ragnoroker: Join RuneGuild Today! BIG DROP PARTY IN 1 HOUR JOIN NOW - Newish Server 30+ Online all the time - Very Unique - Play now : [link]
      February 15, 2020, 04:16:38 PM
    • ragnoroker: Join RuneGuild Today! BIG DROP PARTY IN 1 HOUR JOIN NOW - Discord : [link]
      February 15, 2020, 04:15:41 PM
    • ragnoroker: Join RuneGuild Today! BIG DROP PARTY IN 1 HOUR JOIN NOW :) - [link]
      February 15, 2020, 04:14:50 PM
    • friendlyhelper: Meet up with old and new friends and explore what Runescape Classic could have been had development continued [link]
      February 15, 2020, 03:55:17 PM
    • friendlyhelper: Meet up with old and new friends and explore what Runescape Classic could have been had development continued [link]
      February 15, 2020, 03:49:34 PM
    • friendlyhelper: After well over 6 years of continuous runtime, RSCR still most actively developed RSC server  [link]
      February 15, 2020, 03:49:29 PM
    • SnowRSPS: Checkout Snowrsps.com - Snow317.org - Snowscape.net Open 24.7 [link] !Do not join Galaxy!
      February 15, 2020, 08:15:39 AM
    • SnowRSPS: Checkout Snowrsps.com - Snow317.org - Snowscape.net Open 24.7 [link] !Do not join Galaxy!
      February 15, 2020, 08:15:32 AM
    • SuperNativeZ: GALAXY #1 UNIQUE CUSTOM RSPS [link][link]
      February 14, 2020, 12:27:16 PM
    • SuperNativeZ: GALAXY #1 UNIQUE CUSTOM RSPS [link][link]
      February 14, 2020, 12:27:11 PM
    • SuperNativeZ: GALAXY #1 UNIQUE CUSTOM RSPS [link][link]
      February 14, 2020, 12:27:00 PM
    • ragnoroker: Looking for a new server? Join RuneGuild : [link] You won't be disappointed.
      February 14, 2020, 07:49:42 AM
    • ragnoroker: Looking for a new server? Join RuneGuild : [link] You won't be disappointed.
      February 14, 2020, 07:49:37 AM
    • ragnoroker: Looking for a new server? Join RuneGuild : [link] You won't be disappointed.
      February 14, 2020, 07:49:33 AM
    • Tonystark2830: https: //discord .gg /AHeVSMQ
      February 13, 2020, 11:35:21 AM
    • Tonystark2830:[link]
      February 13, 2020, 11:35:06 AM
    • Tonystark2830:[link] who ever has the most invites will be given money weekly! whats the catch? you must have over 15 invites for the week!  if you are tied with someone else at the end of the week you will both be awarded the same amount "no it will not be split"
      February 13, 2020, 11:34:42 AM

    Author Topic: Random Rewards  (Read 2884 times)

    0 Members and 1 Guest are viewing this topic.

    OfflineValazar

    • Member
    • **
    • Posts: 21
    • Thanks: +0/-0
      • View Profile
    Random Rewards
    « on: September 22, 2012, 04:26:03 PM »
    So I wrote this snippet for my donater mystery boxes however you can use it for anything.

    Add this class, I put in my mini-games package however feel free to add it anywhere as long as you remember to change the import.

    Code: [Select]
    package server.model.minigames;

    import server.model.players.Client;
    import server.util.Misc;

    /**
     *
     * @author Jordon
     * Adds donator rewards
     *
     **/

    public class DonatorReward {

    /*
    *
    * Generates the reward
    *
    */

    private static int[][] lowRewards = {
    {995, (Misc.random(4) + 1) * 1000000},
    {537, (Misc.random(10) + 5) * 50},
    {1437, (Misc.random(500) + 100) * 10},
    {222, (Misc.random(50) + 10) * 10},
    {1520, (Misc.random(50) + 10) * 10},
    {4087, 1},
    {1740, 1},
    {4585, 1},
    {11732, 1},
    {1187, 1},
    {4151, 1},
    {3140, 1},
    {11730, 1}
    };

    private static int[][] mediumRewards = {
    {4151, 1},
    {3140, 1},
    {11732, 1},
    {11730, 1},
    {11694, 1},
    {11696, 1},
    {11698, 1},
    {11700, 1},
    {11724, 1},
    {11726, 1},
    {11728, 1},
    {11718, 1},
    {11720, 1},
    {11722, 1}
    };

    private static int[][] rareRewards = {
    {1037, 1},
    {1038, 1},
    {1040, 1},
    {1042, 1},
    {1044, 1},
    {1046, 1},
    {1048, 1},
    {1050, 1},
    {1053, 1},
    {1055, 1},
    {1057, 1}
    };

    public static int generateReward() {
    int rewardLevel = Misc.random(50);
    if(rewardLevel < 35) {
    rewardLevel = 1;
    } else if(rewardLevel < 49) {
    rewardLevel = 2;
    } else if(rewardLevel == 50) {
    rewardLevel = 3;
    } else {
    rewardLevel = 1;
    }
    return rewardLevel;
    }


    /*
    *
    * Performs checks before adding the reward
    *
    */

    public static void addReward(Client player) {
    if(player.getItems().freeSlots() >= 1) {
    if(player.getItems().playerHasItem(6199)) {
    player.getItems().deleteItem(6199, 1);
    int reward = generateReward();
    switch(reward) {
    case 1:
    int lowRandom = Misc.random(lowRewards.length - 1);
    player.getItems().addItem(lowRewards[lowRandom][0], lowRewards[lowRandom][1]);
    break;
    case 2:
    int mediumRandom = Misc.random(mediumRewards.length - 1);
    player.getItems().addItem(mediumRewards[mediumRandom][0], mediumRewards[mediumRandom][1]);
    break;
    case 3:
    int rareRandom = Misc.random(rareRewards.length - 1);
    player.getItems().addItem(rareRewards[rareRandom][0], rareRewards[rareRandom][1]);
    break;
    }
    player.sendMessage("You have recieved a reward from your mystery box!");
    }
    } else {
    player.sendMessage("You need to have atleast 1 free inventory slot to open this!");
    }
    }

    }

    And in your item clicking packet (PI is ClickItem.java) add this
    Code: [Select]
    if (itemId == 6199) { // Donator Reward Box
    DonatorReward.addReward(c);
    }

    Under
    Code: [Select]
    if (c.getFood().isFood(itemId)) {
    c.getFood().eat(itemId, itemSlot);


    This is my first ever snippet and I know its rather simple however handy, someone will probably find a way of doing it better however I tried my best.
    « Last Edit: September 22, 2012, 09:55:36 PM by Valazar »
    Runescape Gambling

    OfflineRandQm

    • Member
    • ****
    • Posts: 4,220
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #1 on: September 22, 2012, 06:56:32 PM »
    Looks alright, might help some people
    soldout

    contact me on [email protected] if you're looking for me

    Offlinejake.bellotti

    • Member
    • ***
    • Posts: 118
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #2 on: September 22, 2012, 06:59:41 PM »
    You said its your first snippet but you post it in the tutorials section:)

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #3 on: September 22, 2012, 08:37:57 PM »
    not a tutorial & why are you creating an instance of the class when you can call the method statically?

    OfflineValazar

    • Member
    • **
    • Posts: 21
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #4 on: September 22, 2012, 09:55:19 PM »
    not a tutorial & why are you creating an instance of the class when you can call the method statically?

    I have never actually noticed that snippets board until now; My mistake.

    Also, updated the code as I realised what you meant, fixed.

    Offline...nerd123456789

    • Member
    • ***
    • Posts: 246
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #5 on: September 23, 2012, 07:05:23 AM »
    it says this class isn't there wtf DonatorReward i added it still says its not there some help please xd

    OfflineSoulcist

    • Global Moderator
    • *****
    • Posts: 6,698
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #6 on: September 23, 2012, 10:02:03 AM »
    it says this class isn't there wtf DonatorReward i added it still says its not there some help please xd

    Have you added the imports?

    Offline...nerd123456789

    • Member
    • ***
    • Posts: 246
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #7 on: September 23, 2012, 03:42:39 PM »
    oh forgot well no errors but still doesn't work

    OfflineValazar

    • Member
    • **
    • Posts: 21
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #8 on: September 23, 2012, 03:48:16 PM »
    oh forgot well no errors but still doesn't work

    Why doesn't it work? Explain what's happening and I'll try to help you.

    Offlinejoint33skinz

    • Member
    • **
    • Posts: 39
    • Thanks: +0/-0
      • View Profile
    Re: Random Rewards
    « Reply #9 on: February 08, 2016, 05:04:22 AM »
    works fine thanks for the share

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal