Petals Around the Rose


#1

So, I’m absolute sugar honey iced tea when it comes to JS. I just need some help with this, please.

I want a script to run when a timer calls !petals as a command.
It will roll five dice and show the individual values.
It will then scrap all even values, then subtract one from each odd value.
Users will then guess the sum of this new set of values. Possible answers should be exclusive to even numbers from 0 through 20.
Users’ guess input should use !guess
After a short timer (I’m thinking 60 seconds) the correct answer should be revealed and correct users should be awarded an arbitrary amount of currency.

I’ve built this in C# as a console app, and these are essentially the steps I have used for that version. LMK if you’d like to see that code for reference. Big thanks to anyone and everyone who tries to help.


I can’t upload a file with the code because I’m new here. The C# code will be in the 4th reply below.


#2

I’d love to take a crack at this, if you want to post the code I can try and “convert” it.


#3

I would also like to see this, would be fun I think.

Oh gods, I spent so long working this puzzle out originally.


#4

Great! I’ll edit the original post with my cs file when I get home from work. Thanks!


#5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Petals
{
    class Score
    {
        public int score = 0;
    }
    class Die
    {
        public int Roll(int x)
        {
            Random face = new Random();
            int value = face.Next(0, 600);
            return (value%x) + 1;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            bool play = true;
            Score Points = new Score();
            Score Streak = new Score();
            while (play)
            {
                int value1 = 0;
                int value2 = 0;
                int value3 = 0;
                int value4 = 0;
                int value5 = 0;

            Die Dice = new Petals.Die();
            Console.WriteLine("Petals Around the Rose");
            Console.WriteLine();
            Console.WriteLine("I can tell you three rules. You have to figure out the rest.");
            Console.WriteLine("1. The name of the game is Petals Around the Rose.");
            Console.WriteLine("2. The name of the game is very important.");
            Console.WriteLine("3. The answer will always be an even number.");
            Console.WriteLine("Bonus: Because this is typically done with standard d6, try to visualize them.");
            Console.WriteLine();
            Console.WriteLine("Rolling Dice...");

            int face1 = Dice.Roll(6);
            int sleep = Dice.Roll(90);
            System.Threading.Thread.Sleep(sleep);
            int face2 = Dice.Roll(6);
            sleep = Dice.Roll(90);
            System.Threading.Thread.Sleep(sleep);
            int face3 = Dice.Roll(6);
            sleep = Dice.Roll(90);
            System.Threading.Thread.Sleep(sleep);
            int face4 = Dice.Roll(6);
            sleep = Dice.Roll(90);
            System.Threading.Thread.Sleep(sleep);
            int face5 = Dice.Roll(6);
            Console.Clear();

            Console.WriteLine("Petals Around the Rose");
            Console.WriteLine();
            Console.WriteLine("I can tell you three rules. You have to figure out the rest.");
            Console.WriteLine("1. The name of the game is Petals Around the Rose.");
            Console.WriteLine("2. The name of the game is very important.");
            Console.WriteLine("3. The answer will always be an even number.");
            Console.WriteLine("Bonus: Because this is typically done with standard d6, try to visualize them.");
            Console.WriteLine();
            Console.Write("Die 1: ");
            Console.WriteLine(face1);
            Console.Write("Die 2: ");
            Console.WriteLine(face2);
            Console.Write("Die 3: ");
            Console.WriteLine(face3);
            Console.Write("Die 4: ");
            Console.WriteLine(face4);
            Console.Write("Die 5: ");
            Console.WriteLine(face5);
            if (face1 % 2 == 0)
            {
                value1 = 0;
            }
            else { value1 = face1 - 1; }
            if (face2 % 2 == 0)
            {
                value2 = 0;
            }
            else { value2 = face2 - 1; }
            if (face3 % 2 == 0)
            {
                value3 = 0;
            }
            else { value3 = face3 - 1; }
            if (face4 % 2 == 0)
            {
                value4 = 0;
            }
            else { value4 = face4 - 1; }
            if (face5 % 2 == 0)
            {
                value5 = 0;
            }
            else { value5 = face5 - 1; }
            int ans = value1 + value2 + value3 + value4 + value5;

            bool num = false;
            while (!num)
            {
                Console.Write("What is your guess? ");

                string usin = Console.ReadLine();
                int i;
                if (int.TryParse(usin, out i) == true)
                { num = true; }
                else
                {
                    Console.WriteLine("Invalid entry. Please enter a number.");
                    
                }
                if (num)
                {
                    Console.WriteLine("The correct answer is " + ans + ".");

                    if (i == ans) { Points.score++; Streak.score++; }
                    else { Streak.score = 0; }

                    Console.WriteLine();
                    Console.WriteLine("Score: " + Points.score + "            Streak; " + Streak.score);

                    Console.WriteLine();
                    Console.WriteLine("Continue playing? [N will stop playing, all other entries continue.]");
                    usin = Console.ReadLine();
                    if (usin == "n" || usin == "N") { play = false; }
                    Console.Clear();
                }
            }
        }
        Console.WriteLine("Thank you for playing!");
        Console.ReadLine();
            Console.Clear();
        
    }
}
}

