Advertisement
Guest User

lib do Killua

a guest
Sep 21st, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.65 KB | None | 0 0
  1. -- lib and functions by Vitor Bertolucci (Killua)
  2.  
  3. function warnPlayersWithStorage(storage, value, class, message) -- By Killua
  4.     if not value then value = 1 end
  5.     if not class then class = MESSAGE_SATUS_CONSOLE_WARNING end
  6.     if not storage or not message then return end
  7.     if #getPlayersOnline() == 0 then
  8.         return
  9.     end
  10.     for _, pid in pairs(getPlayersOnline()) do
  11.         if getPlayerStorageValue(pid, storage) == value then
  12.             doPlayerSendTextMessage(pid, class, message)
  13.         end
  14.     if getPlayerAccess(pid) >= 4 then  
  15.         doPlayerSendTextMessage(pid, class, "Message to those with storage "..storage..message) -- Gms will always receive the messages
  16.     end
  17.     end
  18. end
  19.  
  20. function getPlayerStorageZero(cid, storage) -- By Killua
  21.     local sto = getPlayerStorageValue(cid, storage)
  22.     return sto > 0 and sto or 0
  23. end
  24.  
  25. function getStorageZero(storage) -- By Killua
  26.     local sto = getGlobalStorageValue(storage)
  27.     return sto > 0 and sto or 0
  28. end
  29.  
  30. function countTable(table) -- By Killua
  31.     local y = 0
  32.     if type(table) == "table" then
  33.         for _ in pairs(table) do
  34.             y = y + 1
  35.         end
  36.         return y
  37.     end
  38.     return false
  39. end
  40.  
  41. function getPlayersInArea(frompos, topos) -- By Killua
  42.     local players_ = {}
  43.     local count = 1
  44.     for _, pid in pairs(getPlayersOnline()) do
  45.         if isInArea(getCreaturePosition(pid), frompos, topos) then
  46.             players_[count] = pid
  47.             count = count + 1
  48.         end
  49.     end
  50.     return countTable(players_) > 0 and players_ or false
  51. end
  52.  
  53. function getGuildNameByID(gid) -- By Killua
  54.     local query = db.getResult("SELECT `name` FROM `guilds` WHERE `id` = '"..gid.."'")
  55.     if query:getID() == -1 then
  56.         return false
  57.     end
  58.     local name = query:getDataString("name")
  59.     query:free()
  60.     return name
  61. end
  62.  
  63. function getContainerItemsInfo(containerUid) -- By Killua
  64.     local table = {}
  65.     if containerUid and containerUid > 0 then
  66.         local a = 0  
  67.         for i = 0, getContainerSize(containerUid) - 1 do
  68.             local item = getContainerItem(containerUid,i)
  69.             a = a + 1
  70.             table[a] = {uid = item.uid, itemid = item.itemid, quant = item.type}
  71.         end
  72.         return table
  73.     end
  74.     return false
  75. end
  76.  
  77. function getTableEqualValues(table) -- By Killua
  78.     local ck = {}
  79.     local eq = {}
  80.     if type(table) == "table" then
  81.         if countTable(table) and countTable(table) > 0 then
  82.             for i = 1, countTable(table) do
  83.                 if not isInArray(ck, table[i]) then
  84.                     ck[i] = table[i]
  85.                 else
  86.                     eq[i] = table[i]
  87.                 end
  88.             end
  89.             return countTable(eq) > 0 and eq or 0
  90.         end
  91.     end
  92.     return false
  93. end
  94.  
  95. function killuaGetItemLevel(uid) -- By Killua
  96.     local name = getItemName(uid)
  97.     local pos = 0
  98.     for i = 1, #name do
  99.         if string.byte(name:sub(i,i)) == string.byte('+') then
  100.             pos = i + 1
  101.             break
  102.         end
  103.     end
  104.     return tonumber(name:sub(pos,pos))
  105. end
  106.  
  107. k_table_storage_lib = {
  108.     filtrateString = function(str) -- By Killua
  109.         local tb, x, old, last = {}, 0, 0, 0
  110.         local first, second, final = 0, 0, 0
  111.         if type(str) ~= "string" then
  112.             return tb
  113.         end
  114.         for i = 2, #str-1 do
  115.             if string.byte(str:sub(i,i)) == string.byte(':') then
  116.                 x, second, last = x+1, i-1, i+2
  117.                 for t = last,#str-1 do
  118.                     if string.byte(str:sub(t,t)) == string.byte(',') then
  119.                         first = x == 1 and 2 or old
  120.                         old, final = t+2, t-1
  121.                         local index, var = str:sub(first,second), str:sub(last,final)
  122.                         tb[tonumber(index) or tostring(index)] = tonumber(var) or tostring(var)
  123.                         break
  124.                     end
  125.                 end
  126.             end
  127.         end
  128.         return tb
  129.     end,
  130.  
  131.     translateIntoString = function(tb) -- By Killua
  132.         local str = ""
  133.         if type(tb) ~= "table" then
  134.             return str
  135.         end
  136.         for i, t in pairs(tb) do
  137.             str = str..i..": "..t..", "
  138.         end
  139.         str = "a"..str.."a"
  140.         return tostring(str)
  141.     end
  142. }
  143.  
  144. function setPlayerTableStorage(cid, key, value) -- By Killua
  145.     return doPlayerSetStorageValue(cid, key, k_table_storage_lib.translateIntoString(value))
  146. end
  147.  
  148. function getPlayerTableStorage(cid, key) -- By Killua
  149.     return k_table_storage_lib.filtrateString(getPlayerStorageValue(cid, key))
  150. end
  151.  
  152. function setGlobalTableStorage(key, value) -- By Killua
  153.     return setGlobalStorageValue(key, k_table_storage_lib.translateIntoString(value))
  154. end
  155.  
  156. function getGlobalTableStorage(key) -- By Killua
  157.     return k_table_storage_lib.filtrateString(getGlobalStorageValue(key))
  158. end
  159.  
  160. function printTable(table, includeIndices,prnt) -- By Killua
  161.     if includeIndices == nil then includeIndices = true end
  162.     if prnt == nil then prnt = true end
  163.     if type(table) ~= "table" then
  164.         error("Argument must be a table")
  165.         return
  166.     end
  167.     local str, c = "{", ""
  168.     for v, b in pairs(table) do
  169.         if type(b) == "table" then
  170.             str = includeIndices and str..c.."["..v.."]".." = "..printTable(b,true,false) or str..c..printTable(b,false,false)
  171.         else
  172.             str = includeIndices and str..c.."["..v.."]".." = "..b or str..c..b
  173.         end
  174.         c = ", "
  175.     end
  176.     str = str.."}"
  177.     if prnt then print(str) end
  178.     return str
  179.  end
  180.  
  181. function checkString(str) -- By Killua
  182.     local check = true
  183.     for i = 1, #str do
  184.         local letra = string.byte(str:sub(i,i))
  185.         if letra >= string.byte('a') and letra <= string.byte('z') or letra >= string.byte('A') and letra <= string.byte('Z') or letra >= string.byte('0') and letra <= string.byte('9') then
  186.             check = true
  187.         else
  188.             check = false
  189.             break
  190.         end
  191.     end
  192.     return check
  193. end
  194.  
  195. function isWalkable(cid, pos, considerCreatures) -- Modified by Killua
  196.     if considerCreatures == nil then considerCreatures = true end
  197.     if getTopCreature(pos).uid and getTopCreature(pos).uid > 0 then
  198.         if considerCreatures then return false else return true end
  199.     end
  200.     pos.stackpos = 0
  201.     if getTileThingByPos(pos).uid ~= 0 then
  202.         if doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
  203.             return true
  204.         end
  205.     end
  206.     return false
  207. end
  208.  
  209. function isArmor(itemid) -- By Killua
  210.     return getItemInfo(itemid).armor > 0
  211. end
  212.  
  213. function isWeapon(uid) -- By Killua
  214.     return getItemWeaponType(uid) ~= 0
  215. end
  216.  
  217. function isShield(uid) -- By Killua
  218.     return getItemWeaponType(uid) == 5
  219. end
  220.  
  221. function isSword(uid) -- By Killua
  222.     return getItemWeaponType(uid) == 1
  223. end
  224.  
  225. function isClub(uid) -- By Killua
  226.     return getItemWeaponType(uid) == 2
  227. end
  228.  
  229. function isAxe(uid) -- By Killua
  230.     return getItemWeaponType(uid) == 3
  231. end
  232.  
  233. function isBow(uid) -- By Killua
  234.     return getItemWeaponType(uid) == 4
  235. end
  236.  
  237. function isWand(uid) -- By Killua
  238.     return getItemWeaponType(uid) == 7
  239. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement