Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:33 PM
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:30 PM
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:25 PM
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:19 PM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 19, 2019, 12:36:06 PM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 19, 2019, 12:35:49 PM
    • Codar: Come join us while we're fresh we're growing fast!! @ [link]
      September 18, 2019, 09:30:25 PM
    • Codar: New RSPS come check us out! @ [link]
      September 18, 2019, 04:07:24 AM
    • Codar: Released a new server come check us out! @ [link]
      September 18, 2019, 02:08:23 AM
    • ragnoroker: RuneGuild will be hosting some tournaments later to win some mystery boxes, join here : [link]
      September 16, 2019, 09:50:10 AM
    • calemx: death's-server has officially been released, come check us out  - [link]
      September 13, 2019, 04:14:21 AM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 12, 2019, 12:26:40 PM
    • cbrophy: would my account from 2013 work?
      September 12, 2019, 05:04:43 AM
    • ragnoroker: RuneGuild has officially been released, come check us out - [link]
      September 11, 2019, 11:26:35 AM
    • ragnoroker: RuneGuild has officially been released, come check us out - [link]
      September 11, 2019, 11:26:31 AM
    • ragnoroker: RuneGuild is due to be released tomorrow! First few players will recieve some goodies. Sign up on our website [link] Join our discord for updates [link]
      September 07, 2019, 07:43:28 PM
    • ragnoroker: RuneGuild is due to be released tomorrow! First few players will recieve some goodies. Sign up on our website [link] Join our discord for updates [link]
      September 07, 2019, 07:42:59 PM
    • ChrisMeadows: Yo, what's the forum's discord?
      September 04, 2019, 08:33:06 PM
    • newerarsps: i cannot register to rsps list anyone can help?
      September 01, 2019, 11:24:00 PM
    • PavSwag: Date Registered: July 03, 2012, 03:54:45 PM Think im just as good vet as u man, + I have over 80B in rs3 think im good on anyones 100k ass lookin bank b oi
      August 27, 2019, 10:48:09 AM

    Author Topic: Random Rewards  (Read 2777 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
    Runescape Gambling

    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:)
    Runescape Gambling

    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,699
    • 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