Mystical-Chams

2

Apr 10th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. function getAccountNumberByPlayerName(name)
  2.     local player = Player(name)
  3.     if player ~= nil then
  4.         return player:getAccountId()
  5.     end
  6.  
  7.     local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
  8.     if resultId ~= false then
  9.         local accountId = result.getNumber(resultId, "account_id")
  10.         result.free(resultId)
  11.         return accountId
  12.     end
  13.     return 0
  14. end
  15.  
  16. function getPlayerVipPoints(cid)
  17.     local Info = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. "")
  18.         if Info:getID() ~= LUA_ERROR then
  19.         local Points= Info:getDataInt("premium_points")
  20.         Info:free()
  21.         return Points
  22.     end
  23.      return LUA_ERROR
  24. end
  25.  
  26. function doPlayerAddVipPoints(cid, points)
  27.     local dif = getPlayerVipPoints(cid) + points
  28.     if dif >=  then
  29.         db.Query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. points .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
  30.         return TRUE
  31.     end
  32.     return FALSE
  33. end
  34.  
  35. function doPlayerRemoveVipPoints(cid, points)
  36.     local dif = getPlayerVipPoints(cid) - points
  37.     if dif >=  then
  38.         db.Query("UPDATE `accounts` SET `premium_points` = `premium_points` - " .. points .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
  39.         return TRUE
  40.     end
  41.     return FALSE
  42. end
  43.  
  44. function getMoneyCount(string)
  45.     local b, e = string:find("%d+")
  46.     local money = b and e and tonumber(string:sub(b, e)) or -1
  47.     if isValidMoney(money) then
  48.         return money
  49.     end
  50.     return -1
  51. end
  52.  
  53. function getMoneyWeight(money)
  54.     local gold = money
  55.     local crystal = math.floor(gold / 10000)
  56.     gold = gold - crystal * 10000
  57.     local platinum = math.floor(gold / 100)
  58.     gold = gold - platinum * 100
  59.     return (ItemType(2160):getWeight() * crystal) + (ItemType(2152):getWeight() * platinum) + (ItemType(2148):getWeight() * gold)
  60. end
  61.  
  62. function getRealDate()
  63.     local month = tonumber(os.date("%m", os.time()))
  64.     local day = tonumber(os.date("%d", os.time()))
  65.  
  66.     if month < 10 then
  67.         month = '0' .. month
  68.     end
  69.     if day < 10 then
  70.         day = '0' .. day
  71.     end
  72.     return day .. '/' .. month
  73. end
  74.  
  75. function getRealTime()
  76.     local hours = tonumber(os.date("%H", os.time()))
  77.     local minutes = tonumber(os.date("%M", os.time()))
  78.  
  79.     if hours < 10 then
  80.         hours = '0' .. hours
  81.     end
  82.     if minutes < 10 then
  83.         minutes = '0' .. minutes
  84.     end
  85.     return hours .. ':' .. minutes
  86. end
  87.  
  88. function isValidMoney(money)
  89.     return isNumber(money) and money > 0 and money < 4294967296
  90. end
  91.  
  92. function iterateArea(func, from, to)
  93.     for z = from.z, to.z do
  94.         for y = from.y, to.y do
  95.             for x = from.x, to.x do
  96.                 func(Position(x, y, z))
  97.             end
  98.         end
  99.     end
  100. end
  101.  
  102. function playerExists(name)
  103.     local resultId = db.storeQuery('SELECT `name` FROM `players` WHERE `name` = ' .. db.escapeString(name))
  104.     if resultId then
  105.         result.free(resultId)
  106.         return true
  107.     end
  108.     return false
  109. end
Add Comment
Please, Sign In to add comment