Advertisement
fox1759

Untitled

Mar 26th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. local items = {
  2.  
  3. ["nomedoitem"] = {itemid = xxx , cost = xxx},
  4. ["nomedoitem"] = {itemid = xxx , cost = xxx},
  5.  
  6. }
  7.  
  8. local coins = 6527
  9.  
  10. local keywordHandler = KeywordHandler:new()
  11. local npcHandler = NpcHandler:new(keywordHandler)
  12. NpcSystem.parseParameters(npcHandler)
  13. local talkState = {}
  14. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  15. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  16. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  17. function onThink() npcHandler:onThink() end
  18.  
  19. function creatureSayCallback(cid, type, msg)
  20.  
  21. if not npcHandler:isFocused(cid) then
  22. return false
  23. end
  24.  
  25. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  26.  
  27.  
  28. msg = msg:lower()
  29.  
  30. local item_name = items[msg]
  31.  
  32. if msgcontains(msg, item_name) then
  33. selfSay("you are sure ?", cid)
  34. talkState[talkUser] = 1
  35. end
  36.  
  37. if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
  38. doPlayerAddItem(cid, items[msg].itemid, 1)
  39. doPlayerRemoveItem(cid, coins, items[msg].cost)
  40. selfSay("you received "..items[msg]..".", cid)
  41. talkState[talkUser] = 0
  42. elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
  43. selfSay("Bye!!", cid)
  44. talkState[talkUser] = 0
  45. end
  46.  
  47. return true
  48. end
  49.  
  50. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  51. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement