• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Npc

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
Can someone help me to make an npc that will give you a quest log with mission?

this is the quest log :
Lua:
Storage.GraveDanger.Questline

this is the mission :
Code:
Storage.GraveDanger.CobraBastion.Grave
 
The Quest Log is just a storage value checker.
If the player has the storage value, the quest log will automatically update.

So all you really need is a basic npc, and a way to give a storage value.

But here's both anyway. xD
data/xml/quests.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<quests>
    <quest name="Example Quest I" startstorageid="45001" startstoragevalue="1">
        <mission name="Example Mission 1" storageid="45001" startvalue="1" endvalue="2" >
            <missionstate id="1" description="Ask for quest again at the npc." />
            <missionstate id="2" description="You successfully finished the quest." />
        </mission>
    </quest>
</quests>
Lua:
local storage = 45001

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                          npcHandler:onThink()                        end

local function greetCallback(cid)
    npcHandler.topic[cid] = 0
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
  
    local player = Player(cid)

    if msgcontains(msg, "quest") then
        local storageValue = player:getStorageValue(storage)
        if storageValue < 1 then
            npcHandler:say("Would you like to start this quest?", cid)
            npcHandler.topic[cid] = 1
            return true
        elseif storageValue == 1 then
            npcHandler:say("Would you like to complete this quest?", cid)
            npcHandler.topic[cid] = 1
            return true
        else
            npcHandler:say("I have no more quests for you.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
      
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("Another time then.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        if player:getStorageValue(storage) < 1 then
            player:setStorageValue(storage, 1)
            npcHandler:say("Cool. You have started the quest.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        player:setStorageValue(storage, 2)
        npcHandler:say("Awesome. You have finished the quest.", cid)
        npcHandler.topic[cid] = 0
        return true
      
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
The Quest Log is just a storage value checker.
If the player has the storage value, the quest log will automatically update.

So all you really need is a basic npc, and a way to give a storage value.

But here's both anyway. xD
data/xml/quests.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<quests>
    <quest name="Example Quest I" startstorageid="45001" startstoragevalue="1">
        <mission name="Example Mission 1" storageid="45001" startvalue="1" endvalue="2" >
            <missionstate id="1" description="Ask for quest again at the npc." />
            <missionstate id="2" description="You successfully finished the quest." />
        </mission>
    </quest>
</quests>
Lua:
local storage = 45001

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                          npcHandler:onThink()                        end

local function greetCallback(cid)
    npcHandler.topic[cid] = 0
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    local player = Player(cid)

    if msgcontains(msg, "quest") then
        local storageValue = player:getStorageValue(storage)
        if storageValue < 1 then
            npcHandler:say("Would you like to start this quest?", cid)
            npcHandler.topic[cid] = 1
            return true
        elseif storageValue == 1 then
            npcHandler:say("Would you like to complete this quest?", cid)
            npcHandler.topic[cid] = 1
            return true
        else
            npcHandler:say("I have no more quests for you.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
     
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("Another time then.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        if player:getStorageValue(storage) < 1 then
            player:setStorageValue(storage, 1)
            npcHandler:say("Cool. You have started the quest.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        player:setStorageValue(storage, 2)
        npcHandler:say("Awesome. You have finished the quest.", cid)
        npcHandler.topic[cid] = 0
        return true
     
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
I do not have this address in my data data/xml/quests.lua
 
I had already done this, I had simply placed it in freequest, but I would like it to be with an NPC.
What are you talking about?

You wanted a quest log.
I gave you that. (albeit the wrong one for your server version, because you didn't provide that information in your main post)

You wanted an NPC.
I gave you that as well.

--
Am I missing something?
 
What are you talking about?

You wanted a quest log.
I gave you that. (albeit the wrong one for your server version, because you didn't provide that information in your main post)

You wanted an NPC.
I gave you that as well.

--
Am I missing something?
I get it, ah but it didn't work for me, can you help me create an NPC that will give you that QuestLog?


I would like the NPC to say "Hi, Mission" to give you this Quest Log from Grave Danger
 
I get it, ah but it didn't work for me, can you help me create an NPC that will give you that QuestLog?


I would like the NPC to say "Hi, Mission" to give you this Quest Log from Grave Danger

You gotta learn at some point dude.

I made the best example npc you're ever going to find.

Read the extremely simple code and figure out what you need to change.

Hint: It's line 1.
 
I get it, ah but it didn't work for me, can you help me create an NPC that will give you that QuestLog?


I would like the NPC to say "Hi, Mission" to give you this Quest Log from Grave Danger
I understand that the startstorageID but I changed it and it didn't work lol
 
Back
Top