Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 04-18-2012, 11:46 PM
Hateborne
Hill Giant
 
Join Date: May 2010
Posts: 125
Default Script using DBI does nothing in game, works out of game?

Hello ladies and gents, I seem to have run into an odd problem. I have written a simple script to pull some info from the database. Outside of the game, I can perfectly pull information at will with a junk "driver" line. In game, it stops. No response, no errors, no "quest::say..." commands, nothing.

Could anyone point out the stupid mistake I've made? It's always something like a variable name typo or line termination failure.
Code:
use DBI;

my (@arr, $sth, $instanceID);
my $db = "peq";
my $user = "root";
my $pass = "password";
my $host = "127.0.0.1";
my $dsn = "DBI:mysql:database=$db:host=$host";
my $dbh = DBI->connect ($dsn, $user, $pass);


sub CheckForInstance
{
	
	
	#quest::say("Start CheckForInstance");
	# try to find an instance ID in database
	my $gID = $_[0];
	my $zID = $_[1];
	my $destroyOn;
	my $timeLeft;
	my $foundID;
	my $foundDestroy;
	my $instanceID;
	my $var;
	my $searchString = " SELECT id FROM instances WHERE guild = $gID AND zone = $zID ";
	#quest::say("$searchString");
	$sth = $dbh->prepare ($searchString);
	$sth->execute();
	
	while(@arr = $sth->fetchrow_array())
	{
		$instanceID = @arr[0];
		$foundID = 1;
		#quest::say("Found $instanceID belonging to $gID");
	}
	
	# release result set
	$sth->finish();
	
	if($foundID == 1)
	{
		# get the invite key end time
		$searchString = "SELECT destroy FROM instances WHERE id = $instanceID";
		$sth = $dbh->prepare($searchString);
		$sth->execute();
		# read data into appropriate variable(s)
		@arr = $sth->fetchrow_array();
		$destroyOn = @arr[0];
		# clean for next query
		$sth->finish();
	} else 
	{
		quest::say("Found nothing");
		return "FALSE"; 
	}
	
	if(defined($destroyOn))
	{
		$searchString = "SELECT TIME_TO_SEC(TIMEDIFF('$destroyOn', NOW()))";
		$sth = $dbh->prepare($searchString);
		$sth->execute();
		@arr = $sth->fetchrow_array();
		#while(@arr = $sth->fetchrow_array())
		#{
			$timeLeft = @arr[0];
			#printf "\n$timeLeft\n";
		#}
	
		# final release result set
		$searchString = undef;
		$sth->finish();
	} else { $timeLeft = 0; }
	
	# was an instance ID returned?
	if(($instanceID > 0) && ($timeLeft > 0))
	{
		return $instanceID;
	}
	elsif($timeLeft <= 0)
	{
		return "EXPIRED";
	}
	else
	{
		return "FALSE";
	}
	
}
Thank you so much preemptively!

-Hate
Reply With Quote
  #2  
Old 04-18-2012, 11:52 PM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,071
Default

Quote:
Originally Posted by Hateborne View Post
Hello ladies and gents, I seem to have run into an odd problem. I have written a simple script to pull some info from the database. Outside of the game, I can perfectly pull information at will with a junk "driver" line. In game, it stops. No response, no errors, no "quest::say..." commands, nothing.

Could anyone point out the stupid mistake I've made? It's always something like a variable name typo or line termination failure.
Code:
use DBI;

my (@arr, $sth, $instanceID);
my $db = "peq";
my $user = "root";
my $pass = "password";
my $host = "127.0.0.1";
my $dsn = "DBI:mysql:database=$db:host=$host";
my $dbh = DBI->connect ($dsn, $user, $pass);

CheckForInstance();

sub CheckForInstance
{
	
	
	#quest::say("Start CheckForInstance");
	# try to find an instance ID in database
	my $gID = $_[0];
	my $zID = $_[1];
	my $destroyOn;
	my $timeLeft;
	my $foundID;
	my $foundDestroy;
	my $instanceID;
	my $var;
	my $searchString = " SELECT id FROM instances WHERE guild = $gID AND zone = $zID ";
	#quest::say("$searchString");
	$sth = $dbh->prepare ($searchString);
	$sth->execute();
	
	while(@arr = $sth->fetchrow_array())
	{
		$instanceID = @arr[0];
		$foundID = 1;
		#quest::say("Found $instanceID belonging to $gID");
	}
	
	# release result set
	$sth->finish();
	
	if($foundID == 1)
	{
		# get the invite key end time
		$searchString = "SELECT destroy FROM instances WHERE id = $instanceID";
		$sth = $dbh->prepare($searchString);
		$sth->execute();
		# read data into appropriate variable(s)
		@arr = $sth->fetchrow_array();
		$destroyOn = @arr[0];
		# clean for next query
		$sth->finish();
	} else 
	{
		quest::say("Found nothing");
		return "FALSE"; 
	}
	
	if(defined($destroyOn))
	{
		$searchString = "SELECT TIME_TO_SEC(TIMEDIFF('$destroyOn', NOW()))";
		$sth = $dbh->prepare($searchString);
		$sth->execute();
		@arr = $sth->fetchrow_array();
		#while(@arr = $sth->fetchrow_array())
		#{
			$timeLeft = @arr[0];
			#printf "\n$timeLeft\n";
		#}
	
		# final release result set
		$searchString = undef;
		$sth->finish();
	} else { $timeLeft = 0; }
	
	# was an instance ID returned?
	if(($instanceID > 0) && ($timeLeft > 0))
	{
		return $instanceID;
	}
	elsif($timeLeft <= 0)
	{
		return "EXPIRED";
	}
	else
	{
		return "FALSE";
	}
	
}
Thank you so much preemptively!

-Hate

You need to execute the subroutine, and are you running this from an NPC?
Reply With Quote
  #3  
Old 04-19-2012, 12:51 AM
Hateborne
Hill Giant
 
Join Date: May 2010
Posts: 125
Default

Yes, sorry for the missing documentation

Code:
## plugin::CheckForInstance(guild_id, zone_id)
## returns $instance_id, "EXPIRED", or "FALSE" based on `destroy` field
On the quest NPC:
Code:
# $gu_ID = 1, $zo_ID = 10
my $instExists = plugin::CheckForInstance($gu_ID, $zo_ID);
-Hate
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 05:49 PM.


 

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