Originally Posted by
DewmGuy
Code:
local NPCgryan = 234 -- gryan stoutmantle
local NPCtraitor = 467 -- defias traitor
local QUESTmessenger = 142 -- messenger quest
local QUESTtraitor = 155 -- escort quest
local function onSpawnTraitor(event, creature)
creature:SetPhaseMask(2)
end
local function QuestGiverEvents(event, player, pUnit, quest, _)
if quest:GetId() == QUESTmessenger then
if event == 31 then -- player accepts quest 142
player:SetPhaseMask(3) -- traitor npc becomes visible
end
end
if quest:GetId() == QUESTtraitor then
if event == 34 then -- player completes quest 155
player:SetPhaseMask(1) -- traitor npc becomes invisible
end
end
end
local function PLAYER_EVENT_ON_QUEST_ABANDON(event, player, questId)
if questId == QUESTmessenger then
player:SetPhaseMask(1) -- traitor npc becomes invisible
end
end
RegisterCreatureEvent(NPCtraitor, 5, onSpawnTraitor) -- spawn
RegisterCreatureEvent(NPCgryan, 31, QuestGiverEvents) -- accept
RegisterCreatureEvent(NPCgryan, 34, QuestGiverEvents) -- reward
RegisterPlayerEvent(38, PLAYER_EVENT_ON_QUEST_ABANDON) -- abandon
--CREATURE_EVENT_ON_QUEST_ACCEPT = 31 -- // (event, player, creature, quest) - Can return true
--CREATURE_EVENT_ON_QUEST_REWARD = 34 -- // (event, player, creature, quest, opt) - Can return true
i realized i deleted my script in frustration so i rewrote it, it's basically the same. the npc is correctly phased but when you start quest 155 the escort script doesn't start. Also, i'm not sure how to handle the player logging out and back in if they have the quest. i'm not sure that changing the player's phase is the best option for this scenario but changing the npc phase would affect every player in the zone.
What about something like this?
Code:
local NPC = {
gryan = 234, -- gryan stoutmantle
traitor = 467, -- defias traitor
}
local QUEST = {
messenger = 142, -- messenger quest
traitor = 155, -- escort quest
}
local function onSpawnTraitor(event, creature)
creature:SetPhaseMask(2) -- this should probably be set in the DB instead of on spawn
end
local function QuestGiverEvents(event, player, pUnit, quest, _)
local questId = quest:GetId()
pUnit:SendUnitSay("You have accepted quest " .. tostring(questId) .. ", event: " .. tostring(event)) -- Debug, can delete
if event == 31 and questId == QUEST.messenger then -- quest accept
player:SetPhaseMask(3) -- traitor npc becomes visible
elseif event == 34 and questId == QUEST.traitor then -- quest reward
player:SetPhaseMask(1) -- traitor npc becomes invisible
end
end
local function PLAYER_EVENT_ON_QUEST_ABANDON(event, player, questId)
if questId == QUEST.messenger then
player:SendBroadcastMessage("Abandoning quest!") -- Debug, can delete
player:SetPhaseMask(1) -- traitor npc becomes invisible
end
end
local function PLAYER_EVENT_ON_LOGIN(event, player)
for _,questId in pairs(QUEST) do
if player:HasQuest(questId) then
player:SendBroadcastMessage("Updating phase on login!") -- Debug, can delete
player:SetPhaseMask(3) -- traitor npc becomes visible
break
end
end
end
RegisterCreatureEvent(NPC.traitor, 5, onSpawnTraitor) -- spawn
RegisterCreatureEvent(NPC.gryan, 31, QuestGiverEvents) -- accept
RegisterCreatureEvent(NPC.gryan, 34, QuestGiverEvents) -- reward
RegisterPlayerEvent(38, PLAYER_EVENT_ON_QUEST_ABANDON) -- abandon
RegisterPlayerEvent(3, PLAYER_EVENT_ON_LOGIN)
--CREATURE_EVENT_ON_QUEST_ACCEPT = 31 -- // (event, player, creature, quest) - Can return true
--CREATURE_EVENT_ON_QUEST_REWARD = 34 -- // (event, player, creature, quest, opt) - Can return true
But really you want a zone update. When they enter/exit the area of your quest you update the phase.
Maybe something like this would work fow you:
Code:
PLAYER_EVENT_ON_UPDATE_ZONE = 27, // (event, player, newZone, newArea)
Global:RegisterPlayerEvent - Eluna