Thread: Blackjack
View Single Post
  #8  
Old 01-19-2017, 09:32 PM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default

That' beautiful Shin. Just for laughs I will show you what I've been doing for the last 24 hours and still had not figured it out. I found myself in a loop trying to fix one issue then creating another. lol I appreciate your time. Thanks again.
Code:
#############
#Quest Name: Black Jack's Blackjack
#Author: Cisyouc
#################

sub DealCard
{
	return quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11);
}

sub EVENT_SAY
{
	my $permissions = $qglobals{"permissions"};
	my $serverTotal = $qglobals{"serverTotal"};
	my $clientTotal = $qglobals{"clientTotal"};

	if($text=~/hail/i)
	{
		quest::say("Greetings $name! Would you like to play some Blackjack? The closest to 21 without going over wins. Dealer wins on a tie. I only accept PLATINUM as a wager and 40pp is the maximum bet. All games return double your wager on win. Dealer must draw atleast one card when showing 16 or lower on the deal to win, dealer only will only hit on 17 and above when losing. Just hand me your bet between 1pp and 40pp to begin! !");
		return; #return on each say
	}

	if($permissions < 1)
	{ #easier to escape than than heavily nested if/else conditions
		quest::say("Have you bet?");
		return;
	}

	if($text=~/deal/i)
	{
	if($permissions > 1)
	{ #easier to escape than than heavily nested if/else conditions
		quest::say("This round has already been dealt, The dealer passes you a $card1 and a $card2 giving you a total of $clientTotal. The dealer is showing a $serverTotal. Say [ ". quest::saylink("hit")." ] for another card or [ ". quest::saylink("stay")." ].");
		return;
	}
		my $card1 = DealCard();
		my $card2 = DealCard();
		my $card3 = DealCard();
		my $card4 = DealCard();
		$clientTotal = $card1 + $card2;
		$serverTotal = $card3 + $card4;
		if ($clientTotal > 21) {
			quest::say("The dealer has handed you a $card1, giving you a total of $clientTotal. You bust, and lose the game.");
			quest::setglobal("bet", 0, 0, "F"); #reset
		    quest::setglobal("permissions", 0, 0, "F"); #reset
			return;
			}
			if ($serverTotal > 20 && $serverTotal < 22) {
			quest::say("The dealer has a BLACKJACK. You lose the game.");
			quest::setglobal("bet", 0, 0, "F"); #reset
		    quest::setglobal("permissions", 0, 0, "F"); #reset
			return;
			}
			if ($serverTotal > 21) {
			quest::say("The dealer has busted with a total of $clientTotal. You win the game.");
			{$iWon = 1;
			}
			if (!$iWon) 
		{ 
			quest::say("Dealer wins with $serverTotal. Thanks for playing.");
		} else
		{
			quest::say("The dealer continues to draw and has busted. You win with $clientTotal. Thanks for playing.");
			my $cash = $qglobals{"bet"};
			$copper = ($cash % 1);
			$cash -= $copper;
			$silver = ($cash % 1);
			$cash -= $silver;
			$gold = ($cash % 1);
			$cash -= $gold;
			$platinum = ($cash % 100)/10;
			quest::givecash($copper, $silver, $gold, $platinum * 10); #Give money
		}
			quest::setglobal("bet", 0, 0, "F"); #reset
		    quest::setglobal("permissions", 0, 0, "F"); #reset
			return;
			}
		quest::say("The dealer passes you a $card1 and a $card2 giving you a total of $clientTotal. The dealer is showing a $serverTotal. Say [ ". quest::saylink("hit")." ] for another card or [ ". quest::saylink("stay")." ].");
		quest::setglobal("permissions", 2, 0, "F"); #set permissions
		quest::setglobal("clientTotal", $clientTotal, 0, "F"); #set permissions
		quest::setglobal("serverTotal", $serverTotal, 0, "F"); #set permissions
		return; 
	}
	if ($serverTotal < 17)
		{
			$serverTotal = $serverTotal + $card4;
		}
		if ($serverTotal > 21 && $clientTotal < 22) {
			quest::say("The dealer has drawn another card and busted. You win the game.");
			{$iWon = 1;
			}
			if (!$iWon) 
		{ 
			quest::say("Dealer wins with $serverTotal. Thanks for playing.");
		} else
		{
			
			my $cash = $qglobals{"bet"};
			$copper = ($cash % 1);
			$cash -= $copper;
			$silver = ($cash % 1);
			$cash -= $silver;
			$gold = ($cash % 1);
			$cash -= $gold;
			$platinum = ($cash % 100)/10;
			quest::givecash($copper, $silver, $gold, $platinum * 10); #Give money
		}
			quest::setglobal("bet", 0, 0, "F"); #reset
		    quest::setglobal("permissions", 0, 0, "F"); #reset
			return;
			}

	if($text=~/hit/i)
	{
		if($permissions != 2)
		{
			quest::say("You must [ ". quest::saylink("deal")." ] first!");
			return;
		}
		my $card3 = DealCard();
		$clientTotal = $clientTotal + $card3;
		quest::setglobal("clientTotal", $clientTotal, 0, "F"); #set permissions
		if ($clientTotal > 21) {
			quest::say("The dealer has handed you a $card3, giving you a total of $clientTotal. You bust, and lose the game.");
			quest::setglobal("bet", 0, 0, "F"); #reset
			quest::setglobal("permissions", 0, 0, "F"); #reset
			return;
		}
		quest::say("The dealer has handed you a $card3, giving you a total of $clientTotal. The dealer continues and is now showing a $serverTotal. Say [ ". quest::saylink("hit")." ] for another card or [ ". quest::saylink("stay")." ].");
		return;
	}

	if($text=~/stay/i)
	{
		if($permissions != 2)
		{
			quest::say("You must [ ". quest::saylink("deal")." ] first!");
			return;
		}

		my $iWon = 0;
		if ($clientTotal > 21 && $serverTotal < 21) 
		{ #client went over, server didn't

		} elsif ($serverTotal > 21 && $clientTotal < 21) 
		{ #server went over, client didn't
			$iWon = 1;
		} elsif ($clientTotal < $serverTotal && $serverTotal <= 21)
		{ #server won fair

		} elsif ($serverTotal < $clientTotal && $clientTotal <= 21)
		{ #client won fair			
			$iWon = 1;
		}

		if (!$iWon) 
		{ 
			quest::say("Dealer continues and wins with $serverTotal. Thanks for playing.");
		} else
		{
			quest::say("The dealer continues to draw and busted. You win with $clientTotal. Thanks for playing.");
			my $cash = $qglobals{"bet"};
			$copper = ($cash % 1);
			$cash -= $copper;
			$silver = ($cash % 1);
			$cash -= $silver;
			$gold = ($cash % 1);
			$cash -= $gold;
			$platinum = ($cash % 100)/10;
			quest::givecash($copper, $silver, $gold, $platinum * 10); #Give money
		}
		quest::setglobal("bet", 0, 0, "F"); #reset
		quest::setglobal("permissions", 0, 0, "F"); #reset 
		return;
	}
}

sub EVENT_ITEM
{
	my $cash = $platinum;

	if ($cash < 1) {
		quest::say("I only accept PLATINUM as a wager!");
		return;
	}

	if ($qglobals{"permissions"} > 0) {
		quest::say("You still have a deal going on.");
		return;
	}
	$cash = $cash * 2; #double the bet
	quest::say("Your wager of $platinum platinum has been saved. You may [ ". quest::saylink("deal")." ] the cards now.");
	quest::setglobal("bet", $cash, 0, "F"); #easier to just set all money.
	quest::setglobal("permissions", 1, 0, "F"); #set permissions
}
Reply With Quote