Simple Blackjack v2

Forum Archive - from http://theuniversal.net
Locked
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Simple Blackjack v2

Post by zaroba »

spent some time on the simple blackjack script before adding it to tuwr's script area.

new changes:
Players can set a bet amount by buying tokens and using them, as long as theres no game in progress.
Players can cancel their bet and get their money back, as long as theres no game in progress.
Added a help system accessible by the &bjhelp command
Added a &resetbj command to reset a game in progress
Changed the &hit and &stand commands to &bjhit and &bjstand


to set it up on your world: This script uses 10 event script slots (you can have upto 64 things defined in the event script), and it uses Playervars 40-47 and 50-57. it uses higher numbered vars since most people will probably use lower vars first, so this script probably wont interfere with any other scripts. however, if any other scripts use these vars, there will most likely be problems. due to how big this script is, it'd probably be easier to change the other things :P

using the script as shown, you will need to build a gov building that sells usable items named Bet 1s, Bet 10s, Bet 100s, Bet 1000s, and Bet Canceler. the Bet Canceler should be sold for 1d, the others should probably be sold for the value they add to the bet. you can easily change how much they add in the script, and will have to if your world doesn’t use 10d per s.

Code: Select all


Event( "use item", "bet 1s" )
	{
	if $PlayerVar[41] = 0
		{
		$PlayerVar[55] = $PlayerVar[55] + 10
		*msg %player% you have added 1s to your bet
		*msg %player% your bet is now $PlayerVar[55]
		}
	else
		{
		*msg %player% you cannot change your bet when you have a game in progress.
		*msg %player% Your total card value is $PlayerVar[46]
		*msg %player% Would you like to Hit or Stand?
		}
	}


Event( "use item", "bet 10s" )
	{
	if $PlayerVar[41] = 0
		{
		$PlayerVar[55] = $PlayerVar[55] + 100
		*msg %player% you have added 10s to your bet
		*msg %player% your bet is now $PlayerVar[55]
		}
	else
		{
		*msg %player% you cannot change your bet when you have a game in progress.
		*msg %player% Your total card value is $PlayerVar[46]
		*msg %player% Would you like to Hit or Stand?
		}
	}


Event( "use item", "bet 100s" )
	{
	if $PlayerVar[41] = 0
		{
		$PlayerVar[55] = $PlayerVar[55] + 1000
		*msg %player% you have added 100s to your bet
		*msg %player% your bet is now $PlayerVar[55]
		}
	else
		{
		*msg %player% you cannot change your bet when you have a game in progress.
		*msg %player% Your total card value is $PlayerVar[46]
		*msg %player% Would you like to Hit or Stand?
		}
	}


Event( "use item", "bet 1000s" )
	{
	if $PlayerVar[41] = 0
		{
		$PlayerVar[55] = $PlayerVar[55] + 10000
		*msg %player% you have added 1000s to your bet
		*msg %player% your bet is now $PlayerVar[55]
		}
	else
		{
		*msg %player% you cannot change your bet when you have a game in progress.
		*msg %player% Your total card value is $PlayerVar[46]
		*msg %player% Would you like to Hit or Stand?
		}
	}


Event( "use item", "bet canceler" )
	{
	if $PlayerVar[41] = 0
		{
		$PlayerVar[55] = $PlayerVar[55] + 1
		*msg %player% you have canceled your bet.
		*grantcash %player% $PlayerVar[55]
		}
	else
		{
		*msg %player% you cannot cancel your bet when you have a game in progress.
		*msg %player% Your total card value is $PlayerVar[46]
		*msg %player% Would you like to Hit or Stand?
		}
	}


Event( "&command", "resetbj" )
	{
	*msg %player% You decide your no match for the dealer and forfiet the game.
	*msg %player% The dealer wins by default.  Better luck next time.
	$PlayerVar[41] = 0
	$PlayerVar[55] = 0
	}


