Code:
function AntiAirTowerSpawn(pUnit, Event)
if Event == 18 then
-- If a npc spawns, make it check for nearby units every 1.5 seconds
pUnit:RegisterEvent("AntiAirTowerShoot", 1500, 0)
else
-- If it dies, remove events
pUnit:RemoveEvents()
end
end
function AntiAirTowerShoot(pUnit)
local found = false
-- Get all units
for _, unit in pairs(pUnit:GetInRangeUnits()) do
if unit:IsAlive() then
-- This just makes us face who we are shooting
local x, y, z = pUnit:GetLocation()
pUnit:SetPosition(x, y, z, pUnit:CalcRadAngle(x, y, unit:GetX(), unit:GetY()))
-- This deals damage - in combat log it will show spell 61647 being used (can be any spell)
-- It is dealing 100 damage
-- On critical strike, it will do double damage (1)
pUnit:Strike(unit, 2, 61647, 100, 100, 1)
pUnit:CastSpellOnTarget(61647, unit) -- shoot bow
-- Mark we have found somebody
found = true
-- Stop searching if we found somebody
break
end
end
-- If no creature was found
if not found then
-- Search players
for _, plr in pairs(pUnit:GetInRangePlayers()) do
if plr:IsAlive() then
-- This just makes us face who we are shooting
local x, y, z = pUnit:GetLocation()
pUnit:SetPosition(x, y, z, pUnit:CalcRadAngle(x, y, plr:GetX(), plr:GetY()))
-- This deals damage - in combat log it will show spell 61647 being used (can be any spell)
-- It is dealing 100 damage
-- On critical strike, it will do double damage (1)
pUnit:Strike(plr, 2, 61647, 100, 100, 1)
pUnit:CastSpellOnTarget(61647, plr) -- shoot bow
-- Mark we have found somebody
found = true
-- Stop searching if we found somebody
break
end
end
end
end
RegisterUnitEvent(485211, 18, "AntiAirTowerSpawn") -- 485211 = npc id
RegisterUnitEvent(485211, 4, "AntiAirTowerSpawn")