Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2011, 10:59 PM
Hateborne
Hill Giant
 
Join Date: May 2010
Posts: 125
Question $npc->CastSpell Working on Target, Not Self

Evening gents, I've gone and broken something again!

I am experiencing a weird issue with CastSpell. If I use it to cast on a player, it works fine. If I use it on the npc that is casting (as in self buffing) it is always interrupted.

A few previous posts I've found say to use $npc-GetID() for self targetting, but that just end in the script refusing to run certain parts.

Enclosed are relevant portions of the script:

This is the 'header' to the subroutine. Note @groupMembers is not listed here as it is filled in at the start of the fight on agro (which is relevant, but isn't broken).
Code:
sub doDiscord
{
	my $victim = "";
	my $randy = int(rand(1000));
	my @moblist = $entity_list->GetMobList();
	foreach $ent (@moblist)
	{
		if($ent->GetID() == 999173)
		{
			$selfEnt = $ent;
		}
	}
This next part fails to set $victim to the top threat target. Gives an unknown variable error in logs. Both spells always give Interrupted (guessing due to lack of legitimate target). The spell referenced is a targetted AoE with snare component.
Code:
	
	if($randy > 875)
	{
		quest::say("Slow down friend. No need to be in such a hurry.");
		$victim = $npc->GetHateTop();
		$npc->CastSpell(9895, $victim, 10, 0, 0);		## cast druid 4.0 vines on top threat
		$npc->CastSpell(9895, $victim, 10, 0, 0);		## cast druid 4.0 vines on top threat
	}
This bit was me trying 3 different ways of getting it to work. The spells referenced here are spell damage bonus, melee haste, and casting haste (respectively). The error produced is "Perl runetime error: Can't call method "GetID" without a package or object reference at quest/xxx/yyy.pl line 151". Line 151 is the Ancient: Vampiric Thunder line.
Code:
	elsif($randy > 625)
	{
		quest::say("Let's play pretend! I pretend to be an Enchanter!");
		$npc->CastSpell(9936, $selfEntity->GetID(), 10, 0, 0);		## buff self with Ancient: Vampiric Thunder
		$npc->CastSpell(9937, $selfEnt, 10, 0, 0);		## buff self with Ancient: Melee Haste
		$npc->CastSpell(9938, $selfEntity, 10, 0, 0);		## buff self with Ancient: Spell Haste
		
	}
This section will randomly mezz a few player but refuses to actually do the heal cast. I am assuming it has something to do with targetting again.
The spell first referenced is unresistable npc mezz, second is incredibly strong Complete Heal v2.
Code:
	elsif($randy > 125)
	{
		quest::say("Stop that! I need to heal...");
		my $temp = int(rand($size)) - 1;			## random pick a number of players to mezz
		if($temp < 1) {$temp = 1};				## minor catch to ensure no out of bounds
		for ($i = 0; $i < $temp; $i++)
		{
			$npc->CastSpell(9757, $groupMembers[$i], 10, 0, 0);	## cast NPC Mesmerize on target
		}
		
		$npc->CastSpell(9712, $selfEntity, 10, 8, 0);			## 8 second cast of Cleric CH 2 (with Amp Healing, should do ~400k)
	}
This just produces a massive block of interrupts. Again, targetting I guess :-P
Spell referenced is a 25k x 5 (per cast) wizard nuke.
Code:
	elsif($randy < 50)
	{
		quest::say("Hmm...never used this spell before!");
		$npc->CastSpell(9746, $selfEntity, 10, 0, 0);    ## wiz t3 nuke
		$npc->CastSpell(9746, $selfEntity, 10, 0, 0);    ## wiz t3 nuke
		$npc->CastSpell(9746, $selfEntity, 10, 0, 0);    ## wiz t3 nuke
		$npc->CastSpell(9746, $selfEntity, 10, 0, 0);    ## wiz t3 nuke
		$npc->CastSpell(9746, $selfEntity, 10, 0, 0);    ## wiz t3 nuke
		quest::say("OWW! Now I remember what that does.");
	}
}
Thank you in advance!


-Hate
Reply With Quote
  #2  
Old 04-12-2011, 11:24 PM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,490
Default

Are these all under 1 sub? Is this the complete script just broken into chunks?
Reply With Quote
  #3  
Old 04-13-2011, 12:07 AM
Caryatis
Dragon
 
Join Date: May 2009
Location: Milky Way
Posts: 541
Default

First off, that way of displaying your script makes its really hard to debug. Im not sure if you are worried about somebody stealing your script or something but its not conducive to helping those you want help from.

One issue I see is that the mobs ID is not its NPCTypeID. The ID given is unique to that session and is usually not very large. If you want to get an NPC by its TypeID then you need to use GetNPCList() and check with $ent->GetNPCTypeID().

However, I assume this is a secondary NPC(otherwise you would just use $npc->GetID() right?). Since this is not the npc you want casting the spell, you can still simulate that by using $entity_list->GetNPCByID(999173)->CastSpell(xxx);
Reply With Quote
  #4  
Old 04-13-2011, 05:05 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Well, right off the bat, I see quite a few issues with your script snippets. Part of the problem is that you broke the script up and didn't show the entire script, so it is really hard to tell you for sure where all of your issues are.

For one thing, if you want an NPC to be able to cast more than 1 spell at a time, you should use the following command:

Code:
SpellFinished(spell_id, spell_target = this, mana_cost = 0)
Only 1 spell can be cast at a time, so if you use something like CastSpell(), it will only be able to cast the first cast and then fail any following casts until the first one is completely done casting.

Another issue is you seem to be confused on the idea of entity IDs vs getting the actual mob itself. When using CastSpell(), it requires the entity ID, not the actual mob or NPC Type ID, which Caryatis already mentioned a bit.

Code:
CastSpell(spell_id, target_id, slot= 10, casttime= -1, mana_cost= -1)
The target_id field there is for entity ID only and it will fail if you don't set that to a valid ID. To get the Entity ID is easy though, as you just need to do something like this:

Code:
my $NPC_ID = $npc->GetID();
That will get a number between 1 and about 1600, but more likely less than 300 depending on how many NPCs/Clients you have in the zone. Each mob gets it's own unique ID, and that is what the number is.

You could then do this:

Code:
$npc->CastSpell(11, $NPC_ID);
And that should work.

Also, before you try to do something like this:

Code:
$selfEntity->GetID()
Always make sure the $selfEntity variable was set to a valid mob before using it as a pointer or you will likely run into zone crashes. If you are saving variables like that in timers and using them again later, you run into even more potential crash issues. If you must do that, you should save the entity ID and then get the mob by entity ID again later when you need it again to verify the mob still exists in the zone.

There are a few other issues I can guess you have in that script, but I can't say for sure without seeing the whole script.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #5  
Old 04-13-2011, 11:04 AM
Hateborne
Hill Giant
 
Join Date: May 2010
Posts: 125
Default

First: Trevius the Bad Ass, joligario and Caryatis...thank you for the replies!

Second: The script is cut into just this subroutine as it is the only relevant one. The rest is just a serious of dialog 'Hail', 'Tell me more', 'What artifact' and other such boring quotes. The only thing that really happens outside this subroutine is the mob engages after the last dialog trigger is hit. So there is nothing else to see.
The subroutine itself is broken up because there are several sections of the if-else statement that do the same thing. Either casting 2-3 spells on a player (which work...) or 2-3 on itself (which fail...). I omitted several else 'blocks' as they just randomly cast on player (which even instant multiple castings works, just not on the mob itself due to targeting).

Third: Lastly, I broke it up because adding inline comments to describe each individual block looked absolutely horrific. Apparently, I am alone in that view.

Trevius, again I can't thank you enough for taking time out to write another long and insanely useful response. You truly are win, Sir!

-Hate
Reply With Quote
  #6  
Old 04-13-2011, 11:05 AM
Hateborne
Hill Giant
 
Join Date: May 2010
Posts: 125
Default

--Double Post--

Sorry, college internet is having massive issues atm
Reply With Quote
  #7  
Old 04-13-2011, 11:48 AM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,490
Default

Quote:
Originally Posted by Hateborne View Post
Third: Lastly, I broke it up because adding inline comments to describe each individual block looked absolutely horrific. Apparently, I am alone in that view.
Well the problem with troubleshooting perl script broken up is that often errors are somewhere else in the script. Additionally, the script may only makes sense as a whole so you can catch logic AND syntax errors.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 08:25 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3