#6

petalGame.js
games-petals.js (Idk why hastebin called it sql lol)

I have them set to go into a /custom/ folder but you can change it.

I’m sure it can be done better. If you encounter issues let me know.

Usage:

!petals - tells you info about the game
!petals start - Starts a game.
!petals reward - Allows admins to set the reward all winning users get
!guess - guesses the number if the game is running


#7

This looks brilliant! I won’t be able to test until Monday evening, and I’ll have to change some of the chatbot’s output, but just looking at the code makes me giddy! Thank you so much!

As an aside, can we petition Twitch for some dice emotes? This wouldn’t be the only bot game to benefit from them.

Also, thank you ScaniaTV for editing that code for clarity.


#8

It doesn’t appear to be working. Where exactly do I need to put the files? I can’t seem to find anything online regarding how to set up custom modules.


#9

Apologies!

petalGame.js goes in:
RootBotFolder/scripts/custom/games/petalGame.js

games-petals.js goes in:
RootBotFolder/scripts/lang/custom/games/games-petal.js


#10

Working perfectly now! Many thanks! Is there a channel I can shoutout now and then to send recognition your way?


#11

Question… my phantombot directory only has a “custom” folder in the scripts/lang directory but not the scripts folder itself (aka the “custom” folder in this directory doesn’t exist RootBotFolder/scripts/custom/games/petalGame.js). Is something wrong with my bot/or directory?


#12

You make that yourself.


#13

any way i can set a cool down for this game?


#14

Use the web panel or use a command:
!coolcom command time [user/global]

Example:
!coolcom petals 30 user

Would make the command !petals have a 30 second cooldown per user.


#15

This is awesome! Any way this could be implemented into discord because me and my friends are using discord most of the time and nobody wants to go to my twitch channel just to play this game :confused:


#16

Yes it’d be possible but I’ll have to take a look at it when I get some downtime; unless someone else feels like adding in the support.


#17

ok thank you. Is it hard to convert this into discord capable app? Cause if its not maybe i could look it up and try and do it myself. But if you do come up with one. Please do post it here :smiley: btw: thank you for such a quick response!


#18

Nah it shouldn’t be very hard.

You just need to change the twitch command handler to discord, and change the twitch responses ($.say) to discords (Something like $.discord.say I think?)


#19

Welp. Hard enough to make me scratch my head trying to figure this out for 20 mins. haha anyways. i hope you can help me during your free time! thank you in advance!


#20

Discord only:
petalGame.js - Place this file in \scripts\discord\custom\games\ (you may have to create custom\games)
games-petals.js - Place this file in \scripts\lang\custom\discord\games (you may have to create custom\discord\games)

Did some slight testing and it seemed to work. You’ll have to check on your end. The game also ends pretty quickly.