|
DISCLAIMER!!!! NOT ALL DATA IS RELEASED YET!!!
ALSO I WROTE NON OF THIS CODE EXCEPT FOR THE EXAMPLE
The data that the OSRS Wiki team has been crowdsourcing has started to appear on the wiki which means we can take advantage of it and use it for our servers.
The way OSRS calculates your chance is by interpolating between a low and a high value using your current level to determine the chance.
So the higher your level the closer you are to the specified high chance value. Your chance at being successful will always be competed against a random number between 0 and 256.
So how do we find the low and high values? By scouting the wiki!Code:/** * Interpolates between a low chance and a high chance * * @Param level The player level * @Param lowChance The low chance value * @Param highChance The high chance value * @Return The interpolated value / chance */ public static int interpolate(int level, int lowChance, int highChance) { return lowChance + (highChance - lowChance) * (level - 1) / 98; }
Lets take the low and high chance value for harpooning sharks. (https://oldschool.runescape.wiki/w/Raw_shark) When arriving at the page it should by default look like something below.
Simply scroll down until you see:
The graph shows you the chance in percantage you have at harpooning a shark successfully from level 77 through 99, that's not what we're after through, we're after the low and high values, so click on the edit source button
You should at arrive at a page where you can eddit the source, simply look for the low and high values:
Low val: 3, high val: 40. So how do we use these numbers? Here's an example:
Code:/*The lowest chance val*/ val low = 3; /*The highest chance val*/ val high = 40; /*the players level*/ val level = 99; /*the interpolated chance*/ val chance = interpolate(level, low, high); /*The random number from 0 through 256 the chance val is competed against*/ val random = new Random().nextInt(256); /*if the chance val is higher than the random val, add raw shawk to inventory*/ if (chance >= random) { add(Item.RAW_SHARK, 1); }
Last edited by George; 01-14-2021 at 10:06 AM.
Keep up the good work
nice =]
Include the cascade function found on wikia as well please.
Cascade is used when multiple options are possible, for example when fishing shrimps and anchovies.Code:function interp(low, high, level) local value = math.modf(low*(99-level)/98) + math.modf(high*(level-1)/98) + 1 return math.min(math.max(value / 256, 0), 1) end function cascadeInterp(bounds, level, index) local rate = 1.0 for i, v in ipairs(bounds) do if i == index then rate = rate * interp(v.low, v.high, level) return rate end if level >= v.req then rate = rate * (1 - interp(v.low, v.high, level)) end end end
Despite shrimp success rate being 100% if you input the values into the interp func, it would still only cap out at 50% due to there being two possible options. Would hate to see servers get the interpolation right but miss out on the multiple option part.
Good release though!
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |