Advertisement
Rochet2

HasItemset command

Jul 9th, 2012
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.14 KB | None | 0 0
  1. local ItemSets = {}
  2.  
  3. local function InventorytypeToSlot(pType)
  4.     if(pType >= 1 and pType <= 10) then
  5.         return pType-1
  6.     elseif(pType == 11) then
  7.         return 10 -- , 11
  8.     elseif(pType == 12) then
  9.         return 12 -- , 13
  10.     elseif(pType == 16) then
  11.         return 14
  12.     elseif(pType == 13) then
  13.         return 20 -- One hand
  14.     elseif(pType == 17 or pType == 21) then
  15.         return 15
  16.     elseif(pType == 20) then
  17.         return 4
  18.     elseif(pType == 22) then
  19.         return 16
  20.     end
  21. end
  22.  
  23. local function LoadItemsets()
  24.     for k, v in pairs(ItemSets) do -- Clear the table for reload
  25.         ItemSets[k] = nil
  26.     end
  27.     local Q = WorldDBQuery("SELECT itemset, inventorytype, entry FROM items WHERE itemset > 0")
  28.     if(Q) then
  29.         for i = 1, Q:GetRowCount() do
  30.             local itemset, entry, slot = Q:GetColumn(0):GetULong(), Q:GetColumn(2):GetULong(), InventorytypeToSlot(Q:GetColumn(1):GetULong())
  31.             if(slot) then
  32.                 if(not ItemSets[itemset]) then
  33.                     ItemSets[itemset] = {}
  34.                 end
  35.                 if(not ItemSets[itemset][slot]) then
  36.                     ItemSets[itemset][slot] = {}
  37.                 end
  38.                 table.insert(ItemSets[itemset][slot], entry)
  39.             end
  40.             Q:NextRow()
  41.         end
  42.     end
  43. end
  44. LoadItemsets() -- Load the itemsets
  45.  
  46. function HasItemset(pPlayer, set)
  47.     if(not ItemSets[set]) then
  48.         return nil -- invalid set
  49.     end
  50.     if(set == 65 or set == 737) then
  51.         local item = pPlayer:GetEquippedItemBySlot(15)
  52.         if(item and (item:GetEntryId() == ItemSets[set][20][1] or item:GetEntryId() == ItemSets[set][20][2])) then
  53.             local item2 = pPlayer:GetEquippedItemBySlot(16)
  54.             if(item2 and (item2:GetEntryId() == ItemSets[set][20][1] or item2:GetEntryId() == ItemSets[set][20][2])) then
  55.                 return true
  56.             end
  57.         end
  58.         return false
  59.     end
  60.     for slot,tbl in pairs(ItemSets[set]) do
  61.         local Found = false
  62.         if(slot == 20) then
  63.             for k, entry in ipairs(tbl) do
  64.                 local item = pPlayer:GetEquippedItemBySlot(15)
  65.                 if(item and item:GetEntryId() == entry) then
  66.                     Found = true
  67.                     break
  68.                 end
  69.                 item = pPlayer:GetEquippedItemBySlot(16)
  70.                 if(item and item:GetEntryId() == entry) then
  71.                     Found = true
  72.                     break
  73.                 end
  74.                 break
  75.             end
  76.         elseif(slot == 10 or slot == 12) then
  77.             local first = false
  78.             for k, entry in ipairs(tbl) do
  79.                 local item = pPlayer:GetEquippedItemBySlot(slot)
  80.                 if(item and item:GetEntryId() == entry) then
  81.                     if(first) then
  82.                         Found = true
  83.                         break
  84.                     else
  85.                         first = true;
  86.                     end
  87.                 end
  88.                 item = pPlayer:GetEquippedItemBySlot(slot+1)
  89.                 if(item and item:GetEntryId() == entry) then
  90.                     if(first) then
  91.                         Found = true
  92.                         break
  93.                     else
  94.                         first = true;
  95.                     end
  96.                 end
  97.             end
  98.         else
  99.             for k, entry in ipairs(tbl) do
  100.                 local item = pPlayer:GetEquippedItemBySlot(slot)
  101.                 if(item and item:GetEntryId() == entry) then
  102.                     Found = true
  103.                     break
  104.                 end
  105.             end
  106.         end
  107.         if(not Found) then
  108.             return false
  109.         end
  110.     end
  111.     return true
  112. end
  113.  
  114. --[[
  115. -- Example:
  116.  
  117. local function TestFunc(event, pPlayer, Message, Type, Language, Misc)
  118.     if(HasItemset(pPlayer, tonumber(Message))) then -- say some itemset number ingame
  119.         pPlayer:SendAreaTriggerMessage("true")
  120.     else
  121.         pPlayer:SendAreaTriggerMessage("false")
  122.     end
  123. end
  124.  
  125. RegisterServerHook(16, TestFunc)
  126. -- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement