PDA

View Full Version : Buff Bot re-creation NPC getclass() Help


Figback65
02-12-2013, 02:27 PM
There is a post on here for an awsome buff bot

http://www.eqemulator.org/forums/showthread.php?t=29401

I am trying to take this a step further but my still growing limit script knowledge is leaving me in the dust.

I have a spawngroup cycle that spawns my buff bot. Sometimes it spawns as different classes, so when It spawns I want it to be able to only cast spells from the class it spawned as and with a player(not npc) level check so a level 1 player cannot get clarity 2 because he is too low lvl. I am posting what I have done so far and hoping im on the right track lol.

#Credit goes to Sylaei for the original creation of this buff bot! Thank you Sylaei 08-31-2009
#Edited by Fig to suit VCR server needs. 02-02-2013

sub EVENT_SPAWN {
my $Ench = ($npc->GetClass() == 'Enchanter');
my $Necro = ($npc->GetClass() == 'Necromancer');

if ($npc->GetClass() == 'Enchanter') {
@SpellList = ("Bind Affinity","Breeze","Clarity","Clarity II","Alacrity","Augment","Aanya's Quickening","Rune I");
@SpellCost = ("10","25","50","200","10","30","100","5");
@SpellID = ("35","697","174","1693","170","1729","1708","481");

}

else ($npc->GetClass == 'Necromancer') {
@SpellList = ("Dead Men Floating");
@SpellCost = ("10");
@SpellID = ("1391");
}

}


sub EVENT_SAY {
my $buffs = quest::saylink("buffs", 1);
my $NPCName = $npc->GetCleanName();
if ($text =~/Hail/i) {
$client->Message(315, "Chip Chip $name, Do you need some $buffs?'");
}

#Counts each row for the While
my $count = 1;
#Counts each element in the Array for the While
my $n = 0;

if ($text !~ /Hail/i) && $Ench {
while ($SpellList[$n]) {
#This searches the list to find possible matches. The lc() command makes all text lowercase.
#It is easier to make all text lower case for comparison, if the user types uppercase it will still match.
if ((lc($SpellList[$n]) =~ lc($text) && lc($SpellList[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $SpellList = quest::saylink($SpellList[$n]);
$client->Message(315, "These are your choices, $SpellList");
}
#This is the command that is executed when a the user enters a spell.
if (lc($SpellList[$n]) eq lc($text) && $text !~ /^buffs$/i) {
#Creates a global variable. You must set the qgolbal field in the npc_types table to 1 for each npc you wish to handle global variables.
#buff is the name, $text is what the varible should be eq too, 0 only this npc, char, and zone apply to the variable, M5 is 5 minutes.
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}
}


elsif ($text !~ /Hail/i) && $Necro {
while ($SpellList[$n]) {
#This searches the list to find possible matches. The lc() command makes all text lowercase.
#It is easier to make all text lower case for comparison, if the user types uppercase it will still match.
if ((lc($SpellList[$n]) =~ lc($text) && lc($SpellList[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $SpellList = quest::saylink($SpellList[$n]);
$client->Message(315, "These are your choices, $SpellList");
}
#This is the command that is executed when a the user enters a spell.
if (lc($SpellList[$n]) eq lc($text) && $text !~ /^buffs$/i) {
#Creates a global variable. You must set the qgolbal field in the npc_types table to 1 for each npc you wish to handle global variables.
#buff is the name, $text is what the varible should be eq too, 0 only this npc, char, and zone apply to the variable, M5 is 5 minutes.
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}
}
}



I do not have the level checks placed anywhere because honestly i have no clue where to put the check lol.
As always any and all feedback and suggestions appreciated :)

Edit: Its having a problem calling the correct spell list. I am pretty sure I cannot call my $Ench = ($npc->GetClass() == 'Enchanter'); from sub EVENT_SPAWN to sub EVENT_SAY. Also I think my IF statement under EVENT_SAY could be changed to something like if If ($npc->GetClass() == 'Enchanter') || ($npc->GetClass() == 'Enchanter')

brain hurts

Zamthos
02-12-2013, 04:21 PM
Why'd you do this?: Shouldn't it be elsif? Just try using the syntax checker, errors below. I pasted exactly what you posted and got those errors, nothing extra, nothing less.
else ($npc->GetClass == 'Necromancer') {
@SpellList = ("Dead Men Floating");
@SpellCost = ("10");
@SpellID = ("1391");
}


syntax error at Test.pl line 12, near "else ("
syntax error at Test.pl line 18, near "}"
syntax error at Test.pl line 33, near ") &&"
syntax error at Test.pl line 40, near "}"
syntax error at Test.pl line 47, near "}"
syntax error at Test.pl line 50, near "}"
syntax error at Test.pl line 61, near "}"
syntax error at Test.pl line 68, near "}"
syntax error at Test.pl line 71, near "}"

If you want to keep using else, I think this will work, haven't tested.
else
{
@SpellList = ("Dead Men Floating");
@SpellCost = ("10");
@SpellID = ("1391");
}

Zamthos
02-12-2013, 04:56 PM
No syntax error with this, haven't tested it in the game, but here you go:

sub EVENT_SPAWN {
my $Ench = ($npc->GetClass() == 'Enchanter');
my $Necro = ($npc->GetClass() == 'Necromancer');

if ($npc->GetClass() == 'Enchanter') {
@SpellList = ("Bind Affinity","Breeze","Clarity","Clarity II","Alacrity","Augment","Aanya's Quickening","Rune I");
@SpellCost = ("10","25","50","200","10","30","100","5");
@SpellID = ("35","697","174","1693","170","1729","1708","481");

}

else {
@SpellList = ("Dead Men Floating");
@SpellCost = ("10");
@SpellID = ("1391");
}

}


sub EVENT_SAY {
my $buffs = quest::saylink("buffs", 1);
my $NPCName = $npc->GetCleanName();
if ($text =~/Hail/i) {
$client->Message(315, "Chip Chip $name, Do you need some $buffs?'");
}

my $count = 1;
my $n = 0;

if (($text=~/Hail/i)&& ($Ench)) {
while ($SpellList[$n]) {
if ((lc($SpellList[$n]) =~ lc($text) && lc($SpellList[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $SpellList = quest::saylink($SpellList[$n]);
$client->Message(315, "These are your choices, $SpellList");
}
if (lc($SpellList[$n]) eq lc($text) && $text !~ /^buffs$/i) {
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}
}


elsif (($text=~/Hail/i) && ($Necro)) {
while ($SpellList[$n]) {
if ((lc($SpellList[$n]) =~ lc($text) && lc($SpellList[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $SpellList = quest::saylink($SpellList[$n]);
$client->Message(315, "These are your choices, $SpellList");
}
if (lc($SpellList[$n]) eq lc($text) && $text !~ /^buffs$/i) {
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}
}
}

Figback65
02-12-2013, 05:58 PM
[QUOTE=Zamthos;218075]Why'd you do this?: Shouldn't it be elsif? Just try using the syntax checker, errors below. I pasted exactly what you posted and got those errors, nothing extra, nothing less.
else ($npc->GetClass == 'Necromancer') {
@SpellList = ("Dead Men Floating");
@SpellCost = ("10");
@SpellID = ("1391");
}


I can use elsif, I am still learning. I will be adding more classes than enchanter and necro, but this was just a starting point.

I tested it with elsif and if neither worked, the NPC doesnt talk so I think im missing a link calling the proper list somewhere down in sub EVENT_SAY but im still tryen to find it lol
Here is with 3 class options for more clarification.

sub EVENT_SPAWN {
my $Ench = ($npc->GetClass() == 'Enchanter');
my $Necro = ($npc->GetClass() == 'Necromancer');
my $Cleric = ($npc->GetClass() == 'Cleric');

if ($npc->GetClass() == 'Enchanter') {
@SpellList = ("Bind Affinity","Breeze","Clarity","Clarity II","Alacrity","Augment","Aanya's Quickening","Rune I");
@SpellCost = ("10","25","50","200","10","30","100","5");
@SpellID = ("35","697","174","1693","170","1729","1708","481");
}

if ($npc->GetClass == 'Necromancer') {
@SpellList = ("Dead Men Floating");
@SpellCost = ("10");
@SpellID = ("1391");
}

if ($npc->GetClass == 'Cleric') {
@SpellList = ("Daring");
@SpellCost = ("5");
@SpellID = ("89");
}

}

Drajor
02-12-2013, 09:10 PM
Hiya Fig,

Related post about dealing with class types: http://www.eqemulator.org/forums/showthread.php?t=35970

Figback65
02-12-2013, 10:23 PM
Hiya Fig,

Related post about dealing with class types: http://www.eqemulator.org/forums/showthread.php?t=35970

Thank you for the post.

My problem currently is Having the EVENT_SAY check what class the buffnpc spawned as, then selecting the correct spelllist based on the class. Then all in all, the correct syntax so it works. I am reading your post thoroughly to see if I typed something wrong on calling the classes.

TY!!!

c0ncrete
02-14-2013, 12:35 AM
use 5.012;
use warnings;

package NPC;

sub new {
my ( $class, %param ) = ( shift, @_ );
$param{_class} = 14;
return bless \%param, $class;
}

sub GetClass {
shift->{_class};
}

package main;

my $npc = NPC->new();

# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# hashref containing buffs offered depening on the class of the npc
my $buff = {
Enchanter => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
Necromancer => [ [ "Dead Men Floating", 1391, 10 ], ],
};

# this is what the client said (used to search available buffs)
my $text = "la";

# this is how we find out long name of the class the npc is
my $mclass = (CLASS_L)[ $npc->GetClass() ];

# this searches the array of available buffs and returns only those that match
foreach my $spell ( grep { ${$_}[0] =~ /$text/i } @{ $buff->{$mclass} } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
say "I can cast $spellName [$spellID] on you for $spellCost platinum.";
}


results:

I can cast Clarity [174] on you for 50 platinum.
I can cast Clarity II [1693] on you for 200 platinum.
I can cast Alacrity [170] on you for 10 platinum.

Figback65
02-14-2013, 01:32 PM
Awsome c0ncrete!!! I am going to test that out right now! Here is the script me and Ghanja was working on as well. I got the npcs to respond to hail's with the proper class response but calling the correct spell list was not working... lol. Here is that script of a mess.

use strict;
no strict 'vars';
use warnings;


sub EVENT_SAY {
my $Necro = {
@spelllist => ["Bind Affinity","Dead Men Floating"],
@spellcost => [10,10],
@spellid => [35,1391],
},
my $Ench = {
@spelllist => ["Bind Affinity","Breeze","Clarity","Clarity II","Alacrity","Augment","Aanya's Quickening","Rune I"],
@spellcost => [10,25,50,200,10,30,100,5],
@spellid => [35,697,174,1693,170,1729,1708,481],
},
my $Magi = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Wiz = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Rog = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Ranger = {
@spelllist => ["Bind Affinity",],
@spellcost => [10],
@spellid => [35],
},
my $Druid = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Shaman = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Cleric = {
@spelllist => ["Bind Affinity","Daring"],
@spellcost => [10,5],
@spellid => [35,89],
},
my $SK = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Paladin = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Ber = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Bst = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $War = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},
my $Bard = {
@spelllist => ["Bind Affinity"],
@spellcost => [10],
@spellid => [35],
},

my $cleanclass = $npc->GetClass();


if ($text=~/hail/i) {
my $buffs = quest::saylink("buffs", 1);
my $NPCName = $npc->GetCleanName();
my $count = 1;
my $n = 0;

if($cleanclass eq 11) {
$client->Message(315, "Souls and $buffs.'");
while ($Necro[$n]) {
if ((lc($Spelllist[$n]) =~ lc($text) && lc($Spelllist[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $Spelllist = quest::saylink($Spelllist[$n]);
$client->Message(315, "These are your choices, $buffs");
}
if (lc($Spelllist[$n]) eq lc($text) && $text !~ /^buffs$/i) {
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}
}

elsif ($cleanclass eq 14) {
quest::say("I have the $buffs for your mind.");
while ($Ench[$n]) {
if ((lc($Ench[$n]) =~ lc($text) && lc($Ench[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $Ench = quest::saylink($Ench[$n]);
$client->Message(315, "These are your choices, $Ench");
}
if (lc($Ench[$n]) eq lc($text) && $text !~ /^buffs$/i) {
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}


}

elsif ($cleanclass eq 13) {
quest::say("I will summon you no $buffs.");
}

elsif ($cleanclass eq 12) {
quest::say("Wizard $buffs? Hah! Where do you need to go?");
}

elsif ($cleanclass eq 9) {
quest::say("shhhhhhhhhhhhhhhh!");
}

elsif ($cleanclass eq 4) {
quest::say("What can I do for you naturewalker? Do you require some $buffs?");
}

elsif ($cleanclass eq 6) {
quest::say("I $buffs you to protect my animals!");
}

elsif ($cleanclass eq 10) {
quest::say("All the best $buffs bring the best money.");
}

elsif ($cleanclass eq 2) {
quest::say("Heals? $buffs?");
while ($Cleric[$n]) {
if ((lc($Cleric[$n]) =~ lc($text) && lc($Cleric[$n]) ne lc($text)) || ($text =~ /^buffs$/i)) {
my $Cleric = quest::saylink($Cleric[$n]);
$client->Message(315, "These are your choices, $SpellList");
}
if (lc($Cleric[$n]) eq lc($text) && $text !~ /^buffs$/i) {
quest::setglobal("buffs", $text, 0, "M5");
$client->Message(315, "That's going to cost $SpellCost[$n]pp for the $qglobals{buffs} buff.");
}
$n++;
$count++;
}
}

elsif ($cleanclass eq 5) {
quest::say("No $buffs here, only death!");
}

elsif ($cleanclass eq 3) {
quest::say("Do you need protection my child or some $buffs?");
}

elsif ($cleanclass eq 16) {
quest::say(".......");
}

elsif ($cleanclass eq 15) {
quest::say("Paragon, Feral, $buffs");
}

elsif ($cleanclass eq 1) {
quest::say("Kidding, right?");
}

elsif ($cleanclass eq 8) {
quest::say("La Ti Da Ti");
}


}



}

ghanja
02-14-2013, 02:28 PM
No no, ghanja wasn't working on that one bud.


my $buffs = {
enchanter => {
spelllist => ["Bind Affinity","Breeze","Clarity","Clarity II","Alacrity","Augment","Aanya's Quickening","Rune I"],
spellcost => [10,25,50,200,10,30,100,5],
spellid => [35,697,174,1693,170,1729,1708,481]
},
necromancer => {
spelllist => ["Dead Men Floating"],
spellcost => [10],
spellid => [1391]
},
};


Should be in the last one we were working on. However, the use of grep you may be better off with.

Now using the above and the references I pointed out the other night, tie it all together.

Figback65
02-14-2013, 03:25 PM
Cool, thanks very much guys, ill work on it for a few days and then update!

c0ncrete
02-14-2013, 03:31 PM
use 5.012;
no strict 'vars';
use warnings;

### IGNORE EVERYTHING BELOW HERE ###

package NPC;

sub new {
my ( $class, %param ) = ( shift, @_ );
$param{_class} = 14;
return bless \%param, $class;
}

sub GetClass {
shift->{_class};
}

package main;

my $npc = NPC->new();

sub quest::saylink {
shift;
}

sub quest::say {
say shift;
}

# this is what the client said (used to search available buffs)
my $text = "Clarity II";

### IGNORE EVERYTHING ABOVE HERE ###

# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# saylink
my $buffs = quest::saylink( "buffs", 1 );

# hashref containing buffs offered depening on the class of the npc
my $data = {
Enchanter => {
greet => "I have the $buffs for your mind.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
},
Necromancer => {
greet => "Souls and $buffs.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],
],
},
};

# get class-specific stuff for this npc
my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $greeting = $data->{$npcClass}->{greet};
my $buffList = $data->{$npcClass}->{buffs};

sub EVENT_SAY {
if ( $text =~ /hail/i ) {
quest::say($greeting);
return;
}
given ( [ grep { ${$_}[0] =~ /$text/i } @{$buffList} ] ) {

# one exact match (probably clicked on saylink in list)
when ( @{$_} == 1 && $text eq ${$_}[0][0] ) {
say "That will be ${$_}[0][2]pp for ${$_}[0][0].";
}

# client typed targeted text that did not match hail and
# more than one available spell name matched recieved text
# TODO: create saylinks
when ( @{$_} > 1 ) {
foreach my $spell ( @{$_} ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
say "I can cast $spellName on you for ${spellCost}pp.";
}
}
}
}

### IGNORE EVERYTHING BELOW HERE ###

EVENT_SAY();


you can change the value of $text in this and run it outside of the emulator to see the results.
change $param{_class} to whatever class you want the npc to be.

nyquil is kicking in. you're on your own for a bit...

Figback65
02-14-2013, 04:32 PM
change $param{_class} to whatever class you want the npc to be.




The NPC is in a spawngroup of multiple classes. So when it dies or respawns, the script will determine which class it spawned as and set the spell list for that class....
$param{_class} = $npc->GetClass(); ?

Now by your comment, are you suggesting that I need to change it manually in the script to force a spell list, by the way you have coded it.

This is the 1st time I have seen packages and some syntax you are using, I am googling and researching all I can to understand what you have given. Going to need some time to learn all of this lol.

Edit: And hash tables

c0ncrete
02-14-2013, 04:54 PM
there is a reason i put the comments about ignoring what was above and below a certain point....

the code within those areas was just put there to emulate the behavior of the script being run via the server. if you were to run this script as it is written from a command prompt, you will see a near identical example of how it would work from inside the game. i was letting you know the things you would need to change if you were running it outside of the game so you could see the different results, depending upon a given scenario (client said / npc class is).

to get it to work in the game, you'd remove the lines that are inside the areas designated for you to ignore and change the remaining say lines to quest::say(), $client->Message(), or whatever other message delivery function you would want to use.

Figback65
02-14-2013, 06:03 PM
Thank you for explaining, i understand. I have not done any perl outside of eqemu rofl

c0ncrete
02-14-2013, 07:35 PM
the script you're trying to modify is one of the most convoluted ones i've seen.

also, there's lots of good (and free) reading to be found here:

http://www.perl.org/books/library.html

c0ncrete
02-14-2013, 09:17 PM
tested for syntax, not functionality.

# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# saylink
my $buffs = quest::saylink( "buffs", 1 );

# hashref containing buffs offered depening on the class of the npc
my $data = {
Enchanter => {
greet => "I have the $buffs for your mind.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
},
Necromancer => {
greet => "Souls and $buffs.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],
],
},
};

# get class-specific stuff for this npc
my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $greeting = $data->{$npcClass}->{greet};
my $buffList = $data->{$npcClass}->{buffs};

sub EVENT_SAY {

# matches hail
if ( $text =~ /hail/i ) { quest::say($greeting); }

# doesn't match hail, but does match something in buff list
elsif ( my @match = grep { ${$_}[0] =~ /$text/i } @{$buffList} ) {

# single, exact match in buff list.
if ( @match == 1 && $text eq $match[0][0] ) {
my ( $spellName, $spellID, $spellCost ) = @{ $match[0] };
$client->Message( 315,
"That will be ${spellCost}pp for $spellName." );
quest::setglobal( "buff", $text, 0, "M5" );
}

# more than one match in buff list. list them.
else { CanCast( \@match ); }
}

# defaut to listing all buffs this npc can cast.
else { CanCast($buffList); }
}

sub EVENT_ITEM {

my $correctMoney = 0;

# if client has selected a buff
if ( defined $qglobals{buff} ) {

# find the buff selected
foreach my $spell ( @{$buffList} ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};

# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} != $spellName || $platinum != $spellCost;
$client->Message( 315,
"Thank you for the ${spellCost}pp. Prepare for $spellName!" );
$npc->CastSpell( $spellID, $client->GetID() );
$correctMoney = 1;
quest::delglobal("buff");
last;
}
}

# incorrect amount of money given or no qglobal for buff found for client
if ( !$correctMoney && ( $copper || $silver || $gold || $platinum ) ) {
$client->Message( 315,
"I don't need these coins. You may have them back." );
quest::givecash( $copper, $silver, $gold, $platinum );
}
}

sub CanCast {
foreach my $spell ( @{ +shift } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
my $buffLink = quest::saylink( $spellName, 1 );
$client->Message( 315,
"I can cast $buffLink on you for ${spellCost}pp." );
}
}

Figback65
02-14-2013, 09:42 PM
I am trying, i cannot get it to work in game. I cannot see where sub EVENT_SAY calls the class specification to know which list to call. I am looking for another $npcClass to do the trick but obviously theres something i do not understand. Currently the NPC does not respond to a hail.


Edit: I dunno what I did, but I just got a response from a hail. It is blank, it is not pulling my $greeting = $data->{$npcClass}->{greet}; but its a start. Going to work on it some more, will update.

Edit2: I know what i did to fix, I took out the use 5.012 and use warnings ,I read you needed to use those for the given and when statements if thats the correct term. But noticed you took those out as well.

c0ncrete
02-14-2013, 09:53 PM
everything that sets the class specific info for the current npc happens here (outside of any subroutine):

# get class-specific stuff for this npc
my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $greeting = $data->{$npcClass}->{greet};
my $buffList = $data->{$npcClass}->{buffs};

paste your full script (unless you're only using exactly what i posted).

nevermind. just saw your update. :)

c0ncrete
02-14-2013, 10:01 PM
oops.

change this
# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} != $spellName || $platinum != $spellCost;

to this
# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} ne $spellName || $platinum != $spellCost;

Figback65
02-14-2013, 10:18 PM
Ok change done. Still does not pull the greet. I am reading on arrays from the one of the books off the perl site you linked. lol light reading :)

Edit: But the npc is definately responding to the hail, he turns and does the Buffbot says. "

c0ncrete
02-14-2013, 10:30 PM
probably something to do with that saylink quirkiness. looking at the source for that now.

Figback65
02-14-2013, 10:38 PM
Lol I changed

Necromancer => {
greet => [quest::say("Souls and $buffs.")],
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],


Now the npc responds on hail and says Souls and Buffs(broke link) and on a 2nd line also still says the blank.

Edit: Getting closer! :)

Figback65
02-14-2013, 10:54 PM
Well when I had only changed the necro greet, it worked, then i changed the ench also and repopped the zone to spawn the buffbot as ench, zone.exe crashes. had to take the quest::say out.

c0ncrete
02-14-2013, 10:58 PM
that syntax is wrong, but it was good effort. this moves all of the calls to quest::saylink into EVENT_SAY per notes here:

http://www.eqemulator.net/wiki/wikka.php?wakka=SayLink

# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# hashref containing buffs offered depening on the class of the npc
my $data = {
Enchanter => {
greet => "I have the %s for your mind.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
},
Necromancer => {
greet => "Souls and %s.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],
],
},
};

# get class-specific stuff for this npc
my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $greeting = $data->{$npcClass}->{greet};
my $buffList = $data->{$npcClass}->{buffs};

sub EVENT_SAY {

# saylink
my $buffs = quest::saylink( "buffs", 1 );

my $CanCast = sub {
foreach my $spell ( @{ +shift } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
my $buffLink = quest::saylink( $spellName, 1 );
$client->Message( 315,
"I can cast $buffLink on you for ${spellCost}pp." );
}
};

# matches hail
if ( $text =~ /hail/i ) { quest::say( sprintf $greeting, $buffs); }

# doesn't match hail, but does match something in buff list
elsif ( my @match = grep { ${$_}[0] =~ /$text/i } @{$buffList} ) {

# single, exact match in buff list.
if ( @match == 1 && $text eq $match[0][0] ) {
my ( $spellName, $spellID, $spellCost ) = @{ $match[0] };
$client->Message( 315,
"That will be ${spellCost}pp for $spellName." );
quest::setglobal( "buff", $text, 0, "M5" );
}

# more than one match in buff list. list them.
else { $CanCast->( \@match ); }
}

# defaut to listing all buffs this npc can cast.
else { $CanCast->($buffList); }
}

sub EVENT_ITEM {

my $correctMoney = 0;

# if client has selected a buff
if ( defined $qglobals{buff} ) {

# find the buff selected
foreach my $spell ( @{$buffList} ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};

# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} ne $spellName || $platinum != $spellCost;
$client->Message( 315,
"Thank you for the ${spellCost}pp. Prepare for $spellName!" );
$npc->CastSpell( $spellID, $client->GetID() );
$correctMoney = 1;
quest::delglobal("buff");
last;
}
}

# incorrect amount of money given or no qglobal for buff found for client
if ( !$correctMoney && ( $copper || $silver || $gold || $platinum ) ) {
$client->Message( 315,
"I don't need these coins. You may have them back." );
quest::givecash( $copper||0, $silver||0, $gold||0, $platinum||0 );
}
}

the greetings have a %s where the saylink "buffs" will be inserted during the call to sprintf.

Figback65
02-14-2013, 11:07 PM
Use of uninitliazed value $greeting in sprintf line 51

c0ncrete
02-14-2013, 11:18 PM
that'll happen when the NPC is of a class that isn't covered in the hash ref.

to cover those issues, change this
my $greeting = $data->{$npcClass}->{greet};
to this
my $greeting = $data->{$npcClass}->{greet} || "Got %s?";

Figback65
02-14-2013, 11:36 PM
I only test the script on enchanter and necro bc that is the only 2 with a spelllist. I added what you suggested and i still get the error.

c0ncrete
02-14-2013, 11:40 PM
copy and paste the whole script you have now.

Figback65
02-14-2013, 11:56 PM
# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# hashref containing buffs offered depening on the class of the npc
my $data = {
Enchanter => {
greet => "I have the %s for your mind.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
},
Necromancer => {
greet => "Souls and %s.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],
],
},
};

# get class-specific stuff for this npc
my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $greeting = $data->{$npcClass}->{greet} || "Got %s?";
my $buffList = $data->{$npcClass}->{buffs};

sub EVENT_SAY {

# saylink
my $buffs = quest::saylink( "buffs", 1 );

my $CanCast = sub {
foreach my $spell ( @{ +shift } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
my $buffLink = quest::saylink( $spellName, 1 );
$client->Message( 315,
"I can cast $buffLink on you for ${spellCost}pp." );
}
};

# matches hail
if ( $text =~ /hail/i ) { quest::say( sprintf $greeting, $buffs); }

# doesn't match hail, but does match something in buff list
elsif ( my @match = grep { ${$_}[0] =~ /$text/i } @{$buffList} ) {

# single, exact match in buff list.
if ( @match == 1 && $text eq $match[0][0] ) {
my ( $spellName, $spellID, $spellCost ) = @{ $match[0] };
$client->Message( 315,
"That will be ${spellCost}pp for $spellName." );
quest::setglobal( "buff", $text, 0, "M5" );
}

# more than one match in buff list. list them.
else { $CanCast->( \@match ); }
}

# defaut to listing all buffs this npc can cast.
else { $CanCast->($buffList); }
}

sub EVENT_ITEM {

my $correctMoney = 0;

# if client has selected a buff
if ( defined $qglobals{buff} ) {

# find the buff selected
foreach my $spell ( @{$buffList} ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};

# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} ne $spellName || $platinum != $spellCost;
$client->Message( 315,
"Thank you for the ${spellCost}pp. Prepare for $spellName!" );
$npc->CastSpell( $spellID, $client->GetID() );
$correctMoney = 1;
quest::delglobal("buff");
last;
}
}

# incorrect amount of money given or no qglobal for buff found for client
if ( !$correctMoney && ( $copper || $silver || $gold || $platinum ) ) {
$client->Message( 315,
"I don't need these coins. You may have them back." );
quest::givecash( $copper||0, $silver||0, $gold||0, $platinum||0 );
}
}

c0ncrete
02-15-2013, 12:07 AM
hrm... did you #repop after #reloadpl?

Figback65
02-15-2013, 12:11 AM
yes, #reloadpl and #repop and #repop force

c0ncrete
02-15-2013, 01:19 AM
this works.

i think it might have had something to do with scope and assigning a value to $npcClass by way of the constant. it was an empty string until i moved the declarations of that and $buffList inside of the scopes they were used. the same does not apply to $data, however.


use 5.012;
no strict 'vars';
use warnings;

# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# hashref containing buffs offered depening on the class of the npc
my $data = {
Enchanter => {
greet => "I have the %s for your mind.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
},
Necromancer => {
greet => "Souls and %s.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],
],
},
};

sub EVENT_SAY {

my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $greeting = $data->{$npcClass}->{greet} || "Got %s?";
my $buffList = $data->{$npcClass}->{buffs};

# saylink
my $buffs = quest::saylink( "buffs", 1 );

my $CanCast = sub {
foreach my $spell ( @{ +shift } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
my $buffLink = quest::saylink( $spellName, 1 );
$client->Message( 315,
"I can cast $buffLink on you for ${spellCost}pp." );
}
};

# matches hail
if ( $text =~ /hail/i ) { quest::say( sprintf $greeting, $buffs); }

# doesn't match hail, but does match something in buff list
elsif ( my @match = grep { ${$_}[0] =~ /$text/i } @{$buffList} ) {

# single, exact match in buff list.
if ( @match == 1 && $text eq $match[0][0] ) {
my ( $spellName, $spellID, $spellCost ) = @{ $match[0] };
$client->Message( 315,
"That will be ${spellCost}pp for $spellName." );
quest::setglobal( "buff", $text, 0, "M5" );
}

# more than one match in buff list. list them.
else { $CanCast->( \@match ); }
}

# defaut to listing all buffs this npc can cast.
else { $CanCast->($buffList); }
}

sub EVENT_ITEM {

my $npcClass = (CLASS_L)[ $npc->GetClass() ];
my $buffList = $data->{$npcClass}->{buffs};

my $correctMoney = 0;

# if client has selected a buff
if ( defined $qglobals{buff} ) {

# find the buff selected
foreach my $spell ( @{$buffList} ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};

# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} ne $spellName || $platinum != $spellCost;
$client->Message( 315,
"Thank you for the ${spellCost}pp. Prepare for $spellName!" );
$npc->CastSpell( $spellID, $client->GetID() );
$correctMoney = 1;
quest::delglobal("buff");
last;
}
}

# incorrect amount of money given or no qglobal for buff found for client
if ( !$correctMoney && ( $copper || $silver || $gold || $platinum ) ) {
$client->Message( 315,
"I don't need these coins. You may have them back." );
quest::givecash( $copper||0, $silver||0, $gold||0, $platinum||0 );
}
}

Figback65
02-15-2013, 01:41 AM
:( 1st attempt isnt working, looking into it now though.

c0ncrete
02-15-2013, 01:48 AM
i had it running on an enchanter npc. if it's not casting the buff, make sure the npc has qglobals enabled.

Figback65
02-15-2013, 01:49 AM
qglobals is 1, i am checking everything tho. I will update in a few. If it works for u, i obviously missing something.

Figback65
02-15-2013, 02:02 AM
I dunno.... My npc is enchanter class 14, it has a enchanter spell list assigned(even though i dont think that matters since it pulls the clientside buffs from script), qglobal is 1, i copied ur script verbatim, I deleted everything inside of mine to make sure it was empty before i pasted. I #reloadpl and #repop force and #repop.


Edit: I wish I knew more to help better, lol. Although you have shined a lot of light on this for me, I am definately going to keep learning this. much fun :)

c0ncrete
02-15-2013, 02:12 AM
haven't the faintest on that one. have 160135.pl in tutoriala and popped the npc with #dbspawn 160135 and everything is working for me here.

Figback65
02-15-2013, 02:21 AM
Ill get some fresh eyes on it tomorrow. Thanks for helpen me today c0ncrete.

Figback65
02-15-2013, 03:26 PM
Hmmm what about maybe a version of perl issue? Commands missing maybe? My server is ran off an old winxp 32bit machine currently. Active Perl 5.10.1 and Mysql server 5.1. I dunno lol Tryen to troubleshoot every angle.

c0ncrete
02-15-2013, 03:42 PM
try removing the first three lines then.

Figback65
02-15-2013, 07:00 PM
Awsome, it works for Enchy, so happah!!! lol. Necro is not working tho and i added cleric and its not working either. Looking into that now, just got freed up.

Figback65
02-15-2013, 07:03 PM
Ok, i was wrong, it works for all classes. The problem is, it doesnt work on a repop alone. What I mean is, if you #reloadpl while on the necro class then hail him, the necro responds and works properly. If you repop to a enchy or now added cleric, and hail him, he will not respond. If you then #reloadpl he will begin responding. But as soon as you repop to another enchy or cleric or necro, he stops responding again until you #reloadpl.

Edit: Maybe a sub EVENT_SPAWN around the hash table?

Edit: Nope didnt work., Only response was Got "Buffs?" But it did allow the npc to respond every repop without the #reloadpl

ghanja
02-15-2013, 07:25 PM
Get the PM?

ghanja
02-15-2013, 10:40 PM
Replied again. Use NPC ID(s) for the script names, vice clean name.

Figback65
02-15-2013, 11:15 PM
Ok I did that, and it works. But by doing it this way, its linked directly to a class and i have 16 scripts with 16 spell lists in each one, when the default buffbot was 16 scripts with 1 spell list in each. Its the same, except we did way more work for an autocheck we could have manually done.

Edit : Eitherway I am VERY happy and currently finishing up the scripts.

Thank you very much guys!!!

c0ncrete
02-16-2013, 03:46 AM
i don't know why you're having issues at this point. i made some minor changes to the script (shown in red below) and tossed it on an npc in tutorialb and it worked exactly as i expected it would. half of them spawned as erudites (necros) and the other half as high elves (enchanters), and both showed the correct responses when hailed.

quests\tutorialb\a_cave_rat.pl
use 5.012;
no strict 'vars';
use warnings;

# array of playable class long names
use constant CLASS_L => qw(
Unknown Warrior Cleric Paladin Ranger Shadowknight Druid Monk Bard Rogue
Shaman Necromancer Wizard Magician Enchanter Beastlord Berserker
);

# hashref containing buffs offered depening on the class of the npc
my $data = {
Enchanter => {
greet => "I have the %s for your mind.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Breeze", 697, 25 ],
[ "Clarity", 174, 50 ],
[ "Clarity II", 1693, 200 ],
[ "Alacrity", 170, 10 ],
[ "Augment", 1729, 30 ],
[ "Aanya's Quickening", 1708, 100 ],
[ "Rune I", 481, 5 ],
],
},
Necromancer => {
greet => "Souls and %s.",
buffs => [
[ "Bind Affinity", 35, 10 ],
[ "Dead Men Floating", 1391, 10 ],
],
},
};

sub EVENT_SPAWN {

if ( 49 > (int rand 99) + 1 ) {
$npc->SetEntityVariable( "Class", 14 );
$npc->SetRace(5);
}
else {
$npc->SetEntityVariable( "Class", 11 );
$npc->SetRace(3);
}
}

sub EVENT_SAY {

my $npcClass = (CLASS_L)[ $npc->GetEntityVariable("Class") ];
my $greeting = $data->{$npcClass}->{greet} || "Got %s?";
my $buffList = $data->{$npcClass}->{buffs};

# saylink
my $buffs = quest::saylink( "buffs", 1 );

my $CanCast = sub {
foreach my $spell ( @{ +shift } ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};
my $buffLink = quest::saylink( $spellName, 1 );
$client->Message( 315,
"I can cast $buffLink on you for ${spellCost}pp." );
}
};

# matches hail
if ( $text =~ /hail/i ) { quest::say( sprintf $greeting, $buffs); }

# doesn't match hail, but does match something in buff list
elsif ( my @match = grep { ${$_}[0] =~ /$text/i } @{$buffList} ) {

# single, exact match in buff list.
if ( @match == 1 && $text eq $match[0][0] ) {
my ( $spellName, $spellID, $spellCost ) = @{ $match[0] };
$client->Message( 315,
"That will be ${spellCost}pp for $spellName." );
quest::setglobal( "buff", $text, 0, "M5" );
}

# more than one match in buff list. list them.
else { $CanCast->( \@match ); }
}

# defaut to listing all buffs this npc can cast.
else { $CanCast->($buffList); }
}

sub EVENT_ITEM {

my $npcClass = (CLASS_L)[ $npc->GetEntityVariable("Class") ];
my $buffList = $data->{$npcClass}->{buffs};

my $correctMoney = 0;

# if client has selected a buff
if ( defined $qglobals{buff} ) {

# find the buff selected
foreach my $spell ( @{$buffList} ) {
my ( $spellName, $spellID, $spellCost ) = @{$spell};

# if client gave the correct amount of money, cast the spell
next if $qglobals{buff} ne $spellName || $platinum != $spellCost;
$client->Message( 315,
"Thank you for the ${spellCost}pp. Prepare for $spellName!" );
$npc->CastSpell( $spellID, $client->GetID() );
$correctMoney = 1;
quest::delglobal("buff");
last;
}
}

# incorrect amount of money given or no qglobal for buff found for client
if ( !$correctMoney && ( $copper || $silver || $gold || $platinum ) ) {
$client->Message( 315,
"I don't need these coins. You may have them back." );
quest::givecash( $copper||0, $silver||0, $gold||0, $platinum||0 );
}
}

Figback65
02-16-2013, 04:59 PM
ok checkin it out now.
Thanks c0ncrete.

Figback65
02-16-2013, 05:17 PM
Nope, still same issue. It will work indefinately after each #reloadpl, but any normal respawn from death or #repop, does not respond to the hail until you #reloadpl again.

I did rename scripts to NPCid#.pl and those work every time with respawns without #reloadpl, so the script definately works on pulling the correct class.

Only thing I still think of is my version of perl maybe? The guide I followed...

http://new.eqemulator.net/forums/showthread.php?t=32980


Edit: After the initial "bang your head against wall" stage, I have had the server up and running pretty good since june of 2012. Fixed a lot of missing database stuff and cleaned it up pretty well. So I am scared to try and use another perl lol bc of how hard it was getting started. Specially with all the errors you helped me with from just changing to the new build lol

ghanja
02-16-2013, 05:46 PM
What build is your server running?

Figback65
02-16-2013, 06:47 PM
My server is running everything posted in that guide, mysql 5.1 and perl 5.10.1 build 1007, source2294, built with cmake 2.8, compiled with visual c++ 2008.

c0ncrete
02-16-2013, 10:13 PM
just verified it works after rats begin to respawn as well. i built my executables on the 15th. i've got some custom stuff in there as well, but nothing that should change how the script works.

you can always back up your database and executables, update, and test it out and then revert if it doesn't work.

Figback65
02-18-2013, 09:17 PM
Ok, ill work on that this weekend when i get some more time.
Ty
Fig