SavageDeath
01-28-2013, 01:01 AM
Alright so I know this has been asked a few times before but I'm new to this so please put up with me for a bit =)
My question is how can I get Perl to pull a value from a custom table via a query? I can get it to insert new values and such into the new table I made easy enough but getting it to pull a numerical value is where I have no clue what to do. I have seen the other posts where you guys were using a fetch to pull the values, but how would I get the NPC to tell me what those values are in a say or how could I get the script to use those values as a check ?
Here is what I have.
sub EVENT_SAY {
if($text=~/Hail/i)
{
use DBI;
use DBD::mysql;
$tablename = "test";
my $connect = DBConnect();
# Create the Query
$query = "INSERT INTO $tablename (id, name, description, value) VALUES('$charid', '$name', 'test', 20)";
$query_handle = $connect->prepare($query);
$query_handle->execute();
$connect->disconnect();
}
if($text=~/try/i)
{
use DBI;
use DBD::mysql;
my $connect = DBConnect();
$query = "SELECT value FROM test WHERE id = $charid";
$query_handle = $connect->prepare($query);
$query_handle->execute();
##I'm not sure how to get it to push out what I want in a quest say here, pretty sure I need a fetch of some sort.
$connect->disconnect();
}
}
It connects and inserts a new value when I hail the NPC which is great. But I want to be able to pull the value from the value column and use it as a check. Or to tell the player oh yeah you have x amount of value in storage or whatever.
I know I can do this with globals but I rather not I was hoping to use a completely different table for it.
Any help would be greatly appreciated, if you could post an example or point me in the right direction that would be great, thanks in advance!
Note: I am aware I'm not showing where I have the database info to connect, figured that wasn't need for you guys to help. I made a sub routine for it to connect just a heads up.
My question is how can I get Perl to pull a value from a custom table via a query? I can get it to insert new values and such into the new table I made easy enough but getting it to pull a numerical value is where I have no clue what to do. I have seen the other posts where you guys were using a fetch to pull the values, but how would I get the NPC to tell me what those values are in a say or how could I get the script to use those values as a check ?
Here is what I have.
sub EVENT_SAY {
if($text=~/Hail/i)
{
use DBI;
use DBD::mysql;
$tablename = "test";
my $connect = DBConnect();
# Create the Query
$query = "INSERT INTO $tablename (id, name, description, value) VALUES('$charid', '$name', 'test', 20)";
$query_handle = $connect->prepare($query);
$query_handle->execute();
$connect->disconnect();
}
if($text=~/try/i)
{
use DBI;
use DBD::mysql;
my $connect = DBConnect();
$query = "SELECT value FROM test WHERE id = $charid";
$query_handle = $connect->prepare($query);
$query_handle->execute();
##I'm not sure how to get it to push out what I want in a quest say here, pretty sure I need a fetch of some sort.
$connect->disconnect();
}
}
It connects and inserts a new value when I hail the NPC which is great. But I want to be able to pull the value from the value column and use it as a check. Or to tell the player oh yeah you have x amount of value in storage or whatever.
I know I can do this with globals but I rather not I was hoping to use a completely different table for it.
Any help would be greatly appreciated, if you could post an example or point me in the right direction that would be great, thanks in advance!
Note: I am aware I'm not showing where I have the database info to connect, figured that wasn't need for you guys to help. I made a sub routine for it to connect just a heads up.