Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 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.     [{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 v, x in ipairs(items) do
  17.         if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
  18.             if getPlayerItemCount(cid, v[1]) >= v[2] then
  19.                 npcHandler:say("Hello " .. getCreatureName(cid) .. ". Would you like to {exchange} 10 shrimp for some experience?", cid)
  20.                 Topic[cid] = 1
  21.             else
  22.                 npcHandler:say("Hmm...don't think I can help you.", cid)
  23.                 Topic[cid] = 0
  24.             end
  25.             npcHandler:addFocus(cid)
  26.         elseif(not npcHandler:isFocused(cid)) then
  27.             return false
  28.         elseif Topic[cid] == 1 then
  29.             if msgcontains(msg, "exchange") then
  30.                 npcHandler:say("Are you sure you want to exchange " .. v[2] .. "x " .. getItemInfo(v[1]).name .. " for " .. x .. " experience points?", cid)
  31.                 Topic[cid] = 2
  32.             else
  33.                 npcHandler:say("What was that? I don't understand you.", cid)
  34.                 Topic[cid] = 1
  35.             end
  36.         elseif Topic[cid] == 2 then
  37.             if msgcontains(msg, "yes") then
  38.                 if doPlayerRemoveItem(cid, v[1], v[2] or 1) then
  39.                     npcHandler:say("Great! Here you are.", cid)
  40.                     doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  41.                     doPlayerAddExperience(cid, x)
  42.                     Topic[cid] = 0
  43.                 else
  44.                     npcHandler:say("You do not have the item with you.", cid)
  45.                     Topic[cid] = 0
  46.                 end
  47.             elseif msgcontains(msg, "no") then
  48.                 npcHandler:say("Well, then leave.", cid)
  49.                 Topic[cid] = 0
  50.             end
  51.         elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHandler:isFocused(cid) then
  52.             npcHandler:say("Good bye.", cid, TRUE)
  53.             Topic[cid] = nil
  54.             npcHandler:releaseFocus(cid)
  55.         end
  56.        
  57.         return true
  58.     end
  59. end
  60.  
  61. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  62. npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a good day!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement