-
Notifications
You must be signed in to change notification settings - Fork 12
/
DespawnRespawnScourgeQuestGivers.lua
61 lines (56 loc) · 2.44 KB
/
DespawnRespawnScourgeQuestGivers.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local GAME_EVENT_ID = 17 -- Set the game event ID
local npcIds = {344, 12480, 1284, 400064, 234, 3429} -- Add your NPC entries here
local BROADCAST_MESSAGE = "The Scourge are attacking the people of Azeroth. Quickly adventurers, prepare yourselves!"
local SOUND_ID = 13363
local excludedZones = {44} -- Replace these with the zone IDs where you don't want the sound to play
local YELL_MESSAGES = {
"The Scourge have come!",
"Beware, the Scourge approaches!",
"Defend our home, the Scourge is upon us!",
"To arms, the Scourge is here!",
"All fighters ready the assault against the Scourge.",
"The Scourge invasion has begun!",
"The Lich Kings minions have come! Rally against the Scourge!",
"The Scourge dares to attack us!",
"Show the Scourge the might of the people of Azeroth!"
}
local function YellRandomMessage(npc)
local messageIndex = math.random(1, #YELL_MESSAGES)
npc:SendUnitYell(YELL_MESSAGES[messageIndex], 0)
end
local function valueExists(tbl, value)
for _, v in ipairs(tbl) do
if v == value then
return true
end
end
return false
end
local function DespawnAndRespawnNpcs(event, gameEventId)
if gameEventId == GAME_EVENT_ID then
local players = GetPlayersInWorld() -- Get all players in the world
if event == 34 then -- Game Event Start
SendWorldMessage(BROADCAST_MESSAGE, 2) -- Broadcast the message with chat type 2 (SYSTEM)
for _, player in ipairs(players) do
local playerZoneId = player:GetZoneId()
if not valueExists(excludedZones, playerZoneId) then
player:PlayDirectSound(SOUND_ID) -- Play the sound for each player
end
end
end
for _, player in ipairs(players) do
for _, npcId in ipairs(npcIds) do
local npcs = player:GetCreaturesInRange(1000, npcId) -- Get creatures within a radius of 1000 units from the player
for _, npc in ipairs(npcs) do
if event == 34 then -- Game Event Start
YellRandomMessage(npc)
end
npc:DespawnOrUnsummon()
npc:Respawn()
end
end
end
end
end
RegisterServerEvent(34, DespawnAndRespawnNpcs) -- Game Event Start
RegisterServerEvent(35, DespawnAndRespawnNpcs) -- Game Event End