Bots Home
|
Create an App
guess the number
Author:
playfull_mike
Description
Source Code
Launch Bot
Current Users
Created by:
Playfull_Mike
maxprize = 8; pz = 1; fNumber = parseInt(cb.settings['NoTF']); minchoice = parseInt(cb.settings['minrange']); maxchoice = parseInt(cb.settings['maxrange']); arr = []; msg =''; prize = 0; color = divide(cb.settings['txtcolor'],1); bkcolor= divide(cb.settings['txtcolor'],0); cb.settings_choices = [ {name:'tipvalue', type:'int', minValue:1, maxValue:400, required: true, label:'how many tokens to play', defaultValue:5}, {name:'msgtimer', type:'int', minValue:1, maxValue:400, required: true, label:'how many minutes to show the game', defaultValue:2}, {name:'txtcolor', type: 'str', minLength: 15, maxLength: 15, required: true, label:'normal text color(background color/text color) default: (#fdfdfd/#dd0011) ', defaultValue:'#fdfdfd/#dd0011'}, {name:'wincolor', type: 'str', minLength: 15, maxLength: 15, required: true, label:'winning text color (background color/text color) default: (#ccffeb/#006622) ', defaultValue:'#ccffeb/#006622'}, {name:'NoTF', type:'int', minValue:0, maxValue:999, required: true, label:'Number to find( 0 = random number)', defaultValue:0}, {name:'minrange', type:'int', minValue:0, maxValue:999, required: true, label:'Start of range value', defaultValue:1}, {name:'maxrange', type:'int', minValue:100, maxValue:999, required: true, label:'end of range value', defaultValue:200}, {name:'maxprize', type:'int', minValue:4, maxValue:8, required: true, label:'max prizes going to be used(min = 4 and max = '+ maxprize +') on the max prize will not need to guess a value. just text', defaultValue:5}, ]; for(var x = 1; x <= maxprize; x++) { if (x == 1) {prz = 'Top Prize';} else if (x == 2) {prz = '2ed prize';} else if (x == 2) {prz = '3rd prize';} else {prz = x +'th prize';} if(x < 5) {req = true;} else {req = false;} if(x < 4) {reqb = true;} else {reqb = false;} cb.settings_choices.push({name:'guess' + x, type:'int', minValue:1, maxValue:400, required: reqb, label:'max guesses for '+ prz}); cb.settings_choices.push({name:'prize' + x, type: 'str', minLength: 1, maxLength: 244, required: req, label:prz +' text'}); } function divide(s,v) { if (s) { res = s.split(/\//) [v]; return res;} else {return;} } function randNo(min, max) { minNo = parseInt(min); maxNo = parseInt(max); return Math.floor(Math.random() * (maxNo - minNo + 1)) + minNo; } function getClosest(hilow) { var num = result = 0; arr.sort(function(a, b){return a-b}); if ((arr.length == 0) && (hilow == 'L')) { result = minchoice;} else if ((arr.length == 0) && (hilow == 'H')) { result = maxchoice;} else{ result = ''; for(var i = 0; i < arr.length; i++) { num = parseInt(arr[i]); bnum = parseInt(arr[0]); if (hilow == "L") { if (bnum > fNumber) {result = minchoice; break;} else if(num <= fNumber) { result = num+1;} } else if (hilow == "H") { if((num < fNumber) | (num > maxchoice)) {result = maxchoice;} else if (num >= fNumber){ result = num-1; break;}} } } return result; } function checkNo(No) { ckresult = ''; No = parseInt(No); if (No != 0) { arr.push(No); } if ((No != fNumber) && (No != 0)){ ckresult = 'Guess (' + arr.length + ') Number chosen is: *' + No +'*. \n'; ckresult += 'Sorry you did not find the number please try again \n';} if ((getClosest('L')-1 == getClosest('H')+1) && (prize != 0)) { ckresult = "The Number has been found. please wait for the game to be reset! \n"; ckresult +="My number was: *" + fNumber +"*. \n"; ckresult += "The prize won was: *" + showprize() + "* .";} else if(No == fNumber) { ckresult = "Congratulations you found the my Number in " + arr.length + " tries..\n"; ckresult +="My number is: *" + fNumber +"*. \n"; ckresult += " YOU WON ***" + showprize() + "*** Enjoy and play again soon XXX.." } else if(getClosest('L') == getClosest('H')) {ckresult += "You have only got " + getClosest('L') + " left to choose! \n";} else {ckresult += "Choose a number between " + getClosest('L') + " & " + getClosest('H') + "\n";} if ((No != fNumber) && (No != 0) && (getClosest('L')-1 != getClosest('H')+1)) {ckresult += "The Next Prize is: *" + showprize('N') + "*.";} if ((No == 0) && (prize != 0)) {ckresult += "\n";} return ckresult; } function showgame() { if (fNumber == 0) {fNumber = randNo(minchoice, maxchoice); cb.sendNotice( cb.room_slug + " the number has been chosen for you is: " + fNumber + ".(only you can see this message)", cb.room_slug,'#ffffff', '#000000','normal'); } msg = '##### Find the Number game ##### \n'; msg += 'For this game will cost ' + cb.settings['tipvalue'] + ' tokens to play. \n'; msg += 'Just add your number in the tip note! \n'; msg += checkNo(0); if (getClosest('L')-1 != getClosest('H')+1) {msg += 'The Prize is *' + showprize('N') + '* If you guess correct \n';} msg += "Type !prize to see the list of prizes that you can win by guessing the number correct \n"; msg += "Type !setno with a number to start a new game (broadcaster only!!)\n"; msg += '############################'; cb.sendNotice(msg,'',divide(cb.settings['txtcolor'],0),divide(cb.settings['txtcolor'],1),'bold'); runtimer= cb.setTimeout(showgame,cb.settings['msgtimer']*60000); runtimer; } cb.onTip(function (tip) { tipped = parseInt(tip['amount']); tipmsg = parseInt(tip['message']); from_user = tip['from_user']; if ((tipped == cb.settings['tipvalue']) && (isNaN(tipmsg) == false)) { if (tipmsg <= maxchoice) {msg = checkNo(tipmsg); if ((tipmsg == fNumber) && (prize == 0)) {prize = arr.length; color = divide(cb.settings['wincolor'],1); bkcolor= divide(cb.settings['wincolor'],0); cb.cancelTimeout(runtimer);} else {color = divide(cb.settings['txtcolor'],1); bkcolor= divide(cb.settings['txtcolor'],0);} cb.sendNotice(msg,'',bkcolor, color,'bold'); } else {cb.sendNotice('The number you have chosen is above the max range for this game, it will not be entered!!',from_user,'#ffffff', '#000000','normal'); }} }); function showprize(f) { for(var x = 1; x <= maxprize; x++) { if (prize != 0) {arr2 = prize;} else {arr2 = arr.length;} if (f == 'N') {arrL = parseInt(arr2+1);} else {arrL = parseInt(arr2);} if (arrL <= parseInt(cb.settings['guess' + x])) {aa = cb.settings['prize' +x]; pz = x; break;} else if (maxprize == x) {aa = cb.settings['prize' + x];} } return aa; } function gameReset(setNo) { if (prize == 0) {cb.sendNotice('please wait until the game is finished!!!', cb.room_slug,'#ffffff', '#000000','normal'); return; } else { if (setNo) { fNumber = setNo;} else {fNumber = 0;} arr = []; prize = 0; cb.sendNotice(cb.room_slug + ' has chosen a new number','','#ffffff', '#000000','normal'); showgame();} } function showprizes(username) { note = "Available prizes if you guess the number correct:" for(var p = pz; p <= cb.settings['maxprize']; p++) { pguess = cb.settings['guess' + p]-arr.length; pp = p-1; eguess = cb.settings['guess' + pp]-arr.length+1; if (p < cb.settings['maxprize']) {note += '\n guess in ' + pguess + ' try\'s and win ***' + cb.settings['prize' + p] + ' ***';} else if (eguess >= arr.length) {note += '\n guess after '+ eguess + ' or more try\'s and win ***' + cb.settings['prize' + p] + ' ***';} else { note += '\n you have only got ***' + cb.settings['prize' + p] +'*** to win!!';} } cb.sendNotice(note,username,bkcolor, color,'bold'); } cb.onMessage(function (msg) { if (msg['m'].match(/!prize/i)) { msg['X-Spam'] = true; showprizes(msg['user']); } else if ((msg['m'].match(/!setno/i)) && (msg['user'] == cb.room_slug)) { msg['X-Spam'] = true; mg = msg['m'].replace(/!setno/i, ''); numb = parseInt(mg); chk = isNaN(numb); if (chk == false) { if (numb <= maxchoice) { gameReset(numb);} else { cb.sendNotice("please choose a number between " + minchoice + " & " + maxchoice + "." , cb.room_slug,'#ffffff', '#000000','normal'); } } else {gameReset(0);} } return msg; }); function checkgame() { if (fNumber > maxchoice) {prize = 999; cb.sendNotice("the game can not be started! Type !setno with a number: " + minchoice + " & " + maxchoice + " to start the game!" , cb.room_slug,'#ffffff', '#000000','normal');} else {showgame();};} checkgame()
© Copyright Chaturbate 2011- 2024. All Rights Reserved.