Bots Home
|
Create an App
FoxyHP
Author:
testing1010
Description
Source Code
Launch Bot
Current Users
Created by:
Testing1010
cb.settings_choices = [ {name: 'game_state', type: 'str', defaultValue: '', required: false}, {name: 'golden_snitch', type: 'int', required: true} ] let gamestate = { hufflepuff: { members: {}, points: 0 }, gryffindor: { members: {}, points: 0 }, slytherin:{ members: {}, points: 0 }, ravenclaw:{ members: {}, points: 0 }, muggles: { members: {}, points: 0 } }; let settingsState = cb.settings.game_state; let settingsSnitch = cb.settings.golden_snitch; if(settingsState && settingsState !== ''){ gamestate = JSON.parse(settingsState); } cb.onTip((tip) => { let amount = parseInt(tip.amount); let user = tip.from_user; let house = isInHouse(user); switch(amount){ case 942: allowedToJoinHouse(user, house); break; case 222: learnSpell(user, house); break; case 469: learnPotion(user, house); break; case 711: learnCharm(user, house); break; case settingsSnitch: catchSnitch(user, house, amount); break; case 111: catchTrain(user, house); break; } }); cb.onMessage((msg) => { let txt = msg.m; let user = msg.user; let house = isInHouse(user); let command = txt.split(' ') // '/joinhouse hufflepuff' = ['/joinhouse', 'hufflepuff'] switch(command[0]){ case '/joinhouse': joinHouse(user, house, command[1]); msg['X-Spam'] = true; break; case '/save': saveState(user); msg['X-Spam'] = true; break; case '/givepoints': givePoints(command[1], command[2]); break; case '/addhouse': addToHouse(command[1], command[2]); break; case '/points': if (user === cb.room_slug){ cb.sendNotice(`Gryffindor: ${gamestate.gryffindor.points}, Hufflepuff: ${gamestate.hufflepuff.points}, Ravenclaw: ${gamestate.ravenclaw.points}, Slytherin: ${gamestate.slytherin.points}`); } else{ cb.sendNotice(`Gryffindor: ${gamestate.gryffindor.points}, Hufflepuff: ${gamestate.hufflepuff.points}, Ravenclaw: ${gamestate.ravenclaw.points}, Slytherin: ${gamestate.slytherin.points}`, user); } msg['X-Spam'] = true; break; } if(house){ msg.m = `[${caps(house)}] ${txt}`; } return msg; }); function caps(string) { return string.charAt(0).toUpperCase() + string.slice(1); } function givePoints(user, points){ if(user === cb.room_slug){ } } function addToHouse(user, house){ if(user === cb.room_slug){ } } function saveState(user){ if(user === cb.room_slug){ let state = JSON.stringify(gamestate); cb.sendNotice(state, cb.room_slug); } } function allowedToJoinHouse(user, house){ if(!house){ gamestate.muggles.members[user] = {points: 50, trainAttempts: 0}; cb.sendNotice(`You can now join a house, use the command '/joinhouse HOUSE' to join. ravenclaw, slytherin, gryffindor or hufflepuff`, user); } else { cb.sendNotice(`You are already in house ${house}`, user); } } function joinHouse(user, currentHouse, houseToJoin){ if(currentHouse === 'muggles'){ if(gamestate[houseToJoin]){ gamestate[houseToJoin].members[user] = gamestate.muggles.members[user]; gamestate[houseToJoin].points += gamestate.muggles.members[user].points; cb.sendNotice(`${user} joined house ${houseToJoin}! They brought ${gamestate.muggles.members[user].points} points with them!`); delete gamestate.muggles.members[user]; } else { cb.sendNotice(`${houseToJoin} is not a valid house`, user); } } else if(!currentHouse){ cb.sendNotice(`You can't join a house yet, tip 942 tokens to choose your house!`, user); } else { cb.sendNotice(`You are already in house ${currentHouse}`, user); } } function catchTrain(user, house){ if(!house){ cb.sendNotice(`You can't catch the train until you join a house`, user); } else { gamestate[house].members[user].trainAttempts++; if(gamestate[house].members[user].trainAttempts === 3){ cb.sendNotice(`You caught your train!`, user); gamestate[house].points += 25; gamestate[house].members[user].points += 25; cb.sendNotice(`${user} earned 25 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } else if(gamestate[house].members[user].trainAttempts < 3) { let tries = 3 - gamestate[house].members[user].trainAttempts; cb.sendNotice(`You almost caught your train! Tip 111 tokens ${tries} more ${tries === 1 ? 'time' : 'times'} to catch the train!`, user); } } } function learnSpell(user, house){ if(!house){ cb.sendNotice(`You can't learn a spell until you join a house`, user); } else { let num = randNumber(1, 100); if(num >= 30){ gamestate[house].points += 20; gamestate[house].members[user].points += 20 cb.sendNotice(`${user} learned a spell and earned 20 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } else { gamestate[house].points -= 20; gamestate[house].members[user].points -= 20 cb.sendNotice(`${user} failed to learn a spell and lost 20 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } } } function learnPotion(user, house){ if(!house){ cb.sendNotice(`You can't learn a potion until you join a house`, user); } else { let num = randNumber(1, 100); if(num >= 30){ gamestate[house].points += 60; gamestate[house].members[user].points += 60 cb.sendNotice(`${user} learned a potion and earned 60 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } else { gamestate[house].points -= 60; gamestate[house].members[user].points -= 60 cb.sendNotice(`${user} failed to learn a potion and lost 60 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } } } function learnCharm(user, house){ if(!house){ cb.sendNotice(`You can't learn a charm until you join a house`, user); } else { let num = randNumber(1, 100); if(num >= 30){ gamestate[house].points += 80; gamestate[house].members[user].points += 80 cb.sendNotice(`${user} learned a charm and earned 80 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } else { gamestate[house].points -= 80; gamestate[house].members[user].points -= 80 cb.sendNotice(`${user} failed to learn a charm and lost 80 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); } } } function catchSnitch(user, house, amount){ cb.sendNotice(`${user} caught the golden snitch! The lucky number was ${settingsSnitch}. They earned 500 points for ${house}!`, null, '#ffd700', '#000000', 'bold'); gamestate[house].points += 500; gamestate[house].members[user].points += 500 settingsSnitch = null; } function randNumber(min, max){ return Math.random() * (max - min) + min; } function isInHouse(user){ let house = null; for(let h in gamestate){ if(gamestate[h].members[user]){ house = h break; } } return house; }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.