Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @author=Cicco23 */
- /*
- Parameters:
- > u = $(user);
- > qs = $(query);
- > str = "";
- > win = false;
- */
- /*Clear ueless spaces ("%20")*/
- function trimmer(x){
- x = x.trim();
- while(x.startsWith("%20")){
- x=x.replace("%20","");
- }
- return x.trim();
- }
- /*Function to complete "o" or "e" into "odd" or "even"*/
- function complete(x){
- if(x=="o" || x=="odd") return "odd";
- else return "even";
- }
- /*Function to swap "odd" into "even", and vice versa.*/
- function swap(x){
- if(x=="o" || x=="odd") return "even";
- else return "odd";
- }
- /*If player doesn't bet, Nightbot will bet, instead.. This function turns a random number into "odd" or "even". */
- function nbSel(){
- var x = Math.random()*100;
- if(x<50) return "odd";
- else return "even";
- }
- /*Clear the "%20" space bug*/
- qs = trimmer(qs);
- /*q -> string array of qs (querystring).*/
- var q = qs.split(" ");
- /*This flag is needed to check if the player has done a valid bet or not.*/
- var flag = false;
- /*num is the number the user picked.*/
- var num = 0;
- /*bet is the user's bet ("odd" or "even").*/
- var bet = "";
- /*nbNum is the random number Nightbot wants to pick. He'll pick a number between 1 and 100.*/
- var nbNum = Math.random()*100;
- nbNum = Math.floor(nbNum)+1;
- /*Nightbot waits for a valid bet from the player.*/
- var nbBet = "";
- /*The fundamental string.*/
- var str = "";
- /*The final number, will be the sum between the player's number and Nightbot's number.*/
- var sum = 0;
- /*If the first element of the query is NOT a number, it's an error.*/
- 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\"] .";
- else {
- num = parseInt(Math.round(q[0]));
- num = Math.abs(num);
- /*Checking if the user has made a bet, and if it's valid.*/
- if(q.length>1){
- bet = q[1].toLowerCase();
- flag = bet=="o" || bet=="e" || bet=="odd" || bet=="even";
- }
- if(!flag){
- nbBet = nbSel();
- bet = swap(nbBet);
- str = "Nightbot bets for "+nbBet.toUpperCase()+" so you'll win only if the final number is "+bet.toUpperCase()+" .";
- }
- else{
- bet = complete(bet);
- nbBet = swap(bet);
- str = "You bet for "+bet.toUpperCase()+" , so Nightbot bets for "+nbBet.toUpperCase();
- }
- sum = num + nbNum;
- str = str+"\t Your number is "+num+" , Nightbot's number is "+nbNum+" , and the result is: "+sum;
- if(bet=="odd") win = (sum%2)!=0;
- else win = (sum%2)==0;
- /* TESTING */
- /* str = "Hai inserito \" "+qs+" \"\t"+str;*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement