[Lua] How to script a quest. menu

User Tag List

Results 1 to 7 of 7
  1. #1
    Daimyo2704's Avatar Member
    Reputation
    37
    Join Date
    Jan 2009
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Lua] How to script a quest.

    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.
    Last edited by Daimyo2704; 11-30-2009 at 02:54 PM.

    thanks to P1raten

    [Lua] How to script a quest.
  2. #2
    JD's Avatar Fedora Potato Johnson V
    Reputation
    1113
    Join Date
    Jan 2008
    Posts
    3,129
    Thanks G/R
    12/89
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unreadable blue color is unreadable and blue...
    The link at the end doesn't work.

    Nice guide tho




  3. #3
    Daimyo2704's Avatar Member
    Reputation
    37
    Join Date
    Jan 2009
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Link works now, changing blue colour.

    thanks to P1raten

  4. #4
    Warriar's Avatar Active Member
    Reputation
    31
    Join Date
    May 2009
    Posts
    149
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Daimyo, You wolferine?

  5. #5
    Moranimal's Avatar Active Member
    Reputation
    16
    Join Date
    Apr 2007
    Posts
    102
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks i was looking for this +rep

  6. #6
    thebigman's Avatar Contributor Reliable Trader
    CoreCoins Purchaser
    Reputation
    89
    Join Date
    Dec 2008
    Posts
    605
    Thanks G/R
    2/0
    Trade Feedback
    26 (96%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how does it know if the player is around so it can fail his quest if he isnt there? I dont want players taking the quest, standing in one place, and then finishing the quest anyway.

    I guess I can have it where if the npc dies he fails.
    Last edited by thebigman; 03-22-2010 at 05:55 PM.

  7. #7
    newtech's Avatar Active Member
    Reputation
    57
    Join Date
    Aug 2008
    Posts
    308
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice guide idd

Similar Threads

  1. [PQR] How to script (lua) Mana Sapphire for Mages (auto cast at low mana)
    By dealerx in forum WoW Bot Maps And Profiles
    Replies: 11
    Last Post: 10-11-2016, 08:34 AM
  2. [Tutorial] [Tutorial] How to Script a Phased Boss With LUA.
    By Dimarxx in forum WoW EMU Guides & Tutorials
    Replies: 3
    Last Post: 07-26-2010, 05:06 AM
  3. How to script LUA complete tut.
    By Found in forum WoW EMU Guides & Tutorials
    Replies: 16
    Last Post: 04-13-2009, 10:34 PM
  4. Replies: 0
    Last Post: 02-17-2009, 03:53 AM
  5. How to Create a Quest
    By JulianX in forum WoW EMU Guides & Tutorials
    Replies: 22
    Last Post: 12-19-2007, 08:50 PM
All times are GMT -5. The time now is 04:17 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search