1.1 Using Server Hooks for quests.
1.2 Escort Quests Introduction.
1.3 Escort Quest Finish.
1.4 Credits.
Note: You'll need LuaHypArc.
1.1 Using Server Hooks for quests.
Server hooks are implented in LuaHypArc, it's very useful.
All the server hooks:
Code:
OnNewCharacter(event, pPlayer, name, race, class) --> ID: 1
OnKillPlayer(event, pPlayer, pVictim) --> ID: 2
OnFirstEnterWorld(event, pPlayer) --> ID: 3
OnEnterWorld(event, pPlayer) --> ID: 4
OnGuildJoin(event, pPlayer, guildName) --> ID: 5
OnDeath(event, pPlayer) --> ID: 6
OnRepop(event, pPlayer) --> ID: 7
OnEmote(event, pPlayer, pUnit, emoteId) --> ID: 8
OnEnterCombat(event, pPlayer, pTarget) --> ID: 9
OnCastSpell(event, pPlayer, spellId) --> ID: 10
OnTick(event) --> ID: 11
OnLogoutRequest(event, pPlayer) --> ID: 12
OnLogout(event, pPlayer) --> ID: 13
OnQuestAccept(event, pPlayer, pQuestGiver, questId) --> ID: 14
OnZone(event, pPlayer, zoneId) --> ID: 15
OnChat(event, pPlayer, message, type, language) --> ID: 16
OnLoot(event, pPlayer, money, itemId) --> ID: 17
OnGuildCreate(event, pLeader, guildName) --> ID: 18
OnEnterWorld2(event, pPlayer) --> ID: 19
OnCharacterCreate(event, pPlayer) --> ID: 20
OnQuestCancelled(event, pPlayer, questId) --> ID: 21
OnQuestFinished(event, pPlayer, pQuestGiver, questId) --> ID: 22
OnHonorableKill(event, pPlayer, pKilled) --> ID: 23
OnArenaFinish(event, pPlayer, victory, rated) --> ID: 24
OnObjectLoot(event, pPlayer, pTarget, money, itemId) --> ID: 25
OnAreaTrigger(event, pPlayer, areaTriggerId) --> ID: 26
OnPostLevelUp(event, pPlayer) --> ID: 27
OnPreUnitDie(event, killer, victim) --> ID: 28
OnAdvanceSkillLine(event, pPlayer, skillId, current) --> ID: 29
The --> ID: 29 is to register the Server Hook:
Code:
RegisterServerHook(ID, "FunctionName")
Now the Server Hooks we are going to focus on are:
Code:
OnQuestAccept(event, pPlayer, pQuestGiver, questId) --> ID: 14
OnQuestCancelled(event, pPlayer, questId) --> ID: 21
OnQuestFinished(event, pPlayer, pQuestGiver, questId) --> ID: 22
A sample of using Server Hooks right:
Code:
function Blabla_OnQuestAccept(event, pPlayer, pQuestGiver, questId) -- Triggers if the player accepts the quest.
if(pQuestGiver == NPC_ID) and (questId == QUEST_ID) then -- Will check if the QuestGiver and the Quest is actually the right id, very useful.
pQuestGiver:SendChatMessage(12, 0, "Good luck with killing these beasts, champion!")
end
RegisterServerHook(14, "Blabla_OnQuestAccept")
Do not forget to register, it's VERY important.
You can do alot of variants, from reporting to a General or whatever, to escort quests.
1.2 Escort Quest Introduction.
Okay, so you learned how to use Server hooks now.
These hooks are the so called triggers I think they're one of the important things in Lua.
Now I'll teach you how to write a Escort Quest.
We'll start with a Server Hook (OnQuestAccept)
Code:
function OnQuestAccept(event, pPlayer, pQuestGiver, questId)
if(pQuestGiver == NPC_ID) and (questId == QUEST_ID) then
pQuestGiver:SendChatMessage(12, 0, "We better be going else they will notice I left!")
pQuestGiver:RegisterEvent("Escort_Move", 1000, 1)
end
end
The underlined is the first waypoint, it'll (if you have the quest and the QuestGiver is the right one) move in 1 second 1 time.
Code:
function Escort_Move(QuestGiver, Event)
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:MoveTo(0, x+10, y, z) -- You will need to have your own coords, I've just filled in something.
pQuestGiver:RegisterEvent("Escort_Move2", 5000, 1) -- Registering the second move
end
And so on.
1.3 Escort Quest Finish.
Spawning "Ambushers" at a waypoint:
Code:
pQuestGiver:RegisterEvent("Escort_Move3", 10000, 1)
end
function Escort_Move3(QuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "I really need to catch breath...")
pQuestGiver:RegisterEvent("Escort_Spawn", 5000, 1)
end
function Escort_Spawn(QuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "Watch out!")
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:SpawnCreature(NPC_ID2, x+5, z+5, y, 0)
pQuestGiver:SpawnCreature(NPC_ID3, x+10, z+5, y, 0)
pQuestGiver:SpawnCreature(NPC_ID4, x+7, z+7, y, 0)
pQuestGiver:RegisterEvent("Escort_Move4", 40000, 1)
end
This is quite obvious, but dont forget to set the next waypoint to a high number, else it'll be moving while your still fighting.
Now try and script your own Escort Quest, it'll be something like this:
Code:
local NPC_ID = Npc ID here
local QUEST_ID = Quest ID here
local NPC_ID2 = Npc ID Spawn 2
local NPC_ID3 = Npc ID Spawn 3
local NPC_ID4 = NPC ID Spawn 4
function OnQuestAccept(event, pPlayer, pQuestGiver, questId)
if(pQuestGiver == NPC_ID) and (questId == QUEST_ID) then
pQuestGiver:SendChatMessage(12, 0, "We better be going else they will notice I left!")
pQuestGiver:RegisterEvent("Escort_Move", 1000, 1)
end
end
function Escort_Move(QuestGiver, Event)
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:MoveTo(0, x+10, y, z)
pQuestGiver:RegisterEvent("Escort_Move2", 5000, 1)
end
function Escort_Move2(QuestGiver, Event)
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:MoveTo(0, x+10, y, z)
pQuestGiver:RegisterEvent("Escort_Move3", 10000, 1)
end
function Escort_Move3(QuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "I really need to catch breath...")
pQuestGiver:RegisterEvent("Escort_Spawn", 5000, 1)
end
function Escort_Spawn(QuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "Watch out!")
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:SpawnCreature(NPC_ID2, x+5, z+5, y, 0)
pQuestGiver:SpawnCreature(NPC_ID3, x+10, z+5, y, 0)
pQuestGiver:SpawnCreature(NPC_ID4, x+7, z+7, y, 0)
pQuestGiver:RegisterEvent("Escort_Move4", 40000, 1)
end
function Escort_Move4(QuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "Phew, that was close.")
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:MoveTo(1, x+10, z, y, 0)
pQuestGiver:RegisterEvent("Escort_Complete", 10000, 1)
end
function Escort_Complete(pQuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "Thanks for helping me man!")
pPlayer:QuestComplete(QUEST_ID)
pQuestGiver:Despawn(0, 1)
end
RegisterServerHook(14, "OnQuestAccept")
1.4 Credits
Me for scripting the guide.
Kerp for helping me.
Neglected for showing me how to use Lua correctly.
Related Topics:
http://www.mmowned.com/forums/emulat...vnt-quest.html
Remove the spaces.