I have seen a few people on Discord wondering how to execute code on a spell cast.
Here is an example of how you can spawn an NPC with the use of an already existing blank spell in the database (Claim Reward - ID: 7799)
Commented very extensively for maximum learning
C:\EQEmu\quests\global\spells\7799.pl
Code:
#:: Written by Splose from EQEmpires as an example for M0hnay on Discord
#:: EQEmpires.com Discord: https://discord.gg/UvC88vK
#:: EQEmulator.org Discord: https://discord.gg/QHsm7CD
#:: How to Spawn NPC on spell cast
#:: This will spawn a Priest of Discord at the client's location or a static location after casting Claim Reward (ID: 7799)
sub EVENT_SPELL_EFFECT_CLIENT {
#my $Debug = " "; #:: Remove to enable debug messages for GMs with status 100+
my $SpawnOnClient = 1;
my $npc_to_spawn = 29085;
#:: Static Location
#:: Only need to use these if SpawnOnClient = 0 and you want to spawn the mob in a static location
my ($spawn_x, $spawn_y, $spawn_z, $spawn_h) = (0.00, 0.00, 0.00, 0.00); #:: x/y/z/h
#:: END
#:: If SpawnOnClient is greater than zero it will use the client's location, otherwise it will use the location entered on line 16
my ($x, $y, $z, $h) = $SpawnOnClient > 0 ? ($client->GetX(), $client->GetY(), $client->GetZ(), $client->GetHeading()) : ($spawn_x, $spawn_y, $spawn_z, $spawn_h);
#:: These debug messages will only fire if you remove the # from line 10 and your GM status is 200+
$client->Message(15, "[Debug: Claim Reward (7799)] :: EVENT_SPELL_EFFECT_CLIENT was a success for (" . $client->GetCleanName() . ") Status: ($status)") if ($Debug && $status >= 200);
$client->Message(15, "[Debug: Claim Reward (7799)] :: X: ($spawn_x / $x) Y: ($spawn_y / $y) Z: ($spawn_z / $z) H: ($h / $spawn_h)") if ($Debug && $status >= 200);
quest::spawn2($npc_to_spawn, 0, 0, $x, $y, $z, $h);
}