EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Custom (https://www.eqemulator.org/forums/forumdisplay.php?f=671)
-   -   Higher or Lower game (https://www.eqemulator.org/forums/showthread.php?t=42427)

Sturm 05-02-2019 10:21 PM

Higher or Lower game
 
Simple little game I made. Uses qglobals, but I'm sure it'd be simple to adapt it to data buckets if you're so inclined. Enjoy!

Code:

# Higher_Lower.pl Game
# written by Sturm

sub DiceRoll {
        quest::ChooseRandom(1..20);
}

sub CleanUP {
        quest::delglobal(permissions);
        quest::delglobal(dealerroll);
        quest::delglobal(playerdice);
        quest::delglobal(bet);
}

sub EVENT_SAY {
        my $permissions = $qglobals{"permissions"}; # have you place a wager
        my $dealerroll = $qglobals{"dealerroll"}; # the dealer's dice roll
        my $playerdice  = $qglobals{"playerdice"};
        if ($text =~ /hail/i) {
                plugin::Whisper("Hello $name! Would you like to play Higher or Lower? It's easy, just hand me your bet and I'll roll a dice between 1 and 20. Then you guess if the next roll is going to be higher or lower. If you're right you get double your bet back! The Maximum wager is 1,000pp.");
        }
        elsif ($text =~ /Higher/i) {
                if ($permissions < 1) {
                        plugin::Whisper("You must place a wager to play.");
                }
                else {
                        $playerdice = DiceRoll();
                        if ($playerdice == $dealerroll) {
                                # push - cards are the same. Return bet.
                                plugin::Whisper("You rolled a $playerdice. It's a draw. Returning your wager. Thanks for playing.");
                                my $cash = $qglobals{"bet"};
                                $copper        = ($cash % 10);
                                $silver        = (int ($cash / 20) % 10);
                                $gold = (int ($cash / 200) % 10);
                                $platinum = int ($cash / 2000);
                                quest::givecash($copper, $silver, $gold, $platinum); #Give money back
                                CleanUP();
                        }
                        elsif ($playerdice < $dealerroll) {
                                # players dice is lower than dealers - player lost.
                                plugin::Whisper("You rolled a $playerdice. It's lower, you lost. Thanks for playing.");
                                CleanUP();
                        }
                        elsif ($playerdice > $dealerroll) {
                                # players dice is greater than dealers - player won.
                                plugin::Whisper("You rolled a $playerdice. It's higher, you win! Thanks for playing.");
                                my $cash = $qglobals{"bet"};
                                $copper        = ($cash % 10);
                                $silver        = (int ($cash / 10) % 10);
                                $gold = (int ($cash / 100) % 10);
                                $platinum = int ($cash / 1000);
                                quest::givecash($copper, $silver, $gold, $platinum); #Give money
                                CleanUP();
                        }
                }
        }
        elsif ($text =~ /Lower/i) {
                if ($permissions < 1) {
                        plugin::Whisper("You must place a wager to play.");
                }
                else {
                        $playerdice = DiceRoll();
                        if ($playerdice == $dealerroll) {
                                # push - cards are the same. Return bet.
                                plugin::Whisper("You rolled a $playerdice. It's a draw. Returning your wager. Thanks for playing.");
                                my $cash = $qglobals{"bet"};
                                $copper        = ($cash % 10);
                                $silver        = (int ($cash / 20) % 10);
                                $gold = (int ($cash / 200) % 10);
                                $platinum = int ($cash / 2000);
                                quest::givecash($copper, $silver, $gold, $platinum); #Give money back
                                CleanUP();
                        }
                        elsif ($playerdice < $dealerroll) {
                                # players dice is lower than dealers - player wins.
                                plugin::Whisper("You rolled a $playerdice. It's lower, you win! Thanks for playing.");
                                my $cash = $qglobals{"bet"};
                                $copper        = ($cash % 10);
                                $silver        = (int ($cash / 10) % 10);
                                $gold = (int ($cash / 100) % 10);
                                $platinum = int ($cash / 1000);
                                quest::givecash($copper, $silver, $gold, $platinum); #Give money
                                CleanUP();
                        }
                        elsif ($playerdice > $dealerroll) {
                                # players dice is greater than dealers - player lost.
                                plugin::Whisper("You rolled a $playerdice. It's higher, you lost! Thanks for playing.");
                                CleanUP();
                        }
                }
        }
}

sub EVENT_ITEM {
        my $Higher = quest::saylink("Higher",1);
        my $Lower = quest::saylink("Lower",1);
        if ($platinum > 0 && $platinum <= 1000) {
        my $cash = $copper + ($silver * 10) + ($gold * 100) + ($platinum * 1000);

        if ($cash < 1 ) {
                plugin::Whisper("You must give me money to play.");
                return;
        }

        if ($qglobals{"permissions"} > 0) {
                plugin::Whisper("You still have a game going on.");
                return;
        }
        $cash = $cash * 2; #double the bet
        $dice = DiceRoll();
        plugin::Whisper("Your bet of $platinum platinum has been saved. I'm showing a $dice on the dice. What do you choose: $Higher or $Lower?");
        quest::setglobal("dealerroll", $dice, 0, "F"); # set dealer's roll
        quest::setglobal("bet", $cash, 0, "F"); #easier to just set all money.
        quest::setglobal("permissions", 1, 0, "F"); #set permissions
        }
        else {
                quest::givecash($copper, $silver, $gold, $platinum);
                plugin::Whisper("You may only bet coins and only upto a maximum of 10,000 platinum.");
                return;
        }
        plugin::return_items(\%itemcount);
}


EQDencelle 05-27-2019 01:18 AM

2 issues that are poping out at me

1 when you break even, your still returning double money because you misplaced where the money doubling is

2 you should be using floor, not int to do the rounding, int will convert things like 1.6 to 2, where floor will convert 1.6 to 1 as it should be

Sturm 05-27-2019 12:48 PM

1 Nope, you better check that scripting again.
2 There is no rounding, so no issues there.

The only issue I found was I neglected to change the:
plugin::Whisper("You may only bet coins and only upto a maximum of 10,000 platinum.");

at the bottom to say the max bet was 1k plat, as I decided 10k was to much for a bet as winning is heavily weighted to the client.

Thanks for the input though :)

EQDencelle 05-27-2019 02:23 PM

i see where you doubled the cash... when the player hands in the plat and such in the first place, but if they break even, i don't see a divide of the bet or anything to turn it back to the original amount... maybe i'm missing something?

Code:

$cash = $cash * 2; #double the bet
as for rounding, you are rounding, its just not apparent i guess...
take this code, if your orginal amounts were as follows: 7 copper, 0 silver
you would get back 7 copper, 1 silver (literally just tested this in a lua sandbox just to make sure i wasn't going crazy)
Code:

my $cash = $qglobals{"bet"};
$copper        = ($cash % 10);
$silver        = (int ($cash / 10) % 10);
$gold = (int ($cash / 100) % 10);
$platinum = int ($cash / 1000);


Sturm 05-27-2019 02:28 PM

I get what you're saying about the rounding, but you can only turn in platinum to the NPC he will hand you back anything else, so that doesn't become an issue.

Code:

if ($playerdice == $dealerroll) {
                                # push - cards are the same. Return bet.
                                plugin::Whisper("You rolled a $playerdice. It's a draw. Returning your wager. Thanks for playing.");
                                my $cash = $qglobals{"bet"};
                                $copper        = ($cash % 10);
                                $silver        = (int ($cash / 20) % 10);
                                $gold = (int ($cash / 200) % 10);
                                $platinum = int ($cash / 2000);
                                quest::givecash($copper, $silver, $gold, $platinum); #Give money back
                                CleanUP();
                        }

It's dividing the bet in half here on the push. Probably not the best way to do it, but it worked. I am definitely not an expert coder, I just dabble and play around with stuff.
This was just something simple I created and thought I'd share it for those wanting a simple gambling mechanic for their server.
Was kinda hoping this sparked an idea in someone and they'd post some other fun little game for everyone to play with.

:)

PeaceDuke 06-26-2020 03:00 AM

Thanks guyz!


All times are GMT -4. The time now is 12:36 PM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.