I copied the
translocator script from Trev and modified it to allow a player to request a buff, then pay/donate for the buff, then get the buff.
There are probably a lot of scripts in the forums that do this type of stuff, but I like this way, because you can change 3 lines and it will work for about any type of caster bot.
I use 3 arrays for the buffs, one is the name of the buff, one is the cost of the buff, and one is the spell id to cast. I also use a qglobal variable for the npc to remember the spell to cast.
The beauty of scripting like this is that once this is working for a few spells it will be easily modifiable for any other buff bot type npc.
My idea is to have an npc for each class that can provide buffs or ports. I then want them to randomly appear and after a while to leave. This is a step in the direction of imitating live with players that would buff for donations.
One final note: I am not really a perl programmer, like I said I just copied Trev's code and modified it some. If there is a way to make this better or a more proper way, please let me know.
Code:
#A buff bot script.
#Buffs a player for pp.
#SpellList is the array containing the names of the spells. SpellCost is the amount in pp for each spell. SpellID is the spell that is cast by the npc.
#Note these are 3 arrays. Each position in the array corosponds to the same position in the other arrays.
#So I have this set so that if you say 'Spirit of Wolf' and pay 2 pp, then the npc will cast spell 278 on you.
#I am setting the amounts to pp just because they can be any amount you wish, this requires changing the EVENT_ITEM function to handle the other money types.
@SpellList = ("Everlasting Breath", "Improved Superior Camouflage", "Levitation", "See Invisible", "Spirit of Wolf", "Storm Strength");
@SpellCost = ("2", "10", "2", "2", "2", "10");
@SpellID = ("2881", "1435", "2894", "80", "278", "430");
sub EVENT_SAY
{
my $all = quest::saylink("List", 1);
#Spacer between Text messages to make them easier to read
$client->Message(7, "-");
my $NPCName = $npc->GetCleanName();
if ($text =~/Hail/i)
{
$client->Message(315, "$NPCName whispers to you, 'If you need a buff or a Port just let me know, or I can [$all] them for you. You may also enter a partial name and I can find it.'");
}
#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)
{
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 =~ /^All$/i))
{
my $SpellList = quest::saylink($SpellList[$n]);
$client->Message(315, "$NPCName whispers to you, 'Possible match is: $SpellList");
}
#This is the command that is executed when a the user enters a spell.
if (lc($SpellList[$n]) eq lc($text) && $text !~ /^All$/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("buff", $text, 0, "M5");
#I'm not sure why I need the next line, the line above should set the $qglobals{buff}, but it wouldn't work for me.
$qglobals{buff} = $text;
$client->Message(315, "Please give me $SpellCost[$n]pp, and I'll cast $qglobals{buff} for you!");
}
$n++;
$count++;
}
}
}
sub EVENT_ITEM
{
my $correctmoney = 0;
#Counts each row for the While
my $count = 1;
#Counts each element in the Array for the While
my $n = 0;
#Cycles through each spell in the array until it matches the requested spell, and the amount pp required.
while ($SpellList[$n])
{
if(($SpellList[$n] eq $qglobals{buff}) && ($platinum == $SpellCost[$n]))
{
$client->Message(315, "Thank you for the $SpellCost[$n]pp, prepare for $qglobals{buff}!");
$npc->CastSpell($SpellID[$n], $userid);
#set this to 1 so that we don't return money we shouldn't.
$correctmoney = 1;
}
$n++;
$count++;
}
#Returns the money if it is not the correct amount.
if ($correctmoney == 0 )
{
if(($copper > 0) || ($silver > 0) || ($gold > 0) || ($platinum > 0))
{
$client->Message(315, "I don't need these coins, you may have them back.");
quest::givecash($copper,$silver,$gold,$platinum);
}
}
#deletes the $qglobals{buff} variable.
quest::delglobal("buff");
}