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.