• 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!

a little help with this npc script

CesarZ

Well-Known Member
Joined
Sep 20, 2012
Messages
268
Solutions
4
Reaction score
63
i need a little help with this script that i wrote is not doing what its suppose to do.
is a 1 mission npc quest.

Lua:
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 creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return true
    end
    local player = Player(cid)
 -- mission
if (msgcontains(msg, "enter the club")) and player:getStorageValue(223344) < 1 then -- checking if the quest hasnt been done
    npcHandler:say("If you are trying to enter this club you have to do me a {favor}.", cid) -- require to enter
                    npcHandler.topic[cid] = 1 --
            elseif (msgcontains(msg, "favor")) and npcHandler.topic[cid] == 1 then -- asking for favor
                    npcHandler:say("I need you to go to the bandit cave and get back that golden amulet they took from me. Can you do that?", cid) -- instruction
          elseif (msgcontains(msg, "yes")) and npcHandler.topic[cid] == 1 then -- quest approval
                  npcHandler:say("Alright, bring it back to me and say {golden amulet}. Be careful.. They are a group of rebellions. While you facing the thief that stole my amulet there will be a lot of bad guys on you. You must gather a team to get this quest done. Their camp is located on the south side outside the City. Good luck..", cid)
                  player:setStorageValue(223345, 1) -- quest started storage value
                  doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have unlocked the Bandict Cave Bridge pass.")
          elseif  (msgcontains(msg, "no")) and npcHandler.topic[cid] == 1 then
                  npcHandler:say("Alright.", cid)
                
                
                
                -- amulet checking and exchange           
                elseif player:getStorageValue(223345) >= 1 then -- elseif player has started the quest then ask him if he has the amulet.
                        npcHandler:say("You have my amulet? just say {golden amulet}.", cid)
                        if (msgcontains(msg, "golden amulet")) and player:getItemCount(2130) >= 1 then
                            player:removeItem(2130, 1)
                            npcHandler:say("Thank you, Welcome to the club brother!", cid)
                            player:setStorageValue(223344, 1) -- quest done storage value
                        else
                        npcHandler:say("Come back when you get the amulet please.", cid) -- if not then this
                        end
else
    npcHandler:say("You are already Welcome!.", cid) -- if player done the quest message.
end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Heyyyyy!!! whats up you want to {enter the club}? |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Always be on guard, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "This ungraceful haste is most suspicious!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Lua:
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 creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return true
    end
    local player = Player(cid)
 -- mission
 
if (msgcontains(msg, "enter the club")) then

    if player:getStorageValue(223345) == 2 then -- checking if the quest hasnt been done
        npcHandler:say("You are...
Do you get any error messages in console? Or what's it doing and what's the expected result?
No, I'm not getting any error.

its just repeating the quest as if i didnt started.
i started the quest i got the storageValue. he should read the value then ask me if i have the item then i say golden amulet and "quest done" storage value should be given to me.

whats currently going on.

1624793464467.png
 
Lua:
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 creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return true
    end
    local player = Player(cid)
 -- mission
 
if (msgcontains(msg, "enter the club")) then

    if player:getStorageValue(223345) == 2 then -- checking if the quest hasnt been done
        npcHandler:say("You are already Welcome!.", cid) -- if player done the quest message.
        npcHandler.topic[cid] = 0
    end
    
    if player:getStorageValue(223345) < 2 then -- checking if the quest hasnt been done
        npcHandler:say("If you are trying to enter this club you have to do me a {favor}.", cid) -- require to enter
            npcHandler.topic[cid] = 1
    end
    
    
    
    elseif (msgcontains(msg, "favor")) and npcHandler.topic[cid] == 1 then -- asking for favor
            npcHandler:say("I need you to go to the bandit cave and get back that golden amulet they took from me. Can you do that?", cid) -- instruction
            npcHandler.topic[cid] = 2
        elseif (msgcontains(msg, "yes")) and npcHandler.topic[cid] == 2 then -- quest approval
            npcHandler:say("Alright, bring it back to me and say {golden amulet}. Be careful.. They are a group of rebellions. While you facing the thief that stole my amulet there will be a lot of bad guys on you. You must gather a team to get this quest done. Their camp is located on the south side outside the City. Good luck..", cid)
            player:setStorageValue(223345, 1) -- quest started storage value
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have unlocked the Bandict Cave Bridge pass.")
        elseif  (msgcontains(msg, "no")) and npcHandler.topic[cid] == 2 then
                  npcHandler:say("Alright, goodbye.", cid)
                  npcHandler.topic[cid] = 0
                  end

                
                
                -- amulet checking and exchange           
    if player:getStorageValue(223345) == 1 then -- elseif player has started the quest then ask him if he has the amulet.
        npcHandler:say("You have my amulet? just say {golden amulet}.", cid)
        npcHandler.topic[cid] = 3
     if (msgcontains(msg, "golden amulet")) and npcHandler.topic[cid] == 3 then
        if player:removeItem(2130, 1) then
            npcHandler:say("Thank you, Welcome to the club brother!", cid)
            player:setStorageValue(223345, 2) -- quest done storage value
            else
            npcHandler:say("Come back when you get the amulet please.", cid) -- if not then this
            end
        end
    end
end


npcHandler:setMessage(MESSAGE_GREET, "Heyyyyy!!! whats up you want to {enter the club}? |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Always be on guard, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "This ungraceful haste is most suspicious!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

something like this should work
 
Solution
Back
Top