[Help]Using Math.Random

Results 1 to 7 of 7
  1. #1
    Zaytron is offline
    MemberRank
    Nov 2012 Join Date
    320Posts

    [Help]Using Math.Random

    Does anyone know if RZ have a full guide on how to use math.random ?
    I've searched and saw Shawn's but I can't really understand on how to use it.

    I'm working on something like using math.random to make a NPC 'scroll' that certain item & it has 30% chance of failure. Upon failure item is destroyed.

    For destroying the item , I've dug out a function from VindicatedStory source. Please do let me know if this function won't work for what I'm trying to do.
    public void removeEquipFromSlot(int slot) {
    MapleInventoryManipulator.removeFromSlot(getClient(), MapleInventoryType.EQUIP, (short) slot, (short) 1, false);
    }


  2. #2
    Omega sunnyboy is offline
    MemberRank
    Mar 2010 Join Date
    6,108Posts

    Re: [Help]Using Math.Random

    Quote Originally Posted by Zaytron View Post
    Does anyone know if RZ have a full guide on how to use math.random ? .
    http://lmgtfy.com/?q=math.random+java

  3. #3
    Member Elyssium is offline
    MemberRank
    Mar 2014 Join Date
    90Posts

    Re: [Help]Using Math.Random

    Well. I think it's pretty hard to learn from what sunnyboy have provided.

    I'm currently learning bout math.random too , try this link :
    http://forum.ragezone.com/f427/odin-...chance-433416/

    It's much more clearer ( for me I guess ) , I'm not so sure if that function will work though.

  4. #4
    Omega sunnyboy is offline
    MemberRank
    Mar 2010 Join Date
    6,108Posts

    Re: [Help]Using Math.Random

    It's not very complicated, if you know math and have common sense to understand / google about it a bit; ull be fine. It's not like it's some class specifically for maple lol

  5. #5
    Member Elyssium is offline
    MemberRank
    Mar 2014 Join Date
    90Posts

    Re: [Help]Using Math.Random

    Yea true. I thought maybe giving him some real examples of how it's used might help him alittle more. ( Or maybe it's just me ? lolol )

    - - - Updated - - -

    Here's a rough guide ( DO NOT FLAME ) , I'm not a pro in math.random too so I figured

    why not just do :
    var rand = 1 + Math.floor(Math.random() * 10);

    this will allow us to use :
    if (rand == 1) { to if (rand == 10) {

    So let's say , I want the NPC to say cm.sendOk("Hi"); & the chances of it saying hi is one out of ten.

    So , basically just do
    if (rand == 1) all the way to if (rand == 9)

    & make it not say Hi but on the "if (rand == 10)" time , you make it say hi.

    I just came up with it in my own way .. i mean if you're gonna do like ... 1 in 100 then I'm not sure on how.

  6. #6
    Zaytron is offline
    MemberRank
    Nov 2012 Join Date
    320Posts

    Re: [Help]Using Math.Random

    Thank you so much.

  7. #7
    Valued Member KayVan is offline
    MemberRank
    May 2013 Join Date
    126Posts

    Re: [Help]Using Math.Random

    Quote Originally Posted by Elyssium View Post
    if (rand == 1) all the way to if (rand == 9)
    if (rand >= 1 && rand <= 9)



Advertisement