EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   $npc->castspell(x,x) not working (https://www.eqemulator.org/forums/showthread.php?t=41408)

Eealer 06-25-2017 02:46 AM

$npc->castspell(x,x) not working
 
Hello,

I am trying to create my own buff bot (that does not require payment, also using someone else's script as a template and replacing what I dont need with what I want/need), but I do not want to use the self cast since it will have a messed up spell duration on the player receiving it. I have tried
Code:

$npc->castspell(3576,$userid)
I have also tried with the 'C' in cast capitalized, and with the 'S' in spell capitalized as well as both capitalized or neither capitalized.
I have tried
Code:

$npc->castspell($userid,3576)
,
Code:

$npc->castspell(3576,$userid,10,0,0)
and
Code:

quest::castspell(3576,$userid)
and none of what I have tried seems to make the NPC cast the buff on me.

I have no real knowledge of how perl works, but I have a basic/intermediate understanding of some other programming languages (SQL, HTML, Crystal Reports) so I can not understand why this is not working. When it uses the selfcast function it works just fine.

Can someone please help me get this to work? The Code is below.
Also, I don't know if it makes any difference, but the server is running on a Windows 10 Pro x64 VM.

Code:

#A buff bot script.
#Buffs a player for pp.

#SpellList is the array containing the names of the spells. minlevel 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 = ("Temperance","Blessing of Faith","Guard of Vie","Resist Disease","Resist Magic","Resist Cold","Resist Fire","Resist Poison","Protection of Vie","Mark of Karn","Aegolism","Faith","Virtue","Blessing of Reverance","Bulwark of Vie","Mark of Kings","Tenacity","Blessing of Purpose","Aegis of Vie");
@minlevel = (                "1",            "1",            "1",            "1",            "1",        "1",          "1",          "1",              "43",            "43",        "45",  "45",    "46",          "46",                "46",          "47",        "61",            "61",            "61");                                   
@SpellID =  ("3692",          "3576",        "4089",            "63",            "64",        "61",          "60",        "62",            "4090",          "1548",      "1447",  "3296",  "3467",        "3472",              "4091",        "3469",      "9732",          "9705",          "9744");



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, "Hello $name. Would you like to receive some [$buffs]?  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 =~ /^List$/i))
                        {
                                my $SpellList = quest::saylink($SpellList[$n]);
                                my $minlevel = $minlevel[$n];
                                $client->Message(315, "Possible match is: $SpellList and it requires you to be a minimum level of: $minlevel to work on you");
                        }
                        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 $minlevel = $minlevel[$n];
                                $client->Message(315, "Possible match is: $SpellList and it requires you to be a minimum level of: $minlevel to work on you");
                        }
                        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 $minlevel = $minlevel[$n];
                                $client->Message(315, "Possible match is: $SpellList and it requires you to be a minimum level of: $minlevel to work on you");
                        }
                       
                        #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, "$name is receiving: $qglobals{buff}!");
                                $npc->castspell($SpellID[$n],$charid, 10, 0, 0);
                        }
                        $n++;
                        $count++;
                }
        }
}


nilbog 06-25-2017 08:11 PM

I suggest testing basic usage of CastSpell to ensure it works properly, then expand upon your script.

i.e.

Code:

sub EVENT_SAY {
  if($text=~/hail/i) {
    $npc->CastSpell(17,$userid); #Light Healing
  }
 }


Eealer 06-25-2017 08:24 PM

Quote:

Originally Posted by nilbog (Post 255032)
I suggest testing basic usage of CastSpell to ensure it works properly, then expand upon your script.

i.e.

Code:

sub EVENT_SAY {
  if($text=~/hail/i) {
    $npc->CastSpell(17,$userid); #Light Healing
  }
 }


Thanks Nilbog, I have tried using other spells for the CastSpell Function and none of them seem to work, the only way I seem to be able to make spells cast is if I use the selfcast function. I just tried changing it to use light healing as you had mentioned above and it crashed the client when I hailed the NPC (It has never done that before)

--Update: I put it back to "quest::CastSpell($userid,17); and it stopped crashing the client, but the spell still doesn't cast

Eealer 06-27-2017 08:55 PM

So I got it to work now but I still have no idea why it wouldn't work before

javewow 08-06-2017 09:05 AM

This is the right

$npc->CastSpell($SpellID[$n],$userid);


All times are GMT -4. The time now is 01:50 AM.

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