Advertisement
Guest User

global.lua diff

a guest
Aug 10th, 2013
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.97 KB | None | 0 0
  1. ACCOUNT_TYPE_NORMAL = 1
  2. ACCOUNT_TYPE_TUTOR = 2
  3. ACCOUNT_TYPE_GAMEMASTER = 3
  4.  
  5. MESSAGE_LOOT = 29
  6. MESSAGE_TRADE_NPC = 30
  7. MESSAGE_EVENT_GUILD = 31
  8. MESSAGE_PARTY_MANAGEMENT = 32
  9. MESSAGE_PARTY = 33
  10. MESSAGE_REPORT = 36
  11. MESSAGE_HOTKEY_USE = 37
  12. MESSAGE_TUTORIAL_HINT = 38
  13.  
  14. getPlayerByNameWildcard = getPlayerByName
  15. doCreatureSetStorage = setPlayerStorageValue
  16. doPlayerSetStorageValue = setPlayerStorageValue
  17. getCreatureStorage = getPlayerStorageValue
  18. getCreatureSkullType = getPlayerSkullType
  19. getCreatureSkull = getPlayerSkullType
  20. getNpcId = getNpcCid
  21. doBroadcastMessage = broadcastMessage
  22. db.executeQuery = db.query
  23. getStorage = getGlobalStorageValue
  24. doSetStorage = setGlobalStorageValue
  25. getItemNameById = getItemName
  26. getItemWeightById = getItemWeight
  27. getItemDescriptionsById = getItemDescriptions
  28. getItemInfo = getItemDescriptions
  29. getThingFromPos = getThingfromPos
  30. getThingPosition = getThingPos
  31.  
  32. string.boolean = function (input)
  33.     local tmp = type(input)
  34.     if(tmp == 'boolean') then
  35.         return input
  36.     end
  37.  
  38.     if(tmp == 'number') then
  39.         return input > 0
  40.     end
  41.  
  42.     local str = string.lower(tostring(input))
  43.     return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
  44. end
  45. getBooleanFromString = string.boolean
  46.  
  47. function getPlayerAccount(pid)
  48. getAccountNumberByPlayerName(getPlayerByName(pid))
  49. end
  50. function getItemArticleById(itemid)
  51. return getItemInfo(itemid).article
  52. end
  53. function getItemPluralNameById(itemid)
  54. return getItemInfo(itemid).plural
  55. end
  56.  
  57. math.round = function(num, idp)
  58.     return tonumber(string.format("%." .. (idp or 0) .. "f", num))
  59. end
  60.  
  61. exhaustion =
  62. {
  63.     check = function (cid, storage)
  64.         if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
  65.             return false
  66.         end
  67.  
  68.         return getPlayerStorageValue(cid, storage) >= os.time()
  69.     end,
  70.  
  71.     get = function (cid, storage)
  72.         if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
  73.             return false
  74.         end
  75.  
  76.         local exhaust = getPlayerStorageValue(cid, storage)
  77.         if(exhaust > 0) then
  78.             local left = exhaust - os.time()
  79.             if(left >= 0) then
  80.                 return left
  81.             end
  82.         end
  83.  
  84.         return false
  85.     end,
  86.  
  87.     set = function (cid, storage, time)
  88.         setPlayerStorageValue(cid, storage, os.time() + time)
  89.     end,
  90.  
  91.     make = function (cid, storage, time)
  92.         local exhaust = exhaustion.get(cid, storage)
  93.         if(not exhaust) then
  94.             exhaustion.set(cid, storage, time)
  95.             return true
  96.         end
  97.  
  98.         return false
  99.     end
  100. }
  101.  
  102. function doComparePositions(position, positionEx)
  103.     return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
  104. end
  105.  
  106. function getArea(position, x, y)
  107.     local t = {}
  108.     for i = (position.x - x), (position.x + x) do
  109.         for j = (position.y - y), (position.y + y) do
  110.             table.insert(t, {x = i, y = j, z = position.z})
  111.         end
  112.     end
  113.  
  114.     return t
  115. end
  116.  
  117. function Position(x, y, z, stackpos)
  118.     local position = {x = 0, y = 0, z = 0}
  119.     if(isNumeric(x .. y .. z)) then
  120.         position = {x = x, y = y, z = z}
  121.         if(isNumeric(stackpos)) then
  122.             position.stackpos = stackpos
  123.         end
  124.     end
  125.  
  126.     return position
  127. end
  128.  
  129. function isValidPosition(position)
  130.     return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
  131.         and position.y > 0 and position.z >= 0 and position.z <= 15)
  132. end
  133. -- googled functions used to convert ip
  134. -- source: http://www.dialectronics.com/Lua/code/BinDecHex.shtml
  135. local hex2bin = {
  136.     ["0"] = "0000",
  137.     ["1"] = "0001",
  138.     ["2"] = "0010",
  139.     ["3"] = "0011",
  140.     ["4"] = "0100",
  141.     ["5"] = "0101",
  142.     ["6"] = "0110",
  143.     ["7"] = "0111",
  144.     ["8"] = "1000",
  145.     ["9"] = "1001",
  146.     ["a"] = "1010",
  147.         ["b"] = "1011",
  148.         ["c"] = "1100",
  149.         ["d"] = "1101",
  150.         ["e"] = "1110",
  151.         ["f"] = "1111"
  152.     }
  153.    
  154. function Hex2Bin(s)
  155. local ret = ""
  156. local i = 0
  157.     for i in string.gfind(s, ".") do
  158.         i = string.lower(i)
  159.  
  160.         ret = ret.." "..hex2bin[i]
  161.     end
  162.     return ret
  163. end
  164. function Bin2Dec(s)
  165. local num = 0
  166. local ex = string.len(s) - 1
  167. local l = 0
  168.     l = ex + 1
  169.     for i = 1, l do
  170.         b = string.sub(s, i, i)
  171.         if b == "1" then
  172.             num = num + 2^ex
  173.         end
  174.         ex = ex - 1
  175.     end
  176.     return string.format("%u", num)
  177. end
  178.  
  179. -- source: http://www.forums.evilmana.com/psp-lua-codebase/string-replace-string-insert/
  180. function string.replace(value, insert, place)
  181.     if place == nil then
  182.         place = string.len(value)+1
  183.     end
  184.     return string.sub( value, 1, place-1) .. string.gsub(string.sub(value, place,place), string.sub(value, place,place), insert) .. string.sub( value, place+string.len(insert), string.len(value))
  185. end
  186. -- end of googled functions
  187.  
  188. function getPlayerIPv4(pid)
  189. local numbers = {}
  190. local ip_bin = Hex2Bin(string.format("%x",getPlayerIp(pid)))
  191. local a = string.replace(ip_bin,".",-10)
  192. local b = string.replace(a,".",-20)
  193. local c = string.replace(b,".",-30)
  194. local d = string.gsub(c, " ", "")
  195. local e = string.sub(d, -8, -1)
  196. local f = string.sub(d, -17, -10)
  197. local g = string.sub(d, -26, -19)
  198. local h = string.sub(d, -35, -28)
  199. return Bin2Dec(e).."."..Bin2Dec(f).."."..Bin2Dec(g).."."..Bin2Dec(h)
  200. end
  201.  
  202. function doRevertIp(str)
  203.     local i, ip = 4, {}
  204.     for b in str:gmatch("(%d+).?") do
  205.         ip[i] = b
  206.         i = i - 1
  207.     end
  208.  
  209.     if(not ip[1] or not ip[2] or not ip[3] or not ip[4]) then
  210.         return nil
  211.     end
  212.  
  213.     return table.concat(ip, ".")
  214. end
  215.  
  216. function choose(...)
  217.     local arg = {...}
  218.     return arg[math.random(1, table.maxn(arg))]
  219. end
  220.  
  221. function doPlayerAddExpEx(cid, amount)
  222.     if(not doPlayerAddExp(cid, amount)) then
  223.         return false
  224.     end
  225.  
  226.     local position = getThingPosition(cid)
  227.     doPlayerSendTextMessage(cid, MESSAGE_EXPERIENCE, "You gained " .. amount .. " experience.", amount, COLOR_WHITE, position)
  228.  
  229.     local spectators, name = getSpectators(position, 7, 7), getCreatureName(cid)
  230.     for _, pid in ipairs(spectators) do
  231.         if(isPlayer(pid) and cid ~= pid) then
  232.             doPlayerSendTextMessage(pid, MESSAGE_EXPERIENCE_OTHERS, name .. " gained " .. amount .. " experience.", amount, COLOR_WHITE, position)
  233.         end
  234.     end
  235.  
  236.     return true
  237. end
  238.  
  239. function getItemTopParent(uid)
  240.     local parent = getItemParent(uid)
  241.     if(not parent or parent.uid == 0) then
  242.         return nil
  243.     end
  244.  
  245.     while(true) do
  246.         local tmp = getItemParent(parent.uid)
  247.         if(tmp and tmp.uid ~= 0) then
  248.             parent = tmp
  249.         else
  250.             break
  251.         end
  252.     end
  253.  
  254.     return parent
  255. end
  256.  
  257. function getItemHolder(uid)
  258.     local parent = getItemParent(uid)
  259.     if(not parent or parent.uid == 0) then
  260.         return nil
  261.     end
  262.  
  263.     local holder = nil
  264.     while(true) do
  265.         local tmp = getItemParent(parent.uid)
  266.         if(tmp and tmp.uid ~= 0) then
  267.             if(tmp.itemid == 1) then -- a creature
  268.                 holder = tmp
  269.                 break
  270.             end
  271.  
  272.             parent = tmp
  273.         else
  274.             break
  275.         end
  276.     end
  277.  
  278.     return holder
  279. end
  280.  
  281. function valid(f)
  282.     return function(p, ...)
  283.         if(isCreature(p)) then
  284.             return f(p, ...)
  285.         end
  286.     end
  287. end
  288.  
  289. function doSetItemText(uid, text, writer, date)
  290.     local thing = getThing(uid)
  291.     if(thing.itemid < 100) then
  292.         return false
  293.     end
  294.  
  295.     doItemSetAttribute(uid, "text", text)
  296.     if(writer ~= nil) then
  297.         doItemSetAttribute(uid, "writer", tostring(writer))
  298.         if(date ~= nil) then
  299.             doItemSetAttribute(uid, "date", tonumber(date))
  300.         end
  301.     end
  302.  
  303.     return true
  304. end
  305.  
  306. function doSendAnimatedText(...)
  307.     print("doSendAnimatedText is now a deprecated function.")
  308.     return true
  309. end
  310.  
  311. function doPlayerSendToChannel(cid, target, type, text, channel, time)
  312.     return doCreatureChannelSay(cid, target, text, type, channel)
  313. end
  314.  
  315. function getItemWeaponType(uid)
  316.     local thing = getThing(uid)
  317.     if(thing.itemid < 100) then
  318.         return false
  319.     end
  320.  
  321.     return getItemInfo(thing.itemid).weaponType
  322. end
  323.  
  324. function getItemRWInfo(uid)
  325.     local thing = getThing(uid)
  326.     if(thing.itemid < 100) then
  327.         return false
  328.     end
  329.  
  330.     local item, flags = getItemInfo(thing.itemid), 0
  331.     if(item.readable) then
  332.         flags = 1
  333.     end
  334.  
  335.     if(item.writable) then
  336.         flags = flags + 2
  337.     end
  338.  
  339.     return flags
  340. end
  341.  
  342. function doPlayerWithdrawMoney(cid, amount)
  343.     local balance = getPlayerBalance(cid)
  344.     if(amount > balance or not doPlayerAddMoney(cid, amount)) then
  345.         return false
  346.     end
  347.  
  348.     doPlayerSetBalance(cid, balance - amount)
  349.     return true
  350. end
  351.  
  352. function doPlayerDepositMoney(cid, amount)
  353.     if(not doPlayerRemoveMoney(cid, amount)) then
  354.         return false
  355.     end
  356.  
  357.     doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
  358.     return true
  359. end
  360.  
  361. function doPlayerWithdrawAllMoney(cid)
  362.     return doPlayerWithdrawMoney(cid, getPlayerBalance(cid))
  363. end
  364.  
  365. function doPlayerDepositAllMoney(cid)
  366.     return doPlayerDepositMoney(cid, getPlayerMoney(cid))
  367. end
  368.  
  369. function doPlayerTransferAllMoneyTo(cid, target)
  370.     return doPlayerTransferMoneyTo(cid, target, getPlayerBalance(cid))
  371. end
  372.  
  373. string.trim = function (str)
  374.  return str:gsub("^%s*(.-)%s*$", "%1")
  375. end
  376.  
  377. string.explode = function (str, sep, limit)
  378. if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
  379.     return {}
  380. end
  381.  
  382.  local i, pos, tmp, t = 0, 1, "", {}
  383.  for s, e in function() return string.find(str, sep, pos) end do
  384.   tmp = str:sub(pos, s - 1):trim()
  385.   table.insert(t, tmp)
  386.   pos = e + 1
  387.  
  388.   i = i + 1
  389.   if(limit ~= nil and i == limit) then
  390.    break
  391.   end
  392.  end
  393.  
  394.  tmp = str:sub(pos):trim()
  395.  table.insert(t, tmp)
  396.  return t
  397. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement