Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Custom

Quests::Custom Custom Quests here

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2017, 11:04 PM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default Blackjack

Looking for a fresh set of eyes to help me get this working. Thank you in advance.
Code:
#############
#Quest Name: Black Jack's Blackjack
#Author: Cisyouc
#################

my $permissions = 0;
my $xplatinum = 0;
my $xgold = 0;
my $xsilver = 0;
my $xcopper = 0;
my $client1 = 0;
my $client2 = 0;
my $server = 0;
my $client = 0;

sub DealCard
{
	@cards = (1,2,3,4,5,6,7,8,9,10,11);
	$returnvalue = $cards[int(rand(scalar @cards))];
	return $choice;
}

sub EVENT_SAY
{
	if($text=~/hail/i)
		{
			quest::say("Greetings! Want to play balackjack? Hand me your bet to begin! All games return double on win!");
		}
	if($text=~/deal/i)
		{
			if($permissions == 1)
				{
					$client1 = DealCard();
					$client2 = DealCard();
					my $tempserver = DealCard();
					my $tempclient = ($client1+$client2);
					$client = $tempclient;
					$server = (DealCard() + $tempserver);
					if($server < 16)
						{
							$server = ($server + DealCard());
						}
					quest::say("The dealer passes you a $client1 and a $client2 giving you a total of $tempclient. The dealer is showing a $tempserver. Say [yes] for another card or [no] to stay.");
					$permissions = 2;
				}
				else
				{
					quest::say("Have you bet?");
				}
		}
	if($text=~/yes/i)
		{
			if($permissions == 2)
				{
					my $newcard = DealCard();
					$client = ($client + $newcard);
					quest::say("The dealer has handed you a $newcard, giving you a total of $client. Say [yes] for another card or [no] to stay.");
				}
				elsif($permissions == 1)
				{
					quest::say("You must [deal] first!");
				}
		}
	if($text=~/no/i)
		{
			if($permissions == 2)
				{
					if($client < $server && $server <= 21)
						{
							quest::say("Dealer wins with $server. Thanks for playing.");
							$client = 0;
							$permissions = 0;
							$xplatinum = 0;
							$xgold = 0;
							$xsilver = 0;
							$xcopper = 0;
						}
					if($client < $server && $server > 21)
						{
							quest::say("You win with $client. Thanks for playing.");
							quest::givecash($xplatinum*2,$xgold*2,$xsilver*2,$xcopper*2);
							$permissions = 0;
							$client = 0;
							$xplatinum = 0;
							$xgold = 0;
							$xsilver = 0;
							$xcopper = 0;
						}
					if($client > $server && $client <= 21)
						{
							quest::say("You win with $client. Thanks for playing.");
							quest::givecash($xplatinum*2,$xgold*2,$xsilver*2,$xcopper*2);
							$permissions = 0;
							$client = 0;
							$xplatinum = 0;
							$xgold = 0;
							$xsilver = 0;
							$xcopper = 0;
						}
					if($client > $server && $client > 21)
						{
							quest::say("Dealer wins with $server. Thanks for playing.");
							$permissions = 0;
							$xplatinum = 0;
							$client = 0;
							$xgold = 0;
							$xsilver = 0;
							$xcopper = 0;
						}
				}
		}
}

sub EVENT_ITEM
{
	if($xplatinum > 0 || $xgold > 0 || $xsilver > 0 || $xcopper > 0 && $permissions == 0 && $platinum > 0 && $gold > 0 && $silver > 0 && $copper > 0)
		{
			quest::say("Your bet of $platinum platinum, $gold gold, $silver silver, $copper copper has been saved. You may [deal] the cards now.");
			$xplatinum = $platinum;
			$xgold = $gold;
			$xsilver = $silver;
			$xcopper = $copper;
			$permissions = 1;
		}
	else
		{
			quest::say("You've already bet!");
		}
}
Reply With Quote
  #2  
Old 01-18-2017, 11:37 PM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,497
Default

Where is it failing? Have you tried #questerrors?

Not sure if you can redefine a global variable like $client in Perl. Maybe it creates its own instance, but might be worth looking in to.
Reply With Quote
  #3  
Old 01-18-2017, 11:51 PM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default

When you say deal, it skips to the end and says you've already bet. Something is not letting the questglobal not saving the information needed to continue with the script. Where do I find quest errors? Thanks.
Reply With Quote
  #4  
Old 01-19-2017, 12:58 AM
Shin Noir's Avatar
Shin Noir
Legendary Member
 
Join Date: Apr 2002
Location: Seattle, WA
Posts: 506
Default

You weren't using qglobals. Make sure your npc is set with qglobals by targetting it and typing #npcedit qglobals 1 , then #repop for it to apply.
Using "global" scoped variables on the top outside a function means that it will share it between players and have some bad juju.

I remedied your code, and did a few improvements.. It should work, likely some bugs here or there. Enjoy.


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! Want to play balackjack? Hand me your bet to begin! All games return double on win! $permissions");
		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)
	{
		my $card1 = DealCard();
		my $card2 = DealCard();
		$clientTotal = $card1 + $card2;
		$serverTotal = DealCard() + DealCard();
		if($serverTotal < 16)
		{
			$serverTotal = $serverTotal + DealCard();
		}
		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("yes")." ] for another card or [ ". quest::saylink("no")." ] to 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($text=~/yes/i)
	{
		if($permissions != 2)
		{
			quest::say("You must [ ". quest::saylink("deal")." ] first!");
			return;
		}
		my $card1 = DealCard();
		$clientTotal = $clientTotal + $card1;
		quest::setglobal("clientTotal", $clientTotal, 0, "F"); #set permissions
		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;
		}
		quest::say("The dealer has handed you a $card1, giving you a total of $clientTotal. The deal is showing a $serverTotal. Say [ ". quest::saylink("yes")." ] for another card or [ ". quest::saylink("no")." ] to stay.");
		return;
	}

	if($text=~/no/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 wins with $serverTotal. Thanks for playing.");
		} else
		{
			quest::say("You win with $clientTotal. Thanks for playing.");
			my $cash = $qglobals{"bet"};
			$copper = ($cash % 10);
			$cash -= $copper;
			$silver = ($cash % 100)/10;
			$cash -= $silver;
			$gold = ($cash % 1000)/100;
			$cash -= $gold;
			$platinum = ($cash % 10000)/1000;
			quest::givecash($copper, $silver, $gold, $platinum); #Give money
		}
		quest::setglobal("bet", 0, 0, "F"); #reset
		quest::setglobal("permissions", 0, 0, "F"); #reset 
		return;
	}
}

sub EVENT_ITEM
{	
	my $cash = $copper + ($silver * 10) + ($gold * 100) + ($platinum * 1000);

	if ($cash < 1) {
		quest::say("You must give me money to bet");
		return;
	}

	if ($qglobals{"permissions"} > 0) {
		quest::say("You still have a deal going on.");
		return;
	}
	$cash = $cash * 2; #double the bet
	quest::say("Your bet of $platinum platinum, $gold gold, $silver silver, $copper copper 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
}
__________________

~Shin Noir
DungeonEQ.com

Last edited by Shin Noir; 01-19-2017 at 01:03 AM..
Reply With Quote
  #5  
Old 01-19-2017, 01:29 AM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default

This rocks, works like a charm, thank you kindly.
Reply With Quote
  #6  
Old 01-19-2017, 03:25 AM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default

One issue, anything over 4 pp returns the incorrect amount of winnings or none at all. Any help appreciated. Thanks again.
Reply With Quote
  #7  
Old 01-19-2017, 04:50 PM
ghanja's Avatar
ghanja
Dragon
 
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
Default

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! Want to play balackjack? Hand me your bet to begin! All games return double on win! $permissions");
		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)
	{
		my $card1 = DealCard();
		my $card2 = DealCard();
		$clientTotal = $card1 + $card2;
		$serverTotal = DealCard() + DealCard();
		if($serverTotal < 16)
		{
			$serverTotal = $serverTotal + DealCard();
		}
		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("yes")." ] for another card or [ ". quest::saylink("no")." ] to 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($text=~/yes/i)
	{
		if($permissions != 2)
		{
			quest::say("You must [ ". quest::saylink("deal")." ] first!");
			return;
		}
		my $card1 = DealCard();
		$clientTotal = $clientTotal + $card1;
		quest::setglobal("clientTotal", $clientTotal, 0, "F"); #set permissions
		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;
		}
		quest::say("The dealer has handed you a $card1, giving you a total of $clientTotal. The deal is showing a $serverTotal. Say [ ". quest::saylink("yes")." ] for another card or [ ". quest::saylink("no")." ] to stay.");
		return;
	}

	if($text=~/no/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 wins with $serverTotal. Thanks for playing.");
		} else
		{
			quest::say("You win with $clientTotal. 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
		}
		quest::setglobal("bet", 0, 0, "F"); #reset
		quest::setglobal("permissions", 0, 0, "F"); #reset 
		return;
	}
}

sub EVENT_ITEM
{	
	my $cash = $copper + ($silver * 10) + ($gold * 100) + ($platinum * 1000);

	if ($cash < 1) {
		quest::say("You must give me money to bet");
		return;
	}

	if ($qglobals{"permissions"} > 0) {
		quest::say("You still have a deal going on.");
		return;
	}
	$cash = $cash * 2; #double the bet
	quest::say("Your bet of $platinum platinum, $gold gold, $silver silver, $copper copper 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
}
I'd probably use entity variables to reduce the read/writes to DB, but try the above.
Reply With Quote
  #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
  #9  
Old 01-19-2017, 11:55 PM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default Blackjack in action

Love the new Blackjack, addicting. I got a new dealer in town. Also added, if the dealer gets a blackjack the game ends in a loss. Tried to make it as close to casino Blackjack as possible. Thanks again for the help.

Reply With Quote
  #10  
Old 01-20-2017, 12:14 AM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default

Added the profit to the dialog when you win. Took some big losses on this one. lol
Reply With Quote
  #11  
Old 01-23-2017, 08:55 PM
cannon
Hill Giant
 
Join Date: Dec 2004
Location: Pittsburgh, PA
Posts: 128
Default

I did end up using Ghanja's code for the money situation. With some tweaks and a little bit of both examples and additions its about as close to a real blackjack table as it gets.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:38 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3