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

Solved NPC conversation help please

highclick

New Member
Joined
Mar 21, 2011
Messages
80
Reaction score
4
This is what I've got so far.

TFS 0.3.6
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 storage = 5001

function creatureSayCallback(cid, type, msg)


    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
           
            if getPlayerStorageValue(cid, storage) == -1 then
                    selfSay("Silence! You are disturbing the ritual, either {help} me or be gone!", cid)
                    talkState[talkUser] = 1
                elseif getPlayerStorageValue(cid, storage) == 1 then
                    selfSay("Well, did you get me the feather?", cid)
                    talkState[talkUser] = 1
                else
                    selfSay("Thank you for helping me out!", cid)
            end
            npcHandler:addFocus(cid)
        else
            return false
        end 
    end
   
   
    if msg == "help" and talkState[talkUser] == 1 then
        selfSay("I need a chicken feather, will you get it for me?")
        talkState[talkUser] = 2
    elseif msg == "Yes" and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, 5890, 1) then
            selfSay("Thank you!", cid)
            doPlayerAddItem(cid, 2160, 3)
            doPlayerAddExp(cid, 5000)
            setPlayerStorageValue(cid, storage, 2)
        else
            selfSay("You don't have the feather")
        end       
    end
     
     
    if msg == "yes" and talkState[talkUser] == 2 then
        selfSay("Thank you, I'll be waiting for you!")
        setPlayerStorageValue(cid, storage, 1)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)


Errors:
After i type hi then "help" the npc starts too respond in default chat.
When I've got the feather she wont take it
 
Change too:

PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 storage = 5001

function creatureSayCallback(cid, type, msg)


    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
           
            if getPlayerStorageValue(cid, storage) == -1 then
                    selfSay("Silence! You are disturbing the ritual, either {help} me or be gone!", cid)
                    talkState[talkUser] = 1
                elseif getPlayerStorageValue(cid, storage) == 1 then
                    selfSay("Well, did you get me the feather?", cid)
                    talkState[talkUser] = 1
                else
                    selfSay("Thank you for helping me out!", cid)
            end
            npcHandler:addFocus(cid)
        else
            return false
        end 
    end
   
   
    if msg == "help" and talkState[talkUser] == 1 and getPlayerStorageValue(cid, storage) == -1 then
        selfSay("I need a chicken feather, will you get it for me?")
        talkState[talkUser] = 2
    elseif msg == "Yes" and talkState[talkUser] == 1 and getPlayerStorageValue(cid, storage) == 1 then
        if doPlayerRemoveItem(cid, 5890, 1) then
            selfSay("T", cid)
            doPlayerAddItem(cid, 2160, 3)
            doPlayerAddExp(cid, 5000)
            setPlayerStorageValue(cid, storage, 2)
        else
            selfSay("You don't have the feather")
        end       
    end
     
     
    if msg == "yes" and talkState[talkUser] == 2 then
        selfSay("Thank you, I'll be waiting for you!")
        setPlayerStorageValue(cid, storage, 1)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Still doesnt work
 
Line 37
change this
Code:
    elseif msg == "Yes" and talkState[talkUser] == 1 and getPlayerStorageValue(cid, storage) == 1 then
to this
Code:
    elseif msg == "Yes" and talkState[talkUser] == 2 and getPlayerStorageValue(cid, storage) == 1 then

You should really use a different word rather than Yes and yes
 
Line 37
change this
Code:
    elseif msg == "Yes" and talkState[talkUser] == 1 and getPlayerStorageValue(cid, storage) == 1 then
to this
Code:
    elseif msg == "Yes" and talkState[talkUser] == 2 and getPlayerStorageValue(cid, storage) == 1 then

You should really use a different word rather than Yes and yes

Thanks for the help! I fixed the issue, and yes i should use something else than "yes/yes".

Do you know how to make the answers non-case sensitive?

For example when i say "yes" instead of "Yes" the NPC doesnt reply
 
elseif string.lower(msg) == "yes" and talkState[talkUser] == 1 and getPlayerStorageValue(cid, storage) == 1 then
 
Thanks for the reply!
This works, however:
This will make it so that the NPC will react even if you say "yesterday" since its "msgCONTAINS".

Depends on your function implementation. It should look only for the word "yes". Sentences containing word "yes" would also return true for the function, but not words containing "yes" in them.
 
Back
Top