I tried to make a lua script that lets you talk to an npc, that npc then spawns another npc that nearly identical, has combat capabilities instead of gossip to help the player, along with an invisible unfriendly mob that will begin summoning adds for two minutes upon entering combat.
There's three different types of adds that will be spawned: Raider - general melee unit, Walking Bomb - low health bomb that creates a way point to the beginning friendly npc that starts the event, once the bomb reaches the way point, it explodes, and you die horribly, Commander - high health high damage creature which will drop the quest item once I make the quest.
World.exe crashes before the entire duration of the script.
Take a look at the scripts below, and see what I did wrong. Any useful comments will be +Rep'd
Spawner
Code:
function HordeRaidEventSpawner_OnCombat(Unit, Event)
Unit:Despawn(120000, 0)
Unit:RemoveAllAuras()
Unit:RegisterEvent("HordeRaidEventSpawner_RandomSummon", 8000, 0)
Unit:RegisterEvent("HordeRaidEventSpawner_SpawnHordeCommander", 100000, 1)
end
--SOUTH DOOR 2616.333008, 5262.813477, 39.410072, 5.513389
--NORTH DOOR 2643.458984, 5248.559570, 38.309711, 3.145407
function HordeRaidEventSpawner_RandomSummon(Unit, Event)
local RandomSummon=math.random(1, 4);
if RandomSummon == 1 then -- 2 raiders
Unit:SpawnCreature(900063, 2616.333008, 5262.813477, 39.410072, 5.513389, 85, 120000)
Unit:SpawnCreature(900063, 2643.458984, 5248.559570, 38.309711, 3.145407, 85, 120000)
elseif RandomSummon == 2 then -- 2 walking bombs
Unit:SpawnCreature(900064, 2616.333008, 5262.813477, 39.410072, 5.513389, 32, 120000)
Unit:SpawnCreature(900064, 2643.458984, 5248.559570, 38.309711, 3.145407, 32, 120000) -- Takes place in Farshire, Borean Tundra
elseif RandomSummon == 3 then -- one of each
Unit:SpawnCreature(900064, 2616.333008, 5262.813477, 39.410072, 5.513389, 32, 120000)
Unit:SpawnCreature(900063, 2643.458984, 5248.559570, 38.309711, 3.145407, 85, 120000)
elseif RandomSummon == 4 then -- one of each, spawns at different doors than one above
Unit:SpawnCreature(900063, 2616.333008, 5262.813477, 39.410072, 5.513389, 85, 120000)
Unit:SpawnCreature(900064, 2643.458984, 5248.559570, 38.309711, 3.145407, 32, 120000)
end
end
function HordeRaidEventSpawner_SpawnHordeCommander(Unit, Event)
Unit:SpawnCreature(900065, 2643.458984, 5248.559570, 38.309711, 3.145407, 85, 120000)
end
function HordeRaidEventSpawner_OnDied(Unit, Event)
Unit:RemoveEvents()
end
function HordeRaidEventSpawner_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(900068, 1, "HordeRaidEventSpawner_OnCombat")
RegisterUnitEvent(900068, 4, "HordeRaidEventSpawner_OnDied")
RegisterUnitEvent(900068, 2, "HordeRaidEventSpawner_OnLeaveCombat")
Gossip NPC which starts the event
Code:
function AllianceWarLeaderGOSSIPOn_Gossip(unit, event, player)
unit:GossipCreateMenu(50, player, 0)
unit:GossipMenuAddItem(0, "I'm ready to help defend against the Horde.", 1, 0)
unit:GossipMenuAddItem(0, "Uhh, never mind...", 2, 0)
unit:GossipSendMenu(player)
end
function AllianceWarLeaderGOSSIPGossip_Submenus(unit, event, player, id, intid, code)
if(intid == 1) then
unit:GossipCreateMenu(58, player, 0)
unit:SendChatMessage(14, 0, "Here they come!")
unit:Despawn(1000, 0)
unit:SpawnCreature(900067, 2623.929, 5249.411, 38.3, .73, 12, 0) --combat unit to help player
unit:SpawnCreature(900068, 2623.929, 5249.411, 38.3, .73, 85, 120000) --invisible spawner unit that will spawn the adds
end
if(intid ==2) then
unit:GossipComplete()
unit:SendChatMessage(14, 0, "Bastard.")
end
end
RegisterUnitGossipEvent(900066, 1, "AllianceWarLeaderGOSSIPOn_Gossip")
RegisterUnitGossipEvent(900066, 2, "AllianceWarLeaderGOSSIPGossip_Submenus")
Walking Bomb [Usually crashes once ascend to the heavens is casted, but varies]
Code:
function WalkingBomb_OnLoad(Unit, Event)
Unit:CreateWaypoint(2624.588867, 5250.187500, 38.292435, 3.83, 300, 0, 0)
Unit:MoveToWaypoint(1)
end
function WalkingBomb_OnReachWaypoint(Unit, Event)
Unit:FullCastSpell(64487) --ascend to the heavens
Unit:RegisterEvent("WalkingBomb_DespawnSpecial", 2500, 1)
end
function WalkingBomb_DespawnSpecial(Unit, Event)
Unit:Despawn(300, 0)
Unit:RemoveEvents()
end
function WalkingBomb_OnDied(Unit, Event)
Unit:RemoveEvents()
Unit:Despawn(1500, 0)
end
function WalkingBomb_OnLeaveCombat(Unit, Event)
Unit:Despawn(8000, 0)
Unit:RemoveEvents()
end
RegisterUnitEvent(900064, 19, "WalkingBomb_OnReachWaypoint")
RegisterUnitEvent(900064, 18, "WalkingBomb_OnLoad")
RegisterUnitEvent(900064, 4, "WalkingBomb_OnDied")
RegisterUnitEvent(900064, 2, "WalkingBomb_OnLeaveCombat")
I really appreciate any helpful comments!