|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quests::Q&A This is the quest support section |
03-12-2016, 05:04 PM
|
Banned
|
|
Join Date: Aug 2010
Location: Sanctuary
Posts: 269
|
|
Pet Naming Script
Would anyone happen to have a pet renaming script they could share? Looking for a way to let players rename their summoned pets.
|
|
|
|
03-12-2016, 09:44 PM
|
|
Discordant
|
|
Join Date: Sep 2009
Posts: 269
|
|
This comes from intercepting a command like !petname <name>. I was flowing those through a universal world script at the time so that a player could just type it in chat without needing an NPC receiver, but these days I gather there are more convenient ways to do it.
Code:
if($text =~/^!petname/i)
{
my $pid = $client->GetPetID();
my $pet = $entity_list->GetMobByID($pid);
if($pet)
{
($cm, $petname) = split(/\ /, $text, 2);
$pet->TempName($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.");
}
}
While we're at this, I also see I had a pet size function.
Code:
if($text =~/^!petsize/i)
{
my $pid = $client->GetPetID();
my $pet = $entity_list->GetMobByID($pid);
if($pet)
{
my $cursize = $pet->GetSize();
($cm, $petsize) = split(/\ /, $text, 2);
if ($petsize > 9)
{
$petsize = 9; ## Not abnormally large
}
if ($petsize < 1)
{
$petsize = 1; ## Not abnormally small
}
$newsize = $petsize - $cursize;
$pet->ChangeSize($petsize);
$client->Message(315, "Your pet's size has been changed.");
$client->Message(315, "Please do not abuse this function. Extremely large pets can lag the zone and cause issues for other people.");
}
}
|
|
|
|
03-12-2016, 10:50 PM
|
|
Legendary Member
|
|
Join Date: Apr 2002
Location: Seattle, WA
Posts: 506
|
|
Doesn't stay after zoning I assume, nor does it retain after relogging, right?
|
03-13-2016, 06:14 AM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,594
|
|
You could just use a permanent quest global with a custom #-based Perl command. Don't have time to write an example right now, but if I get some time and you don't have it done I'll write it up for you.
|
03-13-2016, 02:49 PM
|
Banned
|
|
Join Date: Aug 2010
Location: Sanctuary
Posts: 269
|
|
That sounds like a really cool way of doing it, Kingly. Right now I'm using a temporary naming script but your way sounds much nicer. If you get the chance, I would love to see what you come up with
|
|
|
|
03-13-2016, 06:04 PM
|
|
Dragon
|
|
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
|
|
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.
|
|
|
|
|
|
|
03-13-2016, 08:54 PM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,594
|
|
Untested, but try this.
global_player.pl:
Code:
sub EVENT_SAY {
if ($text=~/#Rename/i) {
if ($client->GetTarget() && $client->GetTarget()->IsNPC() && $client->GetTarget()->CastToNPC()->GetOwnerID() == $userid) {
quest::setglobal("PetName", substr($text, 8, 64), 5, "F");
$client->GetTarget()->TempName(substr($text, 8, 64));
$client->Message(315, "Your pet's name is now set to " . substr($text, 8, 64) . ", upon respawning your pet will instantly be renamed from now on.");
} else {
$client->Message(315, "You must target your pet first.");
}
}
}
sub EVENT_SIGNAL {
if ($signal == 2) {
if (defined $qglobals{"NewName"} && length($qglobals{"NewName"}) > 0) {
$entity_list->GetMobByID($client->GetPetID())->TempName($qglobals{"TempName"});
$client->Message(315, "Your pet has been instantly renamed to '" . $qglobals{"TempName"} . "'.");
}
}
}
global_npc.pl:
Code:
sub EVENT_SPAWN {
if ($npc->GetOwnerID() > 0 && $entity_list->GetMobByID($npc->GetOwnerID())->IsClient()) {
quest::settimer("Rename", 5);
}
}
sub EVENT_TIMER {
if ($timer eq "Rename") {
quest::stoptimer("Rename");
$entity_list->GetClientByID($npc->GetOwnerID())->SignalClient(2);
}
}
|
|
|
|
03-13-2016, 09:25 PM
|
|
Administrator
|
|
Join Date: Feb 2009
Location: MN
Posts: 2,071
|
|
Someone should just implement this in the source, it would be super simple.
#command, save to DB, make it a rule based feature
|
|
|
|
03-19-2016, 05:37 PM
|
|
Hill Giant
|
|
Join Date: Dec 2013
Posts: 151
|
|
This is my old pet naming code. I can post the rest of it if anyone even cares.
Code:
void command_petname(Client *c, const Seperator *sep) {
uint32 t = c->GetPTimers().GetRemainingTime(pTimerAntiQuery);
if (!c->GetPTimers().Expired(&database, pTimerAntiQuery, false)) {
c->Message(13, "You must wait (%is) before renaming your pet.", t);
return;
}
int MAX_PET_NAME = 12;
int MIN_PET_NAME = 3;
if (sep->arg[1][0] == 0) {
c->Message(15, "Clearing current pet name.");
std::string query = StringFormat("REPLACE INTO `pets_custom_name` VALUES (%i, '')", c->CharacterID());
auto results = database.QueryDatabase(query);
c->GetPTimers().Start(pTimerAntiQuery, 30);
return;
}
for (int i = 0; i < MAX_PET_NAME; i++) {
if (sep->arg[1][i] == NULL) {
break;
}
if (!isalpha(sep->arg[1][i])) {
c->Message(13, "Pet names must only contain letters of the alphabet.");
return;
}
if (isupper(sep->arg[1][i])) {
sep->arg[1][i] = tolower(sep->arg[1][i]);
}
}
if (strlen(sep->arg[1]) >= MAX_PET_NAME) {
c->Message(13, "The pet name you've entered is too long. (Maximum: %i)", MAX_PET_NAME);
}
else if (strlen(sep->arg[1]) < MIN_PET_NAME && strlen(sep->arg[1]) > 0) {
c->Message(13, "The pet name you've entered is too short. (Minimum: %i)", MIN_PET_NAME);
}
else {
sep->arg[1][0] = toupper(sep->arg[1][0]);
c->Message(15, "Your new pet will now be named: %s", sep->arg[1]);
std::string query = StringFormat("REPLACE INTO `pets_custom_name` VALUES (%i, '%s')", c->CharacterID(), sep->arg[1]);
auto results = database.QueryDatabase(query);
c->GetPTimers().Start(pTimerAntiQuery, 30);
}
}
__________________
"The true sign of intelligence is not knowledge but imagination."
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 09:30 PM.
|
|
|
|
|
|
|
|
|
|
|
|
|