User Tag List

Results 1 to 7 of 7

Thread: How do I connect my npc to Lua Script ?

  1. #1
    Lurking Member
    Join Date
    Jan 2017
    Posts
    17
    XP
    115
    Level
    1
    Thanks
    8
    Thanked 1 Time in 1 Post

    Question How do I connect my npc to Lua Script ?

    Hey people,

    first of all happy new year to everyone.

    Now about my problem:


    I use Trinitycore Eluna ( Comunity Repack) and TrinityCores last Rev., for the very first time because I had to leave Arcemu.

    I have a problem with making my Lua Script work with my Custom Quest NPC.

    This Npc is the first login Quest in my World. I added quests into The required Templates inside Database and made in addition to That a small Escort Script.

    maybe I set some Value of my NPC wrong or my script ist Wrong, because everytime I reload Eluna Engine it doesnt show any errors. So it should normaly work but it doesnŽt at all.

    The Script I did running on TrinityCore Eluna:
    Code:
    local NAME = "test"
    local NPC_ID = 300000
    local NPC_ID2 = 300001
    local QUEST_ID = 1234567
    
    function test_OnQuestAccept(event, plr, creature, quest)
    if(creature:GetEntry() == NPC_ID) and (quest:GetId() == QUEST_ID) then
    creature:SendChatMessageToPlayer(12, 0, "Wir sollten uns lieber beeilen!", plr)
    creature:RegisterEvent("Escort_Move", 1000, 1)
    end
    end
    
    function test_EscortMove(creature, event)
    creature:GetX()
    creature:GetY()
    creature:GetZ()
    creature:MoveTo(1, -2865.35, -1481.59, 10.154058)
    creature:RegisterEvent("Escort_Complete", 10000, 1)
    end
    
    
    function test_EscortComplete(creature, event)
    creature:SendChatMessageToPlayer(12, 0, "So, hier sind wir sicher", plr)
    plr:CompleteQuest(QUEST_ID)
    creature:SpawnCreature( NPC_ID2, -2855.366455, -1478.071289, 10.153750, 3.324098, 8, 0)
    end
    
    RegisterCreatureEvent( NPC_ID, 1, test_OnQuestAccept, 0)
    RegisterCreatureEvent( NPC_ID, 2, test_EscortMove, 0)
    RegisterCreatureEvent( NPC_ID, 3, test_EscortComplete, 0)
    Well thanks for reading

    greats ^^
    Last edited by Meistro; 01-10-2017 at 08:58 PM.
    Achievements:
    Level I Member 7 days registered

  2. #2
    Original Poster
    Lurking Member
    Join Date
    Jan 2017
    Posts
    17
    XP
    115
    Level
    1
    Thanks
    8
    Thanked 1 Time in 1 Post
    Oh forgot to ask if anybody has got a link to an updated tutorial how to make npc( quest, gossip, etc...)
    This is the only problem i have because I'm a kind of new to trinity (Eluna) Batabase.
    If i had enough time I would study everything but life sucks you ^^.

    Edited
    Last edited by Meistro; 01-10-2017 at 08:59 PM.
    Achievements:
    Level I Member 7 days registered

  3. #3
    Original Poster
    Lurking Member
    Join Date
    Jan 2017
    Posts
    17
    XP
    115
    Level
    1
    Thanks
    8
    Thanked 1 Time in 1 Post
    Updated my progress

    Code:
     local NpcId = 300000
    local QuestId = 1234567
    local NPC_ID2 = 300001
    
    local function OnQuestAccept(event, player, creature, quest) -- on accepting
        
    	if 	(quest:GetId() == QuestId) then
    		creature:SendUnitSay("Wir sollten uns lieber beeilen!", 0)
    		creature:RegisterEvent(Escort_Move, 1000, 1)
        
    	end
    
    end
    
    function Escort_Move(event, creature, unit) -- NPC should start to walk to destination
        
    	creature:GetX()
        creature:GetY()
        creature:GetZ()
        Unit:MoveTo(150000, -2862.245361, -1480.336060, 10.154062, 1)
        creature:RegisterEvent(Escort_Complete, 10000, 1)
    
    end
    
    function Escort_Complete(event, player, creature, quest, opt) -- Completing quest when NPC arived to destination
        
    	if (quest:GetId() == QuestId) then
            creature:SendUnitSay("So, hier sind wir sicher", 0)
    		Player:CompleteQuest(QUEST_ID)
    		WorldObject:SpawnCreature( NPC_ID2, -2855.366455, -1478.071289, 3.324098, 8, o)
    		creature:SendUnitSay("wir haben es geschafft", 0)
    	
    	end
    
    end
    
    RegisterCreatureEvent(NpcId, 31, OnQuestAccept)
    RegisterCreatureEvent(NpcId, 27, Escort_Move)
    RegisterCreatureEvent(NpcId, 34, Escort_Complete)
    - - - Updated - - -

    okei I changed

    Code:
    Unit:MoveTo(150000, -2862.245361, -1480.336060, 10.154062, 1)
    to

    Code:
    creature:MoveTo(150000, -2862.245361, -1480.336060, 10.154062, 1)
    And it is working but when I spawn the NPC, he is just starting to walk even I didnt take any quest lol xD.

    Maybe I didnt register that The Quest should be accepted first, then it should say a smal "TExt", wait for 3 second and then first start to walk.
    Last edited by Meistro; 01-11-2017 at 01:14 PM.
    Achievements:
    Level I Member 7 days registered

  4. #4
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,536
    XP
    20,135,369
    Level
    500
    Thanks
    1,102
    Thanked 337 Times in 217 Posts
    [QUOTE=Meistro;40148]Updated my progress
    Code:
    function Escort_Move(event, creature, unit) -- NPC should start to walk to destination
        
    	creature:GetX()
        creature:GetY()
        creature:GetZ()
        Unit:MoveTo(150000, -2862.245361, -1480.336060, 10.154062, 1)
        creature:RegisterEvent(Escort_Complete, 10000, 1)
    
    end
    
    RegisterCreatureEvent(NpcId, 27, Escort_Move)
    And it is working but when I spawn the NPC, he is just starting to walk even I didnt take any quest lol xD.

    thats due to you have registered the Function `Escort_Move` to Event (27) CREATURE_EVENT_ON_MOVE_IN_LOS (event, creature, unit) - Does not actually check LOS. Just uses the sight range .

    So as soon as the npc detects motion it fires that function causing it to start walking to designated gps coords

    since it seems you want that Function to only fire after a player accepts a quest then i would remove
    Code:
    RegisterCreatureEvent(NpcId, 27, Escort_Move)
    completely because you are Registering a Timed event to it when they accept the quest
    Code:
    creature:RegisterEvent(Escort_Move, 1000, 1)
    Last edited by slp13at420; 01-24-2017 at 05:18 PM.
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  5. The Following User Says Thank You to slp13at420 For This Useful Post:


  6. #5
    Original Poster
    Lurking Member
    Join Date
    Jan 2017
    Posts
    17
    XP
    115
    Level
    1
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by slp13at420 View Post
    since it seems you want that Function to only fire after a player accepts a quest then i would remove
    Code:
    RegisterCreatureEvent(NpcId, 27, Escort_Move)
    completely because you are Registering a Timed event to it when they accept the quest
    Code:
    creature:RegisterEvent(Escort_Move, 1000, 1)

    wow I didn't see that coming :D nice ! I'll try that now :) thank you !!

    and do you think anything else should be okei ?

    greats

  7. #6
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,536
    XP
    20,135,369
    Level
    500
    Thanks
    1,102
    Thanked 337 Times in 217 Posts
    Code:
    	creature:GetX()
        creature:GetY()
        creature:GetZ()
    is just taking up memory space and time since its quering but doing nothing with the data. i.e. storing to a variable or directly applying so i would just delete those 3 lines.
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  8. The Following User Says Thank You to slp13at420 For This Useful Post:


  9. #7
    Original Poster
    Lurking Member
    Join Date
    Jan 2017
    Posts
    17
    XP
    115
    Level
    1
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by slp13at420 View Post
    Code:
    	creature:GetX()
        creature:GetY()
        creature:GetZ()
    is just taking up memory space and time since its quering but doing nothing with the data. i.e. storing to a variable or directly applying so i would just delete those 3 lines.

    okei thank you :) iŽll try my best ! ;) In the hope that IŽll finisch this one day xD

  10. The Following User Says Thank You to Meistro For This Useful Post:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •