Bots Home
|
Create an App
testdice
Author:
cryptojunkie
Description
Source Code
Launch Bot
Current Users
Created by:
Cryptojunkie
// Paradice Timer v 0.0.0 /* I'm going for readability on this one, for example: "incepted" arrays will be declared as new Array([]), not [[]] (even though I think the later looks cooler). So, hopefully: 1. CB Api Functions and Event Handlers 2. Helper Functions 3. "Loose" code */ // cb settings cb.settings_choices = [ {name:'optionsString', type:'str', minLength:1, maxLength:999, defaultValue:"", label: "List of prizes separated by a | (usually located above the enter key), example: Dancing|Stripping|Singing"}, {name:'amountToRoll', type:'int', minValue:1, defaultValue:25, label: "Tip amount required to roll"}, {name:'timePerRoll', type:'int', minValue:1, defaultValue:30, label: "How long, in seconds, will each prize last"}, {name:'chance', type:'int', minValue:1, defaultValue:25, label: "Chance for tip to be a winner (out of 100)"} ]; // Set the options and other variables var refreshInterval = 500; var increaseIncrement; var colorArray = ["#DBF5D1", "#33ABF9", "#BD7AF6", "#FF3BC5"]; // Parse the options, create some arrays var bigArray = []; var timeArray; var hasSetup = false; function setup() { // Set the options increaseIncrement = cb.settings.timePerRoll * 1000; // Parse the options, create some arrays var tempOptionsArray = cb.settings.optionsString.split("|"); for (var i = 0; i < tempOptionsArray.length; i++) { bigArray.push({ index: i, desc: tempOptionsArray[i], startedBy: "", lastQueuedBy: "", color: colorArray[Math.floor(Math.random() * colorArray.length)], time: 0 }); } resetTimeArray(); // Start the interval cb.setTimeout(timer, refreshInterval); } cb.onTip(function (tip) { if (!hasSetup) { setup(); hasSetup = true; } if (tip["amount"] != cb.settings.amountToRoll) { return; } // Did they win? var d = Math.random(); if (Math.random() > (cb.settings.chance / 100)) { return; } // And the roll... var index = Math.floor(Math.random() * bigArray.length); cb.sendNotice("We have a winner folks...", "", "#00FF00", "", "bolder", ""); cb.sendNotice(tip["from_user"] + " has rolled " + bigArray[index].desc + " for " + cb.settings.timePerRoll + " seconds!", "", bigArray[index].color, "", "bolder", ""); //cb.sendNotice("***ATTENTION***\n" + tip["from_user"] + " has tipped " + cb.settings.amountToRoll + " for " + optionsArray[index], cb.room_slug, "#FF0000", "", "bolder", ""); if (bigArray[index].time == 0) { bigArray[index].time = getTime() + increaseIncrement } else { bigArray[index].time += increaseIncrement; } }); function timer() { //cb.log("Running timer"); for (var i = 0; i < bigArray.length; i++) { if (bigArray[i].time != 0 && (bigArray[i].time < getTime() + refreshInterval / 2 && bigArray[i].time > getTime() - refreshInterval / 2)) { cb.sendNotice("Alright, times up for " + bigArray[i].desc + ".\nThanks again tippers, and remember that only you can keep the party going :)", "", bigArray[i].color, "", "bolder", ""); //cb.sendNotice("***ATTENTION***\n" + "Fhew, the timer for " + optionsArray[i] + " has expired.", cb.room_slug, "#FF0000", "", "bolder", ""); bigArray[i].time = 0; } if (bigArray[i].time != 0 && (bigArray[i].time - 15000 < getTime() + refreshInterval / 2 && bigArray[i].time - 15000 > getTime() - refreshInterval / 2)) { cb.sendNotice("15 seconds left for " + bigArray[i].desc + ".\nRoll those dice if you want some more :)", "", bigArray[i].color, "", "bolder", ""); //cb.sendNotice("***ATTENTION***\n" + "There are only 15 seconds remaining for " + optionsArray[i], cb.room_slug, "#FF0000", "", "bolder", ""); } } cb.setTimeout(timer, refreshInterval); } function resetTimeArray() { for (var i = 0; i < bigArray.length; i++) { bigArray[i].time = 0; } } function getTime() { var d = new Date(); return d.getTime(); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.