adrianoswatt

NPC Outfitter

Mar 7th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 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 cfg = {
  13.     outfit = {nome = "Royalist", sto = 322},
  14.     task = {t = true, key = 00000, value = 1, name = ""},
  15.     itemList = {
  16.         [1] = {id = 2160, count = 10},
  17.         [2] = {id = 2152, count = 15},
  18.     }
  19. }
  20. -- [[ END FROM SETTINGS THINGS ]] ---
  21.  
  22. function creatureSayCallback(cid, type, msg)
  23. if(not npcHandler:isFocused(cid)) then
  24. return false
  25. end
  26. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  27.  
  28. if (msgcontains(msg:lower(), ''..cfg.outfit.nome:lower()..'')) then
  29.     if getPlayerStorageValue(cid, cfg.outfit.sto) < 1 then
  30.         list = getItemList(cid, cfg.itemList)
  31.         if cfg.task.t then
  32.             selfSay('You have completed the '..cfg.task.name..' mission and wanna give me '..list..'?', cid)
  33.         else
  34.             selfSay('You have '..list..' to trade for the '..cfg.outfit.nome..' outfit?', cid)
  35.         end
  36.         talkState[talkUser] = 1
  37.     else
  38.         selfSay('Sorry but you already can wear this outfit.', cid)
  39.         talkState[talkUser] = 0
  40.     end
  41.    
  42. elseif talkState[talkUser] == 1 then
  43.     if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
  44.         if cfg.task.t then
  45.             if getPlayerStorageValue(cid, cfg.task.key) >= cfg.task.value then
  46.                 ctrl = 0
  47.                 for i = 1, #cfg.itemList do
  48.                     if getPlayerItemCount(cid, cfg.itemList[i].id) >= cfg.itemList[i].count then
  49.                         ctrl  = ctrl + 1
  50.                     else
  51.                         selfSay('I\'m so sorry, but you don\'t have '..cfg.itemList[i].count..' '..getItemNameById(cfg.itemList[i].id)..'.', cid)
  52.                         talkState[talkUser] = 0
  53.                         return true
  54.                     end
  55.                     if ctrl == #cfg.itemList then
  56.                         for x = 1, #cfg.itemList do
  57.                             doPlayerRemoveItem(cid, cfg.itemList[i].id, cfg.itemList[i].count)
  58.                         end
  59.                         setPlayerStorageValue(cid, cfg.outfit.sto, 1)
  60.                         selfSay('Congratulations, now you can wear the '..cfg.outfit.nome..' outfit.', cid)
  61.                         talkState[talkUser] = 0
  62.                         return true
  63.                     end
  64.                 end
  65.             else
  66.                 selfSay('Sorry, but you don\'t have the '..cfg.task.name..' mission.', cid)
  67.                 talkState[talkUser] = 0
  68.             end
  69.         else
  70.             ctrl = 0
  71.             for i = 1, #cfg.itemList do
  72.                 if getPlayerItemCount(cid, cfg.itemList[i].id) >= cfg.itemList[i].count then
  73.                     ctrl  = ctrl + 1
  74.                 else
  75.                     selfSay('I\'m so sorry, but you don\'t have '..cfg.itemList[i].count..' '..getItemNameById(cfg.itemList[i].id)..'.', cid)
  76.                     talkState[talkUser] = 0
  77.                     return true
  78.                 end
  79.                 if ctrl == #cfg.itemList then
  80.                     for x = 1, #cfg.itemList do
  81.                         doPlayerRemoveItem(cid, cfg.itemList[i].id, cfg.itemList[i].count)
  82.                     end
  83.                     setPlayerStorageValue(cid, cfg.outfit.sto, 1)
  84.                     selfSay('Congratulations, now you can wear the '..cfg.outfit.nome..' outfit.', cid)
  85.                     return true
  86.                 end
  87.             end
  88.         end
  89.         talkState[talkUser] = 0
  90.     else
  91.         selfSay('Okay, see u later.', cid)
  92.         talkState[talkUser] = 0
  93.     end
  94.    
  95. end
  96.   return true
  97. end
  98. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  99. npcHandler:addModule(FocusModule:new())
  100.  
  101.  
  102. -------- [[ FUNCTION SWATT IN LIBRARY ]] --------
  103. function getItemList(cid, list) -- Retorna Lista de Premiação
  104.     local awardList = ''
  105.     get = list
  106.     for a = 1, #list do
  107.         if (a+1) == #list then
  108.             if list[a].count <= 1 then
  109.                 awardList = awardList.."{"..list[a].count.."x "..getItemNameById(list[a].id).."} and "
  110.             else
  111.                 awardList = awardList.."{"..list[a].count.."x "..getItemPluralNameById(list[a].id).."} and "
  112.             end
  113.         elseif (a+1) > #list then
  114.             if list[a].count <= 1 then
  115.                 awardList = awardList.."{"..list[a].count.."x "..getItemNameById(list[a].id).."}"
  116.             else
  117.                 awardList = awardList.."{"..list[a].count.."x "..getItemPluralNameById(list[a].id).."}"
  118.             end
  119.         else
  120.             if list[a].count <= 1 then
  121.                 awardList = awardList.."{"..list[a].count.."x "..getItemNameById(list[a].id).."}, "
  122.             else
  123.                 awardList = awardList.."{"..list[a].count.."x "..getItemPluralNameById(list[a].id).."}, "
  124.             end
  125.         end
  126.     end
  127. return awardList
  128. end
Add Comment
Please, Sign In to add comment