I have a table that saves the spell id of certain buffs. When a user casts a particular spell, I want all of the buffs they have saved to be cast on their target (basically the buff master guy that was on Dungeon Crawl, if anyone remembers). I'm unable to get CastSpell to actually fire though, so I'm not sure if I'm referencing the caster (and target) of the spell correctly.
I currently have the spell in its own global/spells file. I know I could move the code to global_player.pl in an EVENT_CAST sub, but I don't want to clutter up that file unnecessarily, so I'd prefer to get this method to work.
Here is what I have so far.
Code:
sub EVENT_SPELL_EFFECT_CLIENT
{
my $target = $client;
CastBuffs($caster_id, $target);
}
sub EVENT_SPELL_EFFECT_NPC
{
my $target = $npc;
CastBuffs($caster_id, $target);
}
sub CastBuffs
{
my $caster_id = $_[0];
my $target = $_[1];
my $target_id = $target->GetID();
my $caster = $entity_list->GetClientByID($caster_id);
my $dbh = plugin::LoadMysql();
my $query = $dbh->prepare("SELECT spell_id FROM character_stored_buffs WHERE id = ?");
$query->execute($caster->CharacterID());
while (my @row = $query->fetchrow_array())
{
$caster->CastSpell($row[0], $target_id);
}
$query->finish();
$dbh->disconnect();
}
In the while loop, if I do something like
Code:
$caster->Message(5,"$row[0]");
$target->Message(5,"You are the target");
It will message the caster with the correct spell id and message the target as well, so those references somewhat seem to work.
Here are some of the other ways I've tried to reference the caster.
Code:
$caster->CastToClient()->CastSpell($row[0], $target_id);
$caster->CastToMob()->CastSpell($row[0], $target_id);
$entity_list->GetClientByCharID($caster->CharacterID())->CastSpell($row[0], $target_id);
$entity_list->GetClientByID($caster_id)->CastSpell($row[0], $target_id);
$entity_list->GetClientByID($caster->CharacterID())->CastSpell($row[0], $target_id);
$entity_list->GetMobByID($caster_id)->CastSpell($row[0], $target_id);
$entity_list->GetMobByID($caster->CharacterID())->CastSpell($row[0], $target_id);
Does anyone have any insight on how to make CastSpell work from an EVENT_SPELL_EFFECT sub? It seems like if I copy my code into a sub EVENT_SAY, my code works exactly as expected, so I'm not sure if these subs are just weird or not.