• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved NPC responds to all keywords

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
Code:
The Forgotten Server, version 0.3.7_SVN (Crying Damson)
Hey everyone!
Seem to have run into a couple of problems that were brought to my attention.
First problem: If a player uses more then 1 keyword at a time, the npc will respond to all of them!
Second problem: If a player walks away or is idle for too long, the npc will say goodbye as normal... however the player's talkstate is not reset to zero, or none, and can continue where they left off.. or perhaps skip parts, or find another npc and continue a quest they are not meant to have access to!
I appreciate all help, big or small. :p
Code:
12:59 Xikini [17]: hi
12:59 Addon Checker: Welcome, Xikini! I have been expecting you.
13:00 Xikini [17]: help job name gossip backpack
13:00 Addon Checker: Keywords available: Job, Name, Backpack, Gossip.
13:00 Addon Checker: blah.
13:00 Addon Checker: blah blah.
13:00 Addon Checker: blah blah blah.
13:00 Addon Checker: You like my backpack do you? I can make you one for 15,000 gold coins! Would you like to do that?
13:05 Addon Checker: Good bye, Xikini!
13:05 Xikini [17]: hi
13:05 Addon Checker: Welcome, Xikini! I have been expecting you.
13:05 Xikini [17]: no
13:05 Addon Checker: Ah. That is a shame! I'll have to find some other fool to buy it then.
13:05 Xikini [17]: no
13:05 Xikini [17]: yes
Code:
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

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

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

   local player_gold  = getPlayerItemCount(cid,2148)
  local player_plat  = getPlayerItemCount(cid,2152)*100
  local player_crys  = getPlayerItemCount(cid,2160)*10000
  local player_money  = player_gold + player_plat + player_crys

   if msgcontains(msg, "help") then
     selfSay("Keywords available: Job, Name, Backpack, Gossip.", cid)
   end

   if msgcontains(msg, "job") then
     selfSay("blah.", cid)
   end

   if msgcontains(msg, "name") then
     selfSay("blah blah.", cid)
   end

   if msgcontains(msg, "gossip") then
     selfSay("blah blah blah.", cid)
   end

   if (getPlayerStorageValue(cid,45052) < 1) then
     if msgcontains(msg, "backpack") then
       selfSay("You like my backpack do you? I can make you one for 15,000 gold coins! Would you like to do that?", cid)
       talkState[talkUser] = 1
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
       if player_money >= 15000 then
         doPlayerRemoveMoney(cid,15000)
         selfSay("You carry that much money on you without a backpack? Imagine what you can carry now! Take care my good friend.", cid)
         doPlayerAddOutfit(cid, 136, 1)
         doPlayerAddOutfit(cid, 128, 1)
         setPlayerStorageValue(cid,45052,1)
         talkState[talkUser] = 0
       else
         selfSay("You simply don't have enough money my friend.", cid)
         talkState[talkUser] = 0
       end
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
       selfSay("Ah. That is a shame! I'll have to find some other fool to buy it then.", cid)
       talkState[talkUser] = 0
     end
   elseif (getPlayerStorageValue(cid,45052) == 1) then
     if msgcontains(msg, "backpack") then
     selfSay("You already have a backpack mate. I don't think you need another.", cid)
     end
   end

   return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Add:
Code:
function greet(cid)
    talkState[cid] = 0
    return true
end

after:
Code:
function onThink()  npcHandler:onThink()  end

and at the bottom add:
Code:
npcHandler:setCallback(CALLBACK_GREET, greet)

This will reset the talk state every time you say 'hi' to the NPC.

Edit:
What happened to the edit where you had figured out you should use elseif instead of if? It was correct. =P
 
Last edited:
Back
Top