Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • ASDss: where do u download source and clients now
      August 18, 2017, 10:39:31 PM
    • ASDss: yo
      August 18, 2017, 10:39:20 PM
    • dan v jad: click me 4 da fun ;)[link]
      August 18, 2017, 04:39:58 PM
    • stCky: Palidinho is your OpenGL (was it OpenGL?) stuff open source anywhere?
      August 16, 2017, 09:07:22 PM
    • Travas:BUILD THE WALL
      August 15, 2017, 09:28:49 PM
    • Travas: i have ass cancer
      August 15, 2017, 09:23:29 PM
    • stCky: what are the fudge are you tryna ask?
      August 15, 2017, 08:21:35 PM
    • bader: what are the rsps community alive ?
      August 15, 2017, 05:46:16 PM
    • bader: yo guys
      August 15, 2017, 05:46:08 PM
    • Spacehost:[link] Updated our thread :)
      August 15, 2017, 09:40:34 AM
    • Adaro: The client is in Download section at Homepage
      August 15, 2017, 01:09:20 AM
    • FaTe_Of_GoDs: where do i get the client?????????????
      August 14, 2017, 05:23:14 PM
    • stCky: can anyone help me? I cant login to the shoutbox
      August 13, 2017, 05:45:15 PM
    • drubrkletern: appeal denied
      August 13, 2017, 02:35:27 PM
    • King_Trout:[link]
      August 13, 2017, 11:17:12 AM
    • Cole1497: no sorry
      August 13, 2017, 10:27:14 AM
    • ayz: yo can anyone explain something to me
      August 13, 2017, 08:08:51 AM
    • coolking12: Hi
      August 13, 2017, 04:16:06 AM
    • stCky: n+1
      August 11, 2017, 06:09:24 PM
    • PalidinoDH: How many more pages are going to show errors before this dude gets on and fixes shit
      August 11, 2017, 04:57:00 PM

    Author Topic: [PI]My Gamble Command  (Read 948 times)

    0 Members and 1 Guest are viewing this topic.

    Offlinemrnessie

    • Member
    • ****
    • Posts: 384
    • Thanks: +0/-0
      • View Profile
    [PI]My Gamble Command
    « on: October 23, 2014, 06:39:45 PM »
    Hey guys! here is my gambling command. very simple, but. i like the concept. its like dicing with a lower chance and without  a second person. You type ::doubleitem (itemid)    It has a 3 in 100 chance of winning, becuz you cant have people winning on rare items alot.

    Well, here it is.
    Code: [Select]
                            if (playerCommand.startsWith("doubleitem") && playerCommand.length() > 5) {
                String[] args = playerCommand.split(" ");
    int itemBet = Integer.parseInt(args[1]);
                int doubleItem = (Misc.random(100));
                int betAmount = (itemBet * 2);
                if (!c.getItems().playerhasItem(itemBet, betAmount)) {
               c.sendMessage("[Item Doubler] You havent got a "+itemBet+" in your inventory.");
                return;
                }
                if (doubleItem > 1 && doubleItem < 3) {
                        c.sendMessage("[Item Doubler] You pulled the lever and got "+doubleItem+" and received a "+itemBet+" .</col>");
                        c.getItems().addItem(itemBet, betAmount);
    } else {
                        c.sendMessage("[Item Doubler] You lost. You will not lose or gain anything if you lose.");
        }
        }

    Let me know if you get any errors, i didnt get any with InsidiaX base.
    need developers

    OfflineSkiire

    • Member
    • ****
    • Posts: 630
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #1 on: October 23, 2014, 08:53:50 PM »
    I love seeing people dabble around and create something! Nice work.

    Constructive criticism:

    • I would not leave the ability for them to do this with no punishment, anyone with an auto-talker would ruin an economy in an hour
    • Document your code*
    • Work on conventions, pretend that you're programming for an audience, make things self-documenting.

    *I suggest this, even for something this small, because there are a few mistakes that would be caught with a thorough read-over.

    Code: [Select]
    if (playerCommand.startsWith("doubleitem")) {
    int item = Integer.parseInt(args[1]);
    int chance = Misc.random(100);
    boolean won = chance <= 3;
    if (!c.getItems().playerHasItem(item, 1)) {
    c.sendMessage("[Item Doubler] You havent got a "+itemBet+" in your inventory.");
    return;
    }
    if (won) {
    c.getItems().addItem(item, 2);
    c.sendMessage("[Item Doubler] You won a " + item + "!");
    } else {
    c.getItems().deleteItem(item, 1);
    c.sendMessage("[Item Doubler] You lost.");
    }
    }


    Offlinemrnessie

    • Member
    • ****
    • Posts: 384
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #2 on: October 24, 2014, 04:35:54 AM »
    I love seeing people dabble around and create something! Nice work.

    Constructive criticism:

    • I would not leave the ability for them to do this with no punishment, anyone with an auto-talker would ruin an economy in an hour
    • Document your code*
    • Work on conventions, pretend that you're programming for an audience, make things self-documenting.

    *I suggest this, even for something this small, because there are a few mistakes that would be caught with a thorough read-over.

    Code: [Select]
    if (playerCommand.startsWith("doubleitem")) {
    int item = Integer.parseInt(args[1]);
    int chance = Misc.random(100);
    boolean won = chance <= 3;
    if (!c.getItems().playerHasItem(item, 1)) {
    c.sendMessage("[Item Doubler] You havent got a "+itemBet+" in your inventory.");
    return;
    }
    if (won) {
    c.getItems().addItem(item, 2);
    c.sendMessage("[Item Doubler] You won a " + item + "!");
    } else {
    c.getItems().deleteItem(item, 1);
    c.sendMessage("[Item Doubler] You lost.");
    }
    }

    Responses to your Criticism:
    1. I plan on making it so you can get the ability to do this with every vote (so you have to vote to do it)
    2. I dont know what you mean by "Document Your Code" (i think you mean organize, which i feel it is organized)
    3. I will work on my conventions

    As for your code, The reward is wrong, you'd be tripling their item
    Code: [Select]
    if (won) {
    c.getItems().addItem(item, 2);
    c.sendMessage("[Item Doubler] You won a " + item + "!");

    The "addItem(item, 2)" would need to be "addItem(item, 1)" because, it doesnt delete the original item they bet, so adding 2 would make them have 3. Sorry I'm just being picky..

    Anyways, Thanks for your feedback
    need developers

    OfflineSkiire

    • Member
    • ****
    • Posts: 630
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #3 on: October 24, 2014, 01:53:58 PM »
    I like the idea of only being allowed to use this after voting, that would be a much better implementation! What I meant by documenting the code was to just place comments on any questionable parts of the code, written in a language of your choosing; I feel that would help to catch simple mistakes. This is not necessary, I just think it would be helpful for you to re-read the code and remove all dead-code.

    Code: [Select]
                            if (playerCommand.startsWith("doubleitem") && playerCommand.length() > 5) {
                String[] args = playerCommand.split(" ");
    int itemBet = Integer.parseInt(args[1]);
                int doubleItem = (Misc.random(100));
    //betAmount is the item they bet (after the split) multiplied by 2
                int betAmount = (itemBet * 2);
    //if the player does not have 2 of the item they bet (itemBet)
                if (!c.getItems().playerhasItem(itemBet, betAmount)) {
               c.sendMessage("[Item Doubler] You havent got a "+itemBet+" in your inventory.");
                return;
                }
    //if doubleItem is greater than 1 and less than 3 (only number meeting both params is 2)
                if (doubleItem > 1 && doubleItem < 3) {
                        c.sendMessage("[Item Doubler] You pulled the lever and got "+doubleItem+" and received a "+itemBet+" .</col>");
    //adds 2 of the item they bet (itemBet)
                        c.getItems().addItem(itemBet, betAmount);
    } else {
                        c.sendMessage("[Item Doubler] You lost. You will not lose or gain anything if you lose.");
        }
        }

    Wonderful catch seeing how it does not delete their item before adding two more!
    « Last Edit: October 24, 2014, 01:55:31 PM by Skiire »

    Offlinemrnessie

    • Member
    • ****
    • Posts: 384
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #4 on: October 24, 2014, 02:24:58 PM »
    Lol thanks for the feedback :D
    need developers

    Offlinerunescape sucks

    • Member
    • ****
    • Posts: 2,798
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #5 on: October 24, 2014, 03:28:58 PM »
    I wrote one based on what you did. I haven't tested it or anything.
    (click to show/hide)

    However, in your code I noticed that these are just the same (basically)
    Code: Java
    1. int itemBet =Integer.parseInt(args[1]);
    2. int betAmount =(itemBet *2);
    And correct me if I'm wrong, but isn't the itemBet variable supposed to represent the item's ID? In that case, say the item's ID is 1000. You would give them back 2000 items (or maybe 1000 based on how the code was written I didn't read it while writing this) when they win.
    (click to show/hide)

    Offlinemrnessie

    • Member
    • ****
    • Posts: 384
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #6 on: October 24, 2014, 04:33:42 PM »
    I wrote one based on what you did. I haven't tested it or anything.
    (click to show/hide)

    However, in your code I noticed that these are just the same (basically)
    Code: Java
    1. int itemBet =Integer.parseInt(args[1]);
    2. int betAmount =(itemBet *2);
    And correct me if I'm wrong, but isn't the itemBet variable supposed to represent the item's ID? In that case, say the item's ID is 1000. You would give them back 2000 items (or maybe 1000 based on how the code was written I didn't read it while writing this) when they win.

    Code: Java
    1. int itemBet =Integer.parseInt(args[1]);
    2. int betAmount =(itemBet *2);

    These are not the same, itemBet is the item that you bet, betAmount is how many


    need developers

    Offlinerunescape sucks

    • Member
    • ****
    • Posts: 2,798
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #7 on: October 24, 2014, 04:44:20 PM »
    Exactly, and if you double the item that you bet, you'll get double that item's ID, correct?
    (click to show/hide)

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #8 on: October 24, 2014, 04:44:39 PM »
    I guess we're all releasing versions of this...
    here's my command:
    Code: Java
    1.                 if(cmd.length<3){
    2.                         player.sendMessage("Please use the command as ::gamble amount item_name");
    3.                         return;
    4.                 }
    5.                 String itemName ="";
    6.                 int amount =-1;
    7.  
    8.                 try{
    9.                         amount =Integer.parseInt(cmd[1]);
    10.                         if(amount <1){
    11.                                 player.sendMessage("You need to bet at least 1 item.");
    12.                                 return;
    13.                         }
    14.                 }catch(NumberFormatException e){
    15.                         player.sendMessage("Please use the command as ::gamble amount item_name");
    16.                         return;
    17.                 }
    18.  
    19.                 for(int i =2; i < cmd.length; i++){
    20.                         if(cmd[i]!=null&& cmd[i].length()>0)
    21.                                 itemName +=" "+ cmd[i];
    22.                 }
    23.                 player.getPA().selfGamble(itemName, amount, 3);
    24.  
    The rest of it gets handled by the selfGamble method.

    A little sloppy. No documentation lol. Not tested either.
    Code: Java
    1.         publicvoid selfGamble(String itemName, int betAmount, int chance){
    2.                 int itemId = c.getItems().getInventoryItemIDByName(itemName);
    3.                 Misc.out("Item: "+ itemName +" id: "+ itemId +" has: "
    4.                                 + c.getItems().playerHasItem(itemName));
    5.                 boolean jackpot = Misc.random(10000)<3;
    6.  
    7.                 if(chance >100)
    8.                         return;
    9.  
    10.                 if(!c.getItems().playerHasItem(itemName)|| itemId <1){
    11.                         c.sendMessage("[Item Doubler] You need that item in order to bet it!");
    12.                         return;
    13.                 }
    14.  
    15.                 if(!c.getItems().playerHasItem(itemName, betAmount)){
    16.                         c.sendMessage("[Item Doubler] You need to have "
    17.                                         +(betAmount - c.getItems().getItemAmount(
    18.                                                         c.getItems().getInventoryItemIDByName(itemName)))
    19.                                         +" more to bet that high...");
    20.                        
    21.                         if(c.getItems().getItemAmount(itemName)<1)
    22.                                 return;
    23.                         else{
    24.                                 c.sendMessage("[Item Doubler] Setting bet amount to amount in inventory ("
    25.                                                 + c.getItems().getItemAmount(itemName)+")");
    26.                                 betAmount = c.getItems().getItemAmount(itemName);
    27.                         }
    28.  
    29.                 }
    30.                
    31.                 Item betItem =new Item(itemId, betAmount *2);
    32.                
    33.                 c.getItems().deleteItem(itemId, betAmount);
    34.                
    35.                 if(Misc.random(100)< chance){
    36.                         c.sendMessage("[Item Doubler] You won "+ betAmount +" "
    37.                                         + ItemAssistant.getItemName(itemId)+"!");
    38.                         c.getItems().addItem(betItem.getId(), betItem.getCount());
    39.                 }else{
    40.                         c.sendMessage("[Item Doubler] Unfortunatley, you lost "+ betAmount
    41.                                         +" "+ ItemAssistant.getItemName(itemId)+" :(");
    42.                         gambleList.add(betItem);
    43.                 }
    44.                
    45.                 if(jackpot){
    46.                         messageToAll(ClientColors.setShade(
    47.                                         ClientColors.BLACK,
    48.                                         ClientColors.setColor(ClientColors.RED, "[ITEM DOUBLER] "
    49.                                                         + c.playerName+" has just hit the jackpot!")));
    50.                         giveJackpot();
    51.                         c.sendMessage("Your jackpot items can be found in your bank.");
    52.                 }
    53.         }
    Edit 1:
    Did some very minor tests to make sure it worked. it removes the coins and if you win, it adds them * 2. Otherwise it adds the item to the jackpot.

    The jackpot was a feature I thought of. It needs more tuning so it doesn't become a sinkhole (a.k.a no one wins ever) and so it doesn't ruin the economy. Ex: 5000 players all put 5 party hats in. Player 5001 wins jackpot, now has 25000 party hats.

    Edit 2:
    You guys will have to do some modifications to the code above (obviously) to make it work. I'm not giving out any more xP.
    I used item names instead of item ids, because the players shouldn't have to remember all the item ids, and you shouldn't need to have them enabled for the players to see (disregarding that they can get it one way or another). You will also have to add a fix for the following scenarios:
    Player has 2 billion coins (exact) in inventory.
    Player bets all 2 billion coins.
    Player wins.
    Player won 4 billion coins, but cannot hold that.
    Player loses a total of 1852516353 coins because the max is 2147483647.
    (#2)
    Player has 2 billion coins.
    Player bets 1 billion coins.
    Player wins.
    Player gets 2 billion coins back.
    Player cannot hold the full 2 billion, as they have 1 billion already.
    Player loses a total of 852516353 coins because the max is 2147483647.

    Offlinemrnessie

    • Member
    • ****
    • Posts: 384
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #9 on: October 24, 2014, 07:17:38 PM »
    Exactly, and if you double the item that you bet, you'll get double that item's ID, correct?

    Yes


    And as for sk8rdude, dude you're putting more work into this then i did. But looks good. im still sticking with my work, as i like to code stuff myself.
    « Last Edit: October 24, 2014, 07:22:42 PM by mrnessie »
    need developers

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #10 on: October 24, 2014, 07:30:44 PM »
    Exactly, and if you double the item that you bet, you'll get double that item's ID, correct?

    Yes


    And as for sk8rdude, dude you're putting more work into this then i did. But looks good. im still sticking with my work, as i like to code stuff myself.
    That was 30 minutes of work at most.
    And add like 5 for fixing bugs.
    Note I was doing other things at the time as well.

    Offlinematzie

    • Member
    • ****
    • Posts: 1,006
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #11 on: November 25, 2014, 03:58:16 PM »
    rename your variables to be more descriptive.
    rename itemBet (the ID of the item you are betting) and you may see your problem.
    You never parse the the amount you want to bet. and yet you still assign it a value.

    look at these 2 lines, you may find the issue :/
    Quote from: Justin Bieber
    Also, I don't know how other people feel about this but personally I really dislike having to interact with community staff since they're usually kids with a pumped up sense of authority.
    Who its by XD

    OfflineVain_

    • Member
    • ****
    • Posts: 3,054
    • Thanks: +0/-0
      • View Profile
    Re: [PI]My Gamble Command
    « Reply #12 on: November 25, 2014, 04:59:38 PM »
    didn't read all the replies but op states 3/100 chance of winning (3%) but your checks don't append to *or equals too* simple lesser or greater than. which results in the only possible winning outcome being 2, which is only 1/100 (1%) chance to win.


    pretty nice work thought it can be improved drastically

     

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