Event( "&command", "bjhelp" )
	{
	*msg %player% 
	*msg %player% Welcome to Simple Blackjack v2, made by zaroba
	*msg %player% This easier version of blackjack gives players an advantage over the dealer.  The object of the game is to get as 
	*msg %player% as close to haveing a card value of 21 as you possibly can, but without going over 21.  If you are dealt an Ace
	*msg %player% and if it will put you over 21, then its value will automatically be changed to 1.  however, this is not done for
	*msg %player% the dealer, this is to make this simple version easier for players to win.
	*msg %player% now then, onto how to play
	*msg %player%    
	*msg %player% its really simple, and all done via a few commands:
	*msg %player% &Blackjack - starts the game.  if you already had a game in progress, you will have to finish or quit that
	*msg %player% one first.  games are saved threw relogs/crashes, so even if you logoff, your game wont end.
	*msg %player% &resetbj - typed to quit the game in progress.  you will lose any bet you made
	*msg %player% &bjhelp - shows this text, you should already know that
	*msg %player% &bjhit - type this to get another card.  careful though, if you go over 21, you lose.
	*msg %player% &bjstand - when you are happy with your total card value, type this to end your turn and let the dealer play.
	*msg %player% 
	*msg %player% In order to bet, you must buy bet Tokens from a shop.
	*msg %player% Once baught, open your inventory and use them to add money to your bet. 
	*msg %player% It might also be good to buy some bet Cancellers.  that way, you can reset your bet and get it back if needed
	*msg %player% once you start a game, you will not be able to change your bit.  once you finish a game, either by winning, loosing,
	*msg %player% or resetting it, you will need to place your bet again by using more bet tokens.
	*msg %player% 
	}


Event( "&command", "Blackjack" )
	{
	*msg %player% Welcome to Simple Blackjack v2, made by zaroba.
	*msg %player% For info on how to play, type &bjhelp (and hit your F2 key or hit F1 to read everything)
	if ( $PlayerVar[41] = 0)
		{
		$PlayerVar[40] = $PlayerVar[55]
		$PlayerVar[41] = rand(10) + 1
		$PlayerVar[42] = rand(10) + 1
		$PlayerVar[43] = rand(10) + 1
		$PlayerVar[44] = rand(10) + 1
		$PlayerVar[45] = rand(10) + 1
		$PlayerVar[46] = $PlayerVar[41] + $PlayerVar[42]
		$PlayerVar[47] = 2
		$PlayerVar[50] = rand(10) + 1
		$PlayerVar[51] = rand(10) + 1
		$PlayerVar[52] = rand(10) + 1
		$PlayerVar[53] = rand(10) + 1
		$PlayerVar[54] = rand(10) + 1
		$PlayerVar[55] = $PlayerVar[55] + $PlayerVar[55]
		$PlayerVar[56] = $PlayerVar[50] + $PlayerVar[51]
		$PlayerVar[57] = 2
		*msg %player% You have bet $PlayerVar[40], the pot is $PlayerVar[55]
		*msg %player% Your cards are $PlayerVar[41] and $PlayerVar[42].  One of the dealers cards is a $PlayerVar[50]
		if ($PlayerVar[46] = 21)
			{
			*msg %player% Congratulations!  you have 21! You should Stand.
			*msg %player% the prize pot has doubled.  it is now $PlayerVar[55]
			}
		else
			{
			*msg %player% Your total card value is $PlayerVar[46]
			*msg %player% Would you like to Hit or Stand?
			}
		}
	else
		{
		*msg %player% You already have a blackjack game in progress.
		*msg %player% Your total card value is $PlayerVar[46]
		*msg %player% Would you like to Hit or Stand?
		}
	}

