callfunc( "F_Rand", "Hi, how are you ?", "Hi, how do you do ?" )
callfunc( "F_Rand", 1101, 1201, 1501 )
etc..
Sample:
prontera,153,180,5 script test item reward#1 100,{
getitem callfunc("F_Rand",501,502,503,504,505),1;end;}
Method 2: use temporary variables
Tips:
Create a temporary variable with the total chance added up.
Then utilizing chain of if...else-if condition sort them from lowest chance to highest chances. The chance are added from previous conditions ---> condition 1, 1+2, 1+2+3, 1+2+3+4, ...
Use else for last statement
Sample:
prontera,155,180,5 script test item reward#2 100,{.@rand= rand(1+2+3+4+5+5+10+15);// rand Total => 45if(.@rand<1)// 1/45 chance getting 10 knifes
getitem 1201,10;elseif(.@rand<1+2)// 2/45 chance getting 5 knifes
getitem 1201,5;elseif(.@rand<1+2+3)// 3/45 chance getting 2 knifes
getitem 1201,2;elseif(.@rand<1+2+3+4)// 4/45 chance getting 1 knifes
getitem 1201,1;elseif(.@rand<1+2+3+4+5)// 5/45 chance getting 10 red pots
getitem 501,10;elseif(.@rand<1+2+3+4+5+5)// 5/45 chance getting 5 red pots
getitem 501,5;elseif(.@rand<1+2+3+4+5+5+10)// 10/45 chance getting 2 red pots
getitem 501,2;// else if ( .@rand < 1+2+3+4+5+5+10+15 ) // use else for last statementelse// 15/45 chance getting 1 red pot
getitem 501,1;end;}
Method 3: use array
Tips:
Create a preset of array (itemID array and chance array) under OnInit label. The total of itemID array and chance array should have same amount of indexes. Then total them with with another variable (.totalchance).
For the chances : set a random value from .totalchance, then search through the .itemchance array. With every .itemchance value searched, .@rand variable getting deducted. When .@rand less than 0 the loop is breaked : you get an index(.@i) for itemID array.
(Skorm edit: I'd like to add that in this example unless all item chances add-up to 100 .itemchance doesn't exactly represent a percent. In this example by Annie '3' is actually ~3.6% or 3/83. )
sigh ... I seriously need someone to make the english better, my explanation always sux
any staff member here feels like can make this topic better, please do so
Question
AnnieRuru
I make a continuation of this topic
this topic mainly concern about unpopular but useful scripting techniques ...
should wiki this up someday
Randomize item reward
Method 1: use F_Rand function
The function:
F_Rand can be found in our Git repository, Global Function
This function is indeed to be use for randomize a selection.
Usage:
callfunc( "F_Rand", <argument no.1>, <argument no.2> ... )
callfunc( "F_Rand", "Hi, how are you ?", "Hi, how do you do ?" )
callfunc( "F_Rand", 1101, 1201, 1501 )
etc..
Sample:
Method 2: use temporary variables
Tips:
Sample:
Method 3: use array
Tips:
(Skorm edit: I'd like to add that in this example unless all item chances add-up to 100 .itemchance doesn't exactly represent a percent. In this example by Annie '3' is actually ~3.6% or 3/83. )
Sample:
sigh ... I seriously need someone to make the english better, my explanation always sux
any staff member here feels like can make this topic better, please do so
Link to comment
Share on other sites
2 answers to this question
Recommended Posts