Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Used in my Discord bot. Free to be adapted to anyone's use. See https://bulbapedia.bulbagarden.net/wiki/Experience#Gain_formula for more info.
- function calculateXpGain(user,msg) {
- msg = msg.replace(/ /g,"");
- var charCount = msg.length;
- var xpBonus = Math.floor(Math.pow(charCount,1/3)); //Cube root of the message length (excluding spaces) Was giving thousands of XP for "test", hence the cube root :P
- if (xpBonus != 0) {
- var plrLevel = getLevel(user); //Returns an integer
- console.log("[DEBUG]: Base XP for this message: "+xpBonus)
- var gain = Math.floor(((((1*xpBonus*2)/(5*1))*(Math.pow((2*2+10),2.5)/(Math.pow((2+plrLevel+10),2.5)))+1)*1*1*1) //Actual formula. Feel free to remove the "*1"s, they are there for consistency to the actual formula.
- if (charCount < config.minMsgLen) {
- gain = Math.floor(gain/2); //If the message is less than the desired length, halve XP gain. (Default 10)
- }
- console.log("[DEBUG]: Total XP Gain for this message: "+gain+"XP");
- return gain;
- } else {
- return 0; //No reason to use extra CPU time calculating 0 lol
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment