EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Support::Windows Servers (https://www.eqemulator.org/forums/forumdisplay.php?f=587)
-   -   Buff Bot code question (https://www.eqemulator.org/forums/showthread.php?t=41205)

ionhsmith 03-12-2017 11:53 AM

Buff Bot code question
 
I have edit this code to make buff bots in the guild lobby. The cleric one I made will cast temperance on players but I cant see to get this one to cast kei on a player... it cast it on itself... any suggestion why this is happening or how to fix it?

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 = ("Bind Affinity","”See Invisible","Serpent Sight","Intellectual Advancement","Rune I","Breeze","Quickness","Intellectual Superiority","Alacrity","Rune II","Clarity","Augmentation","Ward of Alendar","Radiant Visage","Clarity II","Rune III","Gift of Magic","Insight","Celerity","Rune IV","Brilliance","Guard of Alendar","Adorning Grace","Swift Like the wind","Improved Invisibility","Rune V","Aanya's Quickening","Gift of Insight","Protection of Alendar","Overwhelming Splendor","Augment","Wonderous Rapidity","Gift of Brilliance","KEI");
 @SpellCost = ("2","2","1","2","3","3","2","3","5","6","5","7"," 4","5","7","9","5","5","5","12","7","6","8","8","1 0","15","10","8","10","10","10","12","12","25") ;
 @SpellID = ("35","80","276","2561","481","697","39","2562","1 70","482","174","10","4073","646","1693","483","14 08","175","171","184","33","4074","647","172","140 6","1689","1708","1403","4075","1701","1729","1709 ","1410","2570");

 sub EVENT_SPAWN
 {
 quest::settimer("buffy", 90);
 quest::ooc("Mind buffs in Guild Lobby");
 quest::settimer("despawnbuffy", 1300)
 }

 sub EVENT_TIMER
 {
 #$npc->SetAppearance(1);
 if($timer eq "buffy")
 {
 my $random_number = int(rand(4));
 if ($random_number == 0)
 {
 quest::shout("I have the buffs you're looking for...");
 }
 elsif ($random_number == 1)
 {
 quest::shout("Clarity, Clarity II, KEI, and Haste in Guild Lobby");
 }
 elsif ($random_number == 2)
 {
 quest::shout("Buffing for Platinum! Proceedes go to Arcane Scholarship funds");
 }
 elsif ($random_number == 3)
 {
 quest::say("Terran, Please stop touching me.");
 }
 $npc->SetAppearance(int(rand(2)));
 }
 if($timer eq "despawnbuffy")
 {
 quest::say ("I'm off to shower. This place makes my skin crawl");
 quest::depop();
 }
 }

 sub EVENT_SAY
 {
 my $all = quest::saylink("List", 1);
 my $buffs = quest::saylink("Buffs",1);
 #Spacer between Text messages to make them easier to read
 $client->Message(7, "-");
 my $NPCName = $npc->GetCleanName();
 if ($text =~/Hail/i)
 {
 $npc->SetAppearance(0);
 $client->Message(315, "$NPCName whispers to you, 'Please let me know what [$buffs] you'd like, or I can list them [$all] for you. '");
 }
 #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 =~ /^List$/i))
 {
 my $SpellList = quest::saylink($SpellList[$n]);
 my $SpellCost = $SpellCost[$n];
 $client->Message(315, "$NPCName whispers to you, 'Possible match is: $SpellList and it costs $SpellCost pp");
 }
 if ((lc($SpellList[$n]) =~ lc($text) && lc($SpellList[$n]) ne lc($text)) || (($text =~ /Buffs/i) && ($SpellList[$n] !~ /Port to/i)))
 {
 my $SpellList = quest::saylink($SpellList[$n]);
 my $SpellCost = $SpellCost[$n];
 $client->Message(315, "$NPCName whispers to you, 'Possible match is: $SpellList and it costs $SpellCost pp");
 }
 if ((lc($SpellList[$n]) =~ lc($text) && lc($SpellList[$n]) ne lc($text)) || (($text =~ /Ports/i) && ($SpellList[$n] =~ /Port to/i)) )
 {
 my $SpellList = quest::saylink($SpellList[$n]);
 my $SpellCost = $SpellCost[$n];
 $client->Message(315, "$NPCName whispers to you, 'Possible match is: $SpellList and it costs $SpellCost pp");
 }

 #This Is the command that Is executed when a the user enters a spell.
 if (lc($SpellList[$n]) eq lc($text) && $text !~ /^List$/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}!");
 if ($SpellList[$n] =~ /Port to/i)
 {
 quest::selfcast($SpellID[$n])
 }
 else
 {
 $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");
 }


Uleat 03-12-2017 12:38 PM

This is the problem: https://github.com/EQEmu/Server/blob...ells.cpp#L1753


KEI is a target type '41' spell - aka. 'ST_Group'

So, the target you supply is overridden to 'self' when the spell is actually cast.


I'm not familiar enough with the spell code to offer a suggestion..but, someone else may be :)

ZombieSoul 03-12-2017 03:09 PM

Before I had a bot enchanter I had something similar to this to work around the group buff issue.
Code:

sub EVENT_SAY {

        if($text=~/hail/i) {
                quest::say("Hail, $name.I can help you [clear] your mind.");
        }

        if($text=~/clear/i) {
                my $Group = $client->GetGroup();
               
                if($ulevel >= 46) {
                        if($Group) {
                                #Koadic's Endless Intellect 2570
                                $Group->CastGroupSpell($npc, 2570);
                        }
                        else {
                                #Clairvoyance 5513
                                $npc->CastSpell(5513, $userid);
                        }
                        quest::say("May your mind be clear, $name");
                }
                else {
                        if($Group) {
                                #Boon of the Clear Mind 1694
                                $Group->CastGroupSpell($npc, 1694);
                        }
                        else {
                                #Clarity 174
                                $npc->CastSpell(174, $userid);
                        }
                        quest::say("May your mind be clear, $name");
                }
        }
}

I think npcs should be able to cast any spells including group spells as they were intended, so I may make a personal edit on my server.

ionhsmith 03-12-2017 08:05 PM

Thanks for the replies but not exactly sure what you mean by your post zombie. Are you saying I should add that into what is already there or is that a completely different code for something you have on your server?

ZombieSoul 03-13-2017 01:52 AM

It is just example code, showing a way you could work around the problem you are having with a group target spell like KEI - if the client has a group, cast KEI if they dont, cast some other single target spell
the code example is in no way intended to fit into your script exactly, but an overall block of code to take as an example. There are probably many ways you can do this, this is one.


All times are GMT -4. The time now is 04:34 PM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.