EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Script using DBI does nothing in game, works out of game? (https://www.eqemulator.org/forums/showthread.php?t=35216)

Hateborne 04-18-2012 11:46 PM

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

Akkadius 04-18-2012 11:52 PM

Quote:

Originally Posted by Hateborne (Post 209001)
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?

Hateborne 04-19-2012 12:51 AM

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


All times are GMT -4. The time now is 06:30 PM.

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