SHARE
TWEET

oddeven.js

Cicco23 May 19th, 2019 (edited) 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** @author=Cicco23 */
  2. /*
  3. Parameters:
  4. > u = $(user);
  5. > qs = $(query);
  6. > str = "";
  7. > win = false;
  8. */
  9. /*Clear ueless spaces ("%20")*/
  10. function trimmer(x){
  11.     x = x.trim();
  12.     while(x.startsWith("%20")){
  13.         x=x.replace("%20","");
  14.     }
  15.     return x.trim();
  16. }
  17. /*Function to complete "o" or "e" into "odd" or "even"*/
  18. function complete(x){
  19.     if(x=="o" || x=="odd") return "odd";
  20.     else return "even";
  21. }
  22. /*Function to swap "odd" into "even", and vice versa.*/
  23. function swap(x){
  24.     if(x=="o" || x=="odd") return "even";
  25.     else return "odd";
  26. }
  27. /*If player doesn't bet, Nightbot will bet, instead.. This function turns a random number into "odd" or "even". */
  28. function nbSel(){
  29.     var x = Math.random()*100;
  30.     if(x<50) return "odd";
  31.     else return "even";
  32. }
  33. /*Clear the "%20" space bug*/
  34. qs = trimmer(qs);
  35. /*q -> string array of qs (querystring).*/
  36. var q = qs.split(" ");
  37. /*This flag is needed to check if the player has done a valid bet or not.*/
  38. var flag = false;
  39. /*num is the number the user picked.*/
  40. var num = 0;
  41. /*bet is the user's bet ("odd" or "even").*/
  42. var bet = "";
  43. /*nbNum is the random number Nightbot wants to pick. He'll pick a number between 1 and 100.*/
  44. var nbNum = Math.random()*100;
  45. nbNum = Math.floor(nbNum)+1;
  46. /*Nightbot waits for a valid bet from the player.*/
  47. var nbBet = "";
  48. /*The fundamental string.*/
  49. var str = "";
  50. /*The final number, will be the sum between the player's number and Nightbot's number.*/
  51. var sum = 0;
  52. /*If the first element of the query is NOT a number, it's an error.*/
  53. if(isNaN(q[0])) "\" "+q[0]+" \" is NOT a number. Try again with a number between 0 and 100, next time! (correct sintax: !oddeven [number], or !oddeven [number] [\"odd\"/\"even\"] or !oddeven [number] [\"o\"/\"e\"] .";
  54. else {
  55.     num = parseInt(Math.round(q[0]));
  56.     num = Math.abs(num);
  57. /*Checking if the user has made a bet, and if it's valid.*/
  58.     if(q.length>1){
  59.         bet = q[1].toLowerCase();
  60.         flag = bet=="o" || bet=="e" || bet=="odd" || bet=="even";
  61.     }
  62.     if(!flag){
  63.         nbBet = nbSel();
  64.         bet = swap(nbBet);
  65.         str = "Nightbot bets for "+nbBet.toUpperCase()+" so you'll win only if the final number is "+bet.toUpperCase()+" .";
  66.     }
  67.     else{
  68.         bet = complete(bet);
  69.         nbBet = swap(bet);
  70.         str = "You bet for "+bet.toUpperCase()+" , so Nightbot bets for "+nbBet.toUpperCase();
  71.     }
  72.     sum = num + nbNum;
  73.     str = str+"\t Your number is "+num+" , Nightbot's number is "+nbNum+" , and the result is: "+sum;
  74.     if(bet=="odd") win = (sum%2)!=0;
  75.     else win = (sum%2)==0;
  76. /* TESTING */
  77. /*  str = "Hai inserito \" "+qs+" \"\t"+str;*/
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top