Apps Home
|
Create an App
Number Guesser
Author:
lmpoye
Description
Source Code
Launch App
Current Users
Created by:
Lmpoye
var highest = ""; var highestAmnt = 0; var totalAmnt = 0; var latestAmnt = 0; var latest = ""; var tips = new Array(); cb.settings_choices = [{ "name": "correct_choice", "type": "int", "minValue": 1, "maxValue": 999999, "defaultValue": 69, "label": "The correct number to start a private show" }, { "name": "start_choice", "type": "int", "minValue": 1, "maxValue": 999999, "defaultValue": 1, "label": "The starting number in the game" }, { "name": "end_choice", "type": "int", "minValue": 1, "maxValue": 999999, "defaultValue": 200, "label": "The ending number in the game" }]; function startsWith(str, word) { return str.lastIndexOf(word, 0) === 0; } function shortenArray(array) { var ranges = [], rstart, rend; for (var i = 0; i < array.length; i++) { rstart = array[i]; rend = rstart; while (array[i + 1] - array[i] == 1) { rend = array[i + 1]; i++; } ranges.push(rstart == rend ? rstart + '' : rstart + '-' + rend); } return ranges; } cb.onMessage(function(msg) { if (startsWith(msg.m, "/tips")) { var keys = []; var mod = (msg.is_mod || msg.user === cb.room_slug); for (var k in tips) keys.push(k); if (mod && msg.m.substring(6, 9) == "all") { if (keys.length === 0) { cb.sendNotice("No numbers have been tipped so far.", "", "#FF3"); } else { cb.sendNotice("Tipped numbers:", "", "#FF3"); cb.sendNotice(shortenArray(keys).toString(), "", "#FF3"); } } else { if (keys.length === 0) { cb.sendNotice("No numbers have been tipped so far.", msg.user, "#FF3"); } else { cb.sendNotice("Tipped numbers:", msg.user, "#FF3"); cb.sendNotice(shortenArray(keys).toString(), msg.user, "#FF3"); } } msg["X-Spam"] = true; } return msg; }); cb.onDrawPanel(function(user) { var a = totalAmnt; var b; var c; if (highestAmnt != 0) { b = highest + "(" + highestAmnt + ")"; } else { b = ""; } if (latestAmnt != 0) { c = latest + "(" + latestAmnt + ")"; } else { c = ""; } return { "template": "3_rows_of_labels", "row1_label": "Total Tips:", "row1_value": a, "row2_label": "Highest Tip:", "row2_value": b, "row3_label": "Latest Tip Received:", "row3_value": c }; }); cb.onTip(function(tip) { var correct = cb.settings.correct_choice; var min = cb.settings.start_choice; var max = cb.settings.end_choice; var currentTip = parseInt(tip.amount); var found = false; cb.log("tipped " + currentTip); if (cb.limitCam_isRunning()) { if (currentTip == correct) { cb.limitCam_addUsers(tip.from_user); found = true; } } if (currentTip >= min && currentTip <= max) { cb.log("tip in range"); if (currentTip == correct) { cb.log("tip correct"); cb.sendNotice("Correct number tipped by: " + tip.from_user, "", "#CC3"); cb.sendNotice("Tip the same amount to join the show!", "", "#CC3"); cb.limitCam_start("A user has guessed the correct number!"); cb.limitCam_addUsers(tip.from_user); found = true; } if (!found) { if (tips[tip.amount] === undefined) { cb.log("new tip"); cb.sendNotice(tip.amount + " guessed by " + tip.from_user, "", "#FF3"); tips[tip.amount] = tip.from_user; } else { cb.log("old tip"); cb.sendNotice(tip.amount + " is already guessed by " + tips[tip.amount], "", "#CCC"); } } totalAmnt += currentTip; latestAmnt = currentTip; latest = tip.from_user; if (currentTip > highestAmnt) { highestAmnt = currentTip; highest = tip.from_user; } } cb.drawPanel(); });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.