Random quality with alchemy

Discussion in 'Javascript/Plugin Support' started by omeg, Aug 15, 2019.

  1. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    Hello everybody !

    I'm planning to use Yanfly synthesis system(crafting) and i was wondering if a random quality can be applied on these items(weapon and armor) with a colour code in the name.

    For example the player need 20 iron ore to make 1 iron sword and after the crafting ,this could be a standard iron sword,a common iron sword(with more stats), a rare iron sword (with even more stats) etc..

    any ideas?Im just a rookie in coding so be clear with some examples,thats will help me a lot ^^
     
    #1
  2. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,076
    Likes Received:
    3,407
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA

    I've moved this thread to Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #2
  3. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    573
    Likes Received:
    148
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    it is possible, but it require alot of eventing and items of the same kind, you also need 1 other plugin to get this
    smoothly in motion.

    Each item (Iron Sword) with different stats, 1 with 10 att, 1 with 11 attack, 1 with 12 att etc etc
    the variable on that control the randomness.
    if you want 4 different attack, 4 different stats, you need to make over 16 items or more
    each with its own value and use the value variable to randomize those in the index of 1 through 16 when made.

    are you really sure you want to go into this? specially if you are new to rpg MV?
     
    #3
  4. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    Hello Shadow dragon ,

    To be more specific :
    I will create some category of stuff :wood for lv1-10 ,iron for lv 11-19 etc,in each category some type of weapon :one handed sword,2 handed sword,one handed axe,two handed axes etc
    And for every type of this weapon , rarity will be create with fixed stats:normal rarity 100% of stats,common 120% of stats etc

    My purpose is to randomize this rarity when crafting is done but there is only 5 rarity in my game.
    And yes I want to do that is its possible but i need some to explain me if possible ^^ The game would be greater with ;)
     
    #4
  5. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    573
    Likes Received:
    148
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    than there are 2 questions I would you to ask, do you want it fully event?
    or through a crafting plugin?

    (most crafting plugin doesn't allow randomize though) but eventing it can be time consuming.
    There is a game that allows crafting with items, but if this is the kind you want, you spend hours in making it.

    for a quick search, this LINK might come in handy, how it works, IDK, so read the post and helpfile.
     
    #5
  6. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    Ty for th tips ,will check it =)
     
    #6
  7. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    65
    Likes Received:
    47
    First Language:
    German
    Primarily Uses:
    RMMV
    If you use YEP_ItemCore aswell with independend weapons you could add something like this to your swords notebox:
    Code:
    <On Creation Eval>
    var factor = 1.0;
    var rarity = Math.randomInt(5);
    var textColor = 0;
    switch( rarity ) {
       case 0: break;
       case 1: factor = 1.2; textColor = 14; break;
       case 2: factor = 1.4; textColor = 6; break;
       case 3: factor = 1.6; textColor = 4; break;
       case 4: factor = 1.8; textColor = 3; break;
    }
    for( var i = 0; i < item.params.length; i++ )
    {
        item.params[i] = Math.round(item.params[i] * factor);
    }
    item.textColor = textColor;
    </On Creation Eval>
    But please note with this example all rareties are equally possible and the sword is created with a random rarety no matter how it is created.
    If you only want this to be done via synthesising I would suggest you to set a switch in your synthesising event and reset that switch afterwards
    and change the notetag like this while replacing the 1 with the id of your switch:

    Code:
    <On Creation Eval>
    if( $gameSwitches.value(1) === true )
    {
       var factor = 1.0;
       var rarity = Math.randomInt(5);
       var textColor = 0;
       switch( rarity ) {
          case 0: break;
          case 1: factor = 1.2; textColor = 14; break;
          case 2: factor = 1.4; textColor = 6; break;
          case 3: factor = 1.6; textColor = 4; break;
          case 4: factor = 1.8; textColor = 3; break;
       }
       for( var i = 0; i < item.params.length; i++ )
       {
          item.params[i] = Math.round(item.params[i] * factor);
       }
       item.textColor = textColor;
    }
    </On Creation Eval>
    If you want the rarety to be unequaly distributed you could for example do something like this:

    Code:
    <On Creation Eval>
    if( $gameSwitches.value(1) === true )
    {
       var factor = 1.0;
       var rarity = (Math.randomInt(5) * Math.randomInt(5)) / 4;
       var textColor = 0;
       switch( rarity ) {
          case 0: break;
          case 1: factor = 1.2; textColor = 14; break;
          case 2: factor = 1.4; textColor = 6; break;
          case 3: factor = 1.6; textColor = 4; break;
          case 4: factor = 1.8; textColor = 3; break;
          default: throw new Error("Should not happend!");
       }
       for( var i = 0; i < item.params.length; i++ )
       {
          item.params[i] = Math.round(item.params[i] * factor);
       }
       item.textColor = textColor;
    }
    </On Creation Eval>
    With this
    Rarety 0 has a 50%,
    Rarety 1 has a 25%,
    Rarety 2 has a 15%,
    Rarety 3 has a 10% and
    Rarety 4 has a mere 5% chance
    to happen.

    Wow I completely miscalculated the chances with this (even with a 105% in the sum), they are actually worse:
    Rarety 0 has a 56%,
    Rarety 1 has a 20%,
    Rarety 2 has a 12%,
    Rarety 3 has a 8% and
    Rarety 4 has a mere 4% chance
    to happen.
     
    Last edited: Aug 17, 2019
    #7
    ShadowDragon likes this.
  8. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    Oh Very nice Dude ,that's help me a lot ^^
    But what is the switch for?Because the start of synthesis will be through a command plugin not an event ,i don't get it ^^
     
    #8
  9. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    573
    Likes Received:
    148
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    @omeg there are ways to make rarities in some ways.
    like BurnaOrca said, if you want it only through synthesis, you can use a SWITCH so it only happen than,
    if you want it also accure on different ways, you can drop the switch, but it will apply to all crafting parts.
     
    #9
  10. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    So if i only want to use rarity at random for the synthesis menu(through the plugin command opensynthesis) i just have to paste this code on every item made through synthesis?


    Code:
    <On Creation Eval>
    if( $gameSwitches.value(1) === true )
    {
    var factor = 1.0;
    var rarity = (Math.randomInt(5) * Math.randomInt(5)) / 4;
    var textColor = 0;
    switch( rarity ) {
    case 0: break;
    case 1: factor = 1.2; textColor = 14; break;
    case 2: factor = 1.4; textColor = 6; break;
    case 3: factor = 1.6; textColor = 4; break;
    case 4: factor = 1.8; textColor = 3; break;
    default: throw new Error("Should not happend!");
    }
    for( var i = 0; i < item.params.length; i++ )
    {
    item.params = Math.round(item.params * factor);
    }
    item.textColor = textColor;
    }
    </On Creation Eval>


    Sorry for asking a lot of thing but im new a java ,so i <an to be sure of what i learn =p
     
    #10
  11. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    573
    Likes Received:
    148
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Keep it mind its not "java" but "javascript" those are compleetly different, make no misstake.

    Javascript (.js) is used for creating plugin as well for scritping in MV for calls and other things.
    but everyone learns more as they go deeper and go slightly different ways ^^

    But to your answer, yes. you can try to use factor 1.5 if you want a bit higher chance, but you have to test it out.
     
    #11
  12. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    @ShadowDragon yeah my mistake about java ^^I need to learn so much but some thing are incomprehensible for now ^^

    @BurningOrca What is the formula for calculate the rate? =)
    After this i will try and send feed back =)
     
    #12
  13. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    573
    Likes Received:
    148
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    I think that var factor 1.0 = chance rate, 1.0 = 100%
    so the 5 changes are calculated though that.

    So if you make it 1.5 than you start with 150%, make it 2.0 and you start with 200%, and the 5 calculate through those.
    however you make it is up to you.

    factor of 0.5 = 50% starting point if you want a heavy rare item hard to build ^^
     
    #13
  14. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    Ah yes indeed i try some calculation myself and get the same than burning orca^^
    Ty a lot for your help both of you =)
     
    #14
    ShadowDragon likes this.
  15. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    65
    Likes Received:
    47
    First Language:
    German
    Primarily Uses:
    RMMV
    I meant setting the switch before calling the plugin command and resetting the switch after calling the plugin command, if you only want it for synsthesis.
    In my case I used switch 1, thats why I check ($gameSwitches.value(1)). If you want to use a different switch replace the 1 by the id.

    And No var factor = 1.0 is how much the items stats increases for the rarety.
    So 1.0 means no increase
    1.2 means 20% increase
    1.4 means 40% increase an so on.

    And I had a mistake, the actual code needs to be:
    Code:
    <On Creation Eval>
    if( $gameSwitches.value(1) === true )
    {
       var factor = 1.0;
       var rarity = Math.floor((Math.randomInt(5) * Math.randomInt(5)) / 4);
       var textColor = 0;
       switch( rarity ) {
          case 0: break;
          case 1: factor = 1.2; textColor = 14; break;
          case 2: factor = 1.4; textColor = 6; break;
          case 3: factor = 1.6; textColor = 4; break;
          case 4: factor = 1.8; textColor = 3; break;
       }
       for( var i = 0; i < item.params.length; i++ )
       {
          item.params[i] = Math.round(item.params[i] * factor);
       }
       item.textColor = textColor;
    }
    </On Creation Eval>
    For text colors you may use the index of the color you like.

    For calculating the chance of each rarity I simply went through all possible combination for the formula
    Math.floor((Math.randomInt(5) * Math.randomInt(5)) / 4);
    and devided it by the maximum possibilities.

    Math.randomInt(5) returns a random number from a range of 0 to 4.
    multiplying this by another random number from same range and deviding the result by the maximum, which is 4 and after rounding it down,
    gives 25 possible combinations,
    while 14 give the result 0 (56%)
    and 5 give the result 1 (20%)
    and 3 give the result 2 (12%)
    and 2 give the result 3 (8%)
    and 1 gives the result 4 (4%) (only 4 x 4 / 4 = 4).

    Just one example 3 x 3 = 9 / 4 = 2.25 rounded down = 2.

    This seems to really work like this, I tested it twice.
    1st: I crafted 60 swords and got 1 of the highest rarity. (4% would be 2-3).
    2nd: I crafted 100 swords and got 4 of the highest rarity. (This is exactly 4 percent).

    You could also replace Math.floor around the rarety formula by Math.round to round mathematically instead of always down. This doesn't change the percentages for rarity 3 and 4, but makes rarety 0 less likely and rarety 1 and 2 more likely:
    10 combinations will then give 0 (40%)
    7 combinations will then give 1 (28%)
    5 combinations will then give 2 (20%)
    still 2 will give the result 3 (8%)
    and 1 will give the result 4 (4%)

    I am just curious, why do you want to randomize the result of the synthesis and why do you think this will make the game better?
     
    Last edited: Aug 17, 2019
    #15
    ShadowDragon likes this.
  16. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    So if i want rarity with these parameters, i just need to create only one weapon (same name but color will be different depending on the color code used?)and enter this command ?
     
    Last edited: Aug 17, 2019
    #16
  17. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    65
    Likes Received:
    47
    First Language:
    German
    Primarily Uses:
    RMMV
    Yes exactly.
     
    #17
  18. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    yep tested and functionnal =) You save my life today^^

    So for coloring text i can use this format: #777777 or RBG code (x,x,x) ?

    And last question Is possible to add effect to weapon depending on the rarity?

    For exemple if weapon is rarity 4 ,the weapon will add a firespell to the hero skill?
    Same question for add other stats like defense ,a buff state etc^^
     
    Last edited: Aug 17, 2019
    #18
  19. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    573
    Likes Received:
    148
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    @omeg, the text color is the color pallete on your window.png lower right corner


    it start with 0, 1 ,2 ,3, 4, 5, 6, 7, 8 _. through 32 if not mistaken or 31.
    so you use this number to color it.
     
    #19
  20. omeg

    omeg Veteran Veteran

    Messages:
    46
    Likes Received:
    3
    First Language:
    french
    Primarily Uses:
    RMMV
    Oh ty for the info ,found it after some research ^^ Will give i try now =)
     
    #20

Share This Page