Event( "&command", "bjhit" )
	{
	if ($PlayerVar[47] = 2)
		{
		*msg %player% Your cards are $PlayerVar[41], $PlayerVar[42], $PlayerVar[43]
		$PlayerVar[46] = $PlayerVar[46] + $PlayerVar[43]
		$PlayerVar[47] = 3
		if ($PlayerVar[46] > 21)
			{
			if ($PlayerVar[41] = 11)
				{
				$PlayerVar[41] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else if ($PlayerVar[42] = 11)
				{
				$PlayerVar[42] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else if ($PlayerVar[43] = 11)
				{
				$PlayerVar[43] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else
				{
				*msg %player% You have gone over 21.  You Lose.  Better luck next time.
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			}
		else
			{
			*msg %player% Your total card value is $PlayerVar[46]
			*msg %player% Would you like to Hit or Stand?
			}
		}
	else if ($PlayerVar[47] = 3)
		{
		*msg %player% Your cards are $PlayerVar[41], $PlayerVar[42], $PlayerVar[43], $PlayerVar[44]
		$PlayerVar[46] = $PlayerVar[46] + $PlayerVar[44]
		$PlayerVar[47] = 4
		if ($PlayerVar[46] > 21)
			{
			if ($PlayerVar[41] = 11)
				{
				$PlayerVar[41] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else if ($PlayerVar[42] = 11)
				{
				$PlayerVar[42] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else if ($PlayerVar[43] = 11)
				{
				$PlayerVar[43] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else if ($PlayerVar[44] = 11)
				{
				$PlayerVar[44] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Your total card value is $PlayerVar[46]
				*msg %player% Would you like to Hit or Stand?
				}
			else
				{
				*msg %player% You have gone over 21.  You Lose.  Better luck next time.
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			}
		else
			{
			*msg %player% Your total card value is $PlayerVar[46]
			*msg %player% Would you like to Hit or Stand?
			}
		}
	else
		{
		*msg %player% Your cards are $PlayerVar[41], $PlayerVar[42], $PlayerVar[43], $PlayerVar[44], $PlayerVar[45]
		$PlayerVar[46] = $PlayerVar[46] + $PlayerVar[45]
		$PlayerVar[47]=5
		if ($PlayerVar[46] > 21)
			{
			if ($PlayerVar[41] = 11)
				{
				$PlayerVar[41] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Congradulations!  You have won due to the 5 card rule!
				*grantcash %player% $PlayerVar[55]
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			else if ($PlayerVar[42] = 11)
				{
				$PlayerVar[42] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Congradulations!  You have won due to the 5 card rule!
				*grantcash %player% $PlayerVar[55]
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			else if ($PlayerVar[43] = 11)
				{
				$PlayerVar[43] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Congradulations!  You have won due to the 5 card rule!
				*grantcash %player% $PlayerVar[55]
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			else if ($PlayerVar[44] = 11)
				{
				$PlayerVar[44] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Congradulations!  You have won due to the 5 card rule!
				*grantcash %player% $PlayerVar[55]
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			else if ($PlayerVar[45] = 11)
				{
				$PlayerVar[45] = 1
				$PlayerVar[46] = $PlayerVar[46] - 10
				*msg %player% Your Ace had to be changed to a value of 1 instead of 11 to prevent you from going over 21
				*msg %player% Congradulations!  You have won due to the 5 card rule!
				*grantcash %player% $PlayerVar[55]
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			else
				{
				*msg %player% You have gone over 21.  You Lose.  Better luck next time.
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}
			}
		else
			{
			*msg %player% Congradulations!  You have won due to the 5 card rule!
			*grantcash %player% $PlayerVar[55]
			$PlayerVar[41] = 0
			$PlayerVar[55] = 0
			}
		}
	}



Event( "&command", "bjstand" )
	{
	*msg %player% You have decided to Stand with a total card value of $PlayerVar[46]
	*msg %player% It is now the dealers turn to play.
	*msg %player% The dealers cards are $PlayerVar[50] and $PlayerVar[51]
	if ($PlayerVar[56] > 16)
		{
		sleep(20)
		*msg %player% The dealer decides to Stand with a total value of $PlayerVar[56]
		if ($PlayerVar[56] > $PlayerVar[46])
			{
			*msg %player% Unfortunatly the dealer has won this round.
			*msg %player% better luck next time.
			$PlayerVar[41] = 0
			$PlayerVar[55] = 0
			}
		else if ($PlayerVar[56] = $PlayerVar[46])
			{
			*msg %player% The game is a tie, there is no winner.  Atleast you diden't loose anything.
			*msg %player% Feel free to try again.
			*grantcash player $PlayerVar[40]
			$PlayerVar[41] = 0
			$PlayerVar[55] = 0
			}
		else
			{
			*msg %player% Congradulations!  you have won this hand!
			*msg %player% You have won $PlayerVar[55] Deneri!
			*grantcash %player% $PlayerVar[55]
			$PlayerVar[41] = 0
			$PlayerVar[55] = 0
			}
		}
	else
		{
		Sleep(20)
		*msg %player% The dealer hits.  his cards are now $PlayerVar[50], $PlayerVar[51], and $PlayerVar[52]
		$PlayerVar[56] = $PlayerVar[56] + $PlayerVar[52]
		if ($PlayerVar[56] > 16)
			{
			if ($PlayerVar[56] > 21)
				{
				*msg %player% The dealer has gone over 21!  you have won this hand!  Congratulations
				*msg %player% You have won $PlayerVar[55] Deneri!
				*grantcash %player% $PlayerVar[55]
				$PlayerVar[41] = 0
				$PlayerVar[55] = 0
				}	
			else	
				{
				sleep(20)
				*msg %player% The dealer decides to Stand with a total value of $PlayerVar[56]
				if ($PlayerVar[56] > $PlayerVar[46])
					{
					*msg %player% Unfortunatly the dealer has won this round.
					*msg %player% better luck next time.
					$PlayerVar[41] = 0
					$PlayerVar[55] = 0
					}
				else if ($PlayerVar[56] = $PlayerVar[46])
					{
					*msg %player% The game is a tie, there is no winner.  Atleast you diden't loose anything.
					*msg %player% Feel free to try again.
					*grantcash player $PlayerVar[40]
					$PlayerVar[41] = 0
					$PlayerVar[55] = 0
						}
				else
					{
					*msg %player% Congratulations!  you have won this hand!
					*msg %player% You have won $PlayerVar[55] Deneri!
					*grantcash %player% $PlayerVar[55]
					$PlayerVar[41] = 0
					$PlayerVar[55] = 0
					}	
				}
			}
		else
			{
			Sleep(20)
			*msg %player% The dealer hits.  his cards are now $PlayerVar[50], $PlayerVar[51], $PlayerVar[52], and $PlayerVar[53]
			$PlayerVar[56] = $PlayerVar[56] + $PlayerVar[53]
			if ($PlayerVar[56] > 16)
				{
				if ($PlayerVar[56] > 21)
					{
					*msg %player% The dealer has gone over 21!  you have won this hand!  Congratulations
					*msg %player% You have won $PlayerVar[55] Deneri!
					*grantcash %player% $PlayerVar[55]
					$PlayerVar[41] = 0
					$PlayerVar[55] = 0
					}	
				else	
					{
					sleep(20)
					*msg %player% The dealer decides to Stand with a total value of $PlayerVar[56]
					if ($PlayerVar[56] > $PlayerVar[46])
						{
						*msg %player% Unfortunatly the dealer has won this round.
						*msg %player% better luck next time.
						$PlayerVar[41] = 0
						$PlayerVar[55] = 0
						}
					else if ($PlayerVar[56] = $PlayerVar[46])
						{
						*msg %player% The game is a tie, there is no winner.  Atleast you diden't loose anything.
						*msg %player% Feel free to try again.
						*grantcash player $PlayerVar[40]
						$PlayerVar[41] = 0
						$PlayerVar[55] = 0
						}
					else
						{
						*msg %player% Congratulations!  you have won this hand!
						*msg %player% You have won $PlayerVar[55] Deneri!
						*grantcash %player% $PlayerVar[55]
						$PlayerVar[41] = 0
						$PlayerVar[55] = 0
						}	
					}
				}
			else	
				{
				Sleep(20)
				*msg %player% The dealer hits.
				*msg %player% his cards are now $PlayerVar[50], $PlayerVar[51], $PlayerVar[52], $PlayerVar[53], and $PlayerVar[54]
				$PlayerVar[56] = $PlayerVar[56] + $PlayerVar[54]
				if ($PlayerVar[56] > 21)
					{
					*msg %player% The dealer has gone over 21!  you have won this hand!  Congratulations
					*msg %player% You have won $PlayerVar[55] Deneri!
					*grantcash %player% $PlayerVar[55]
					$PlayerVar[41] = 0
					$PlayerVar[55] = 0
					}	
				else	
					{
					*msg %player% The dealer wins by default due to the 5 card rule.
					*msg %player% Better luck next time.
					$PlayerVar[41] = 0
					$PlayerVar[55] = 0
					}
				}
			}
		}
	}




------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(just a long line to make the post wider so the script doesn't wrap)
Locked