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?