Two more examples of casting on spawn and reset. These are for visual channeling spells.
The first one would be used on an npc who is standing and casting a visual channel spell. the timers are set at one second only for a slight wait when returning to the home position after evade. These values can be zero and it would not effect the script working.
Notice that this event occurs out of combat with the event flag set to 1 “no repeat”. The script will reset on spawn and after evade so the script will run again when it is required too.
The second script is also a channeling spell but this one is channeled on a target. In this script the wait time of one second is very important. Because there is a chance that the caster may spawn before the trigger target without the wait time the npc may attempt to channel spell before the trigger is spawned and fail. So by adding a wait time of one second you give the trigger time to spawn before the spell is cast.
[CODE]-- Cast channeling spell no target
SET @ENTRY := XXXXX; – NPC entry
SET @SPELL := XXXXX; – Spell to cast
UPDATE creature_template
SET AIName
=‘SmartAI’ WHERE entry
=@ENTRY;
DELETE FROM smart_scripts
WHERE source_type
=0 AND entryorguid
=@ENTRY;
INSERT INTO smart_scripts
(entryorguid
,source_type
,id
,link
,event_type
,event_phase_mask
,event_chance
,event_flags
,event_param1
,event_param2
,event_param3
,event_param4
,action_type
,action_param1
,action_param2
,action_param3
,action_param4
,action_param5
,action_param6
,target_type
,target_param1
,target_param2
,target_param3
,target_x
,target_y
,target_z
,target_o
,comment
) VALUES
(@ENTRY,0,0,0,1,0,100,1,1000,1000,1000,1000,11,@SPELL,2,0,0,0,0,1,0,0,0,0,0,0,0, ‘NPC - On spawn & reset - Channel Spell’);
– Cast channeling spell with target
SET @ENTRY := XXXXX; – NPC entry
SET @SPELL := XXXXX; – Spell to cast
SET @CGUID := XXXXX; – Target creature guid
SET @CENTRY := XXXXX; – Target creature entry
UPDATE creature_template
SET AIName
=‘SmartAI’ WHERE entry
=@ENTRY;
DELETE FROM smart_scripts
WHERE source_type
=0 AND entryorguid
=@ENTRY;
INSERT INTO smart_scripts
(entryorguid
,source_type
,id
,link
,event_type
,event_phase_mask
,event_chance
,event_flags
,event_param1
,event_param2
,event_param3
,event_param4
,action_type
,action_param1
,action_param2
,action_param3
,action_param4
,action_param5
,action_param6
,target_type
,target_param1
,target_param2
,target_param3
,target_x
,target_y
,target_z
,target_o
,comment
) VALUES
(@ENTRY,0,0,0,1,0,100,1,1000,1000,1000,1000,11,@SPELL,2,0,0,0,0,10,@CGUID,@CENTRY,0,0,0,0,0, ‘NPC - On spawn & reset - Channel spell on target’);[/sql]
This will cause all creatures of an entry to cast the channeling spell. You may only want one creature to cast it. In this case you want to set the SAI to use -guid value of the creature you wish to cast the spell like the following:
[sql]-- Cast channeling spell no target
SET @ENTRY := XXXXX; – NPC entry
SET @SPELL := XXXXX; – Spell to cast
UPDATE creature_template
SET AIName
=‘SmartAI’ WHERE entry
=@ENTRY;
DELETE FROM smart_scripts
WHERE source_type
=0 AND entryorguid
=-123456;
INSERT INTO smart_scripts
(entryorguid
,source_type
,id
,link
,event_type
,event_phase_mask
,event_chance
,event_flags
,event_param1
,event_param2
,event_param3
,event_param4
,action_type
,action_param1
,action_param2
,action_param3
,action_param4
,action_param5
,action_param6
,target_type
,target_param1
,target_param2
,target_param3
,target_x
,target_y
,target_z
,target_o
,comment
) VALUES
(-123456,0,0,0,1,0,100,1,1000,1000,1000,1000,11,@SPELL,2,0,0,0,0,1,0,0,0,0,0,0,0, ‘NPC - On spawn & reset - Channel Spell’);
– Cast channeling spell with target
SET @ENTRY := XXXXX; – NPC entry
SET @SPELL := XXXXX; – Spell to cast
SET @CGUID := XXXXX; – Target creature guid
SET @CENTRY := XXXXX; – Target creature entry
UPDATE creature_template
SET AIName
=‘SmartAI’ WHERE entry
=@ENTRY;
DELETE FROM smart_scripts
WHERE source_type
=0 AND entryorguid
=-123456;
INSERT INTO smart_scripts
(entryorguid
,source_type
,id
,link
,event_type
,event_phase_mask
,event_chance
,event_flags
,event_param1
,event_param2
,event_param3
,event_param4
,action_type
,action_param1
,action_param2
,action_param3
,action_param4
,action_param5
,action_param6
,target_type
,target_param1
,target_param2
,target_param3
,target_x
,target_y
,target_z
,target_o
,comment
) VALUES
(-123456,0,0,0,1,0,100,1,1000,1000,1000,1000,11,@SPELL,2,0,0,0,0,10,@CGUID,@CENTRY,0,0,0,0,0, ‘NPC - On spawn & reset - Channel spell on target’);
[/CODE]
Where 123456 is the guid of the creature who is to cast the spell. You still need to set AIName
=‘SmartAI’ in creature_template for the creature entry.