• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] How do I connect my npc to Lua Script ?

Status
Not open for further replies.

Meistro

New member
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:

Meistro

New member
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:

Meistro

New member
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. :eek:
 
Last edited:

slp13at420

Mad Scientist
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:

Meistro

New member
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
 

slp13at420

Mad Scientist
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.
 

Meistro

New member
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
 
Status
Not open for further replies.
Top