Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. local Topic = {}
  6. local items = {
  7.     ["shrimp"] = { 2670, 10, 10000 }
  8. }
  9.  
  10. function onCreatureAppear(cid)          npcHandler:onCreatureAppear(cid)            end
  11. function onCreatureDisappear(cid)       npcHandler:onCreatureDisappear(cid)         end
  12. function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)    end
  13. function onThink()                      npcHandler:onThink()                        end
  14.  
  15. function creatureSayCallback(cid, type, msg)
  16.     for m, v in ipairs(items) do
  17.         if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
  18.             for i = 1, #v do
  19.                 if getPlayerItemCount(cid, v[1][i]) >= 1 then
  20.                     npcHandler:say("Hello " .. getCreatureName(cid) .. ". How can I help you?", cid)
  21.                     Topic[cid] == 1
  22.                 else
  23.                     npcHandler:say("How can I help you?", cid)
  24.                     Topic[cid] = nil
  25.                 end
  26.                
  27.                 break
  28.             end
  29.             npcHandler:addFocus(cid)
  30.         elseif(not npcHandler:isFocused(cid)) then
  31.             return false
  32.         elseif Topic[cid] == 1 then
  33.             for i = 1, #m do
  34.                 if msgcontains(msg, m[i]) then
  35.                     npcHandler:say("Do you want to trade " .. m[i] .. " for experience?", cid)
  36.                     Topic[cid] = 2
  37.                 else
  38.                     npcHandler:say("Sorry, what was that?", cid)
  39.                     Topic[cid] = 0
  40.                 end
  41.                
  42.                 break
  43.             end
  44.         elseif Topic[cid] == 2 then
  45.             if msgcontains(cid, "yes") then
  46.                 for i = 1, #v do
  47.                     if doPlayerRemoveItem(cid, v[1][i], v[2][i] or 1) then
  48.                         npcHandler:say("Here you are!", cid)
  49.                         doPlayerAddExperience(cid, v[3][i])
  50.                         doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  51.                         Topic[cid] = 0
  52.                     else
  53.                         npcHandler:say("You don't have the items!", cid)
  54.                         Topic[cid] = 0
  55.                     end
  56.                    
  57.                     break
  58.                 end
  59.             elseif msgcontains(cid, "no") then
  60.                 npcHandler:say("Then not.", cid)
  61.                 Topic[cid] = 0
  62.             end
  63.         elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHandler:isFocused(cid) then
  64.             npcHandler:say("Good bye.", cid, TRUE)
  65.             Topic[cid] = nil
  66.             npcHandler:releaseFocus(cid)
  67.         end
  68.            
  69.         return true
  70.     end
  71. end
  72.  
  73. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  74. npcHandler:setMessage(MESSAGE_WALKAWAY, "How rude!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement