Heading out the door, so untested to say the least:
makecustompetnamestable.sql
Code:
DROP TABLE IF EXISTS `custom_petnames`;
CREATE TABLE `custom_petnames` (
`charid` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`charid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/quests/default.pl (insert into existing)
Code:
sub EVENT_SPAWN {
if (!$npc || $npc->GetSwarmOwner()) {
if ($npc->GetOwnerID()) {
if (defined plugin::FindPetName($npc->GetOwnerID())) {
$npc->TempName(plugin::FindPetName($npc->GetOwnerID()));
}
}
}
}
/quests/global/global_player.pl (insert into existing, working off of Tabasco's original code)
Code:
sub EVENT_SAY {
if($text =~/^!petname/i) {
my $pid = $client->GetPetID();
my $pet = $entity_list->GetMobByID($pid);
if($pet) {
($cm, $petname) = split(/\ /, $text, 2);
if ($petname =~ m/[^a-zA-Z]/){
$pet->TempName($petname);
if (plugin::FindPetName($charid) != $petname) {
plugin::EnterPetName($charid,$petname)
}
$client->Message(315, "Your pet name has been changed.");
$client->Message(315, "This is a family friendly server. Please be considerate when choosing a pet name.");
}
}
}
}
/plugins/custompetnames.pl
Code:
sub EnterPetName {
my $dbh = plugin::MySQL_Connect();
$dbh->do("DELETE FROM `custom_petnames` WHERE `charid` = '$_[0]'");
$sth = $dbh->prepare("INSERT INTO `custom_petnames` (`charid`, `petname`) VALUES (?, ?)");
$sth->execute($_[0], $_[1]);
$sth->finish();
$dbh->disconnect();
}
sub FindPetName {
my $entered_charid = $_[0];
my $dbh = plugin::MySQL_Connect();
my $sth = $dbh->prepare("SELECT `petname` FROM `custom_petnames` WHERE `charid` = '".$entered_charid."' LIMIT 1;");
$sth->execute();
@data = $sth->fetchrow_array();
$sth->finish();
$dbh->disconnect();
if ($data[0] == NULL) {
return NULL;
} else {
return ($data[0]);
}
}
May or may not work, untested and far from a master coder of things. But had 10 minutes before I had to leave out, it may help someone out. I'm very interested to see what Kingly draws up. *Thank you Kingly, I never bothered looking at the source to see qglobal value was const *char anymore (just sorta went by the way I knew them to be -- reading the changeme = a good thing), well then. My way is superfluous in that case.