Advertisement
apolo12

050-functions com script

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