adrianoswatt

Trade Items per Item

Mar 16th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5.  
  6. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  7. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  8. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  9. function onThink() npcHandler:onThink() end
  10.  
  11. -- [[ START THE SETTINGS ]] ---
  12. local knives = {
  13.     ["name1"] = {id = xxxx, tradeid = 2152, tradecount = 10},
  14.     ["name2"] = {id = xxxx, tradeid = xxxx, tradecount = 100},
  15.     ["name3"] = {id = xxxx, tradeid = xxxx, tradecount = 100},
  16. }
  17. -- [[ END FROM SETTINGS THINGS ]] ---
  18.  
  19. function creatureSayCallback(cid, type, msg)
  20. if(not npcHandler:isFocused(cid)) then
  21. return false
  22. end
  23. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  24. knife = knives[""..msg..""]
  25. if knife then
  26.     selfSay('You really wanna trade '..knife.tradecount..' '..getItemNameById(knife.tradeid)..' for a '..msg..'?', cid)
  27.     talkState[talkUser] = 1
  28.    
  29.     -- [[ CONFIRMANDO BROADCASTMESSAGES ]] --
  30. elseif talkState[talkUser] == 1 then
  31.     if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
  32.         if getPlayerItemCount(cid, knife.tradeid) >= knife.tradecount then
  33.             doPlayerRemoveItem(cid, knife.tradeid, knife.tradecount)
  34.             doPlayerAddItem(cid, knife.id, 1)
  35.             selfSay('Here are your item.', cid)
  36.             talkState[talkUser] = 0
  37.         else
  38.             selfSay('Sorry, but you don\'t have '..knife.tradecount..' '..getItemNameById(knife.tradeid)..'s.', cid)
  39.             talkState[talkUser] = 0
  40.         end
  41.     else
  42.         selfSay('Okay, see u later.', cid)
  43.         talkState[talkUser] = 0
  44.     end
  45. else
  46.     local str = ''
  47.     for index, result in pairs(knives) do
  48.         str = str.."{"..index.."}, "
  49.     end
  50.     selfSay('Sorry, but have to say a knife name: '..str..'.', cid)
  51.     talkState[talkUser] = 0
  52. end
  53.   return true
  54. end
  55. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  56. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment