Guest User

Untitled

a guest
May 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. function doAddVipDays(cid, days)
  2. db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
  3. end
  4.  
  5. function doRemoveVipDays(cid, days)
  6. db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` - " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
  7. end
  8.  
  9. function doPlayerGiveItem(cid, itemid, amount, subType)
  10. local item = 0
  11. if(isItemStackable(itemid)) then
  12. item = doCreateItemEx(itemid, amount)
  13. if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
  14. return false
  15. end
  16. else
  17. for i = 1, amount do
  18. item = doCreateItemEx(itemid, subType)
  19. if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
  20. return false
  21. end
  22. end
  23. end
  24.  
  25. return true
  26. end
  27.  
  28.  
  29. function doPlayerGiveItemContainer(cid, containerid, itemid, amount, subType)
  30. for i = 1, amount do
  31. local container = doCreateItemEx(containerid, 1)
  32. for x = 1, getContainerCapById(containerid) do
  33. doAddContainerItem(container, itemid, subType)
  34. end
  35.  
  36. if(doPlayerAddItemEx(cid, container, true) ~= RETURNVALUE_NOERROR) then
  37. return false
  38. end
  39. end
  40.  
  41. return true
  42. end
  43.  
  44. function doPlayerTakeItem(cid, itemid, amount)
  45. return getPlayerItemCount(cid, itemid) >= amount and doPlayerRemoveItem(cid, itemid, amount)
  46. end
  47.  
  48. function doPlayerBuyItem(cid, itemid, count, cost, charges)
  49. return doPlayerRemoveMoney(cid, cost) and doPlayerGiveItem(cid, itemid, count, charges)
  50. end
  51.  
  52. function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
  53. return doPlayerRemoveMoney(cid, cost) and doPlayerGiveItemContainer(cid, containerid, itemid, count, charges)
  54. end
  55.  
  56. function doPlayerSellItem(cid, itemid, count, cost)
  57. if(not doPlayerTakeItem(cid, itemid, count)) then
  58. return false
  59. end
  60.  
  61. if(not doPlayerAddMoney(cid, cost)) then
  62. error('[doPlayerSellItem] Could not add money to: ' .. getPlayerName(cid) .. ' (' .. cost .. 'gp).')
  63. end
  64.  
  65. return true
  66. end
  67.  
  68. function doPlayerWithdrawMoney(cid, amount)
  69. if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
  70. return false
  71. end
  72.  
  73. local balance = getPlayerBalance(cid)
  74. if(amount > balance or not doPlayerAddMoney(cid, amount)) then
  75. return false
  76. end
  77.  
  78. doPlayerSetBalance(cid, balance - amount)
  79. return true
  80. end
  81.  
  82. function doPlayerDepositMoney(cid, amount)
  83. if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
  84. return false
  85. end
  86.  
  87. if(not doPlayerRemoveMoney(cid, amount)) then
  88. return false
  89. end
  90.  
  91. doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
  92. return true
  93. end
  94.  
  95. function isPremium(cid)
  96. return (isPlayer(cid) and (getPlayerPremiumDays(cid) > 0 or getBooleanFromString(getConfigInfo('freePremium'))))
  97. end
  98.  
  99. function getMonthDayEnding(day)
  100. if(day == "01" or day == "21" or day == "31") then
  101. return "st"
  102. elseif(day == "02" or day == "22") then
  103. return "nd"
  104. elseif(day == "03" or day == "23") then
  105. return "rd"
  106. end
  107.  
  108. return "th"
  109. end
  110.  
  111. function getMonthString(m)
  112. return os.date("%B", os.time{year = 1970, month = m, day = 1})
  113. end
  114.  
  115. function getArticle(str)
  116. return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
  117. end
  118.  
  119. function isNumber(str)
  120. return tonumber(str) ~= nil
  121. end
  122.  
  123. function doPlayerAddAddons(cid, addon)
  124. for i = 0, table.maxn(maleOutfits) do
  125. doPlayerAddOutfit(cid, maleOutfits[i], addon)
  126. end
  127.  
  128. for i = 0, table.maxn(femaleOutfits) do
  129. doPlayerAddOutfit(cid, femaleOutfits[i], addon)
  130. end
  131. end
  132.  
  133. function doPlayerWithdrawAllMoney(cid)
  134. return doPlayerWithdrawMoney(cid, getPlayerBalance(cid))
  135. end
  136.  
  137. function doPlayerDepositAllMoney(cid)
  138. return doPlayerDepositMoney(cid, getPlayerMoney(cid))
  139. end
  140.  
  141. function doPlayerTransferAllMoneyTo(cid, target)
  142. return doPlayerTransferMoneyTo(cid, target, getPlayerBalance(cid))
  143. end
  144.  
  145. function playerExists(name)
  146. return getPlayerGUIDByName(name) ~= 0
  147. end
  148.  
  149. function getTibiaTime()
  150. local minutes = getWorldTime()
  151. local hours = 0
  152. while (minutes > 60) do
  153. hours = hours + 1
  154. minutes = minutes - 60
  155. end
  156.  
  157. return {hours = hours, minutes = minutes}
  158. end
  159.  
  160. function doWriteLogFile(file, text)
  161. local f = io.open(file, "a+")
  162. if(not f) then
  163. return false
  164. end
  165.  
  166. f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
  167. f:close()
  168. return true
  169. end
  170.  
  171. function getExperienceForLevel(lv)
  172. lv = lv - 1
  173. return ((50 * lv * lv * lv) - (150 * lv * lv) + (400 * lv)) / 3
  174. end
  175.  
  176. function doMutePlayer(cid, time)
  177. local condition = createConditionObject(CONDITION_MUTED)
  178. setConditionParam(condition, CONDITION_PARAM_TICKS, time * 1000)
  179. return doAddCondition(cid, condition)
  180. end
  181.  
  182. function getPlayerGroupName(cid)
  183. return getGroupInfo(getPlayerGroupId(cid)).name
  184. end
  185.  
  186. function getPlayerVocationName(cid)
  187. return getVocationInfo(getPlayerVocation(cid)).name
  188. end
  189.  
  190. function getPromotedVocation(vid)
  191. return getVocationInfo(vid).promotedVocation
  192. end
  193.  
  194. function doPlayerRemovePremiumDays(cid, days)
  195. return doPlayerAddPremiumDays(cid, -days)
  196. end
  197.  
  198. function getPlayerMasterPos(cid)
  199. return getTownTemplePosition(getPlayerTown(cid))
  200. end
  201.  
  202. function getHouseOwner(houseId)
  203. return getHouseInfo(houseId).owner
  204. end
  205.  
  206. function getHouseName(houseId)
  207. return getHouseInfo(houseId).name
  208. end
  209.  
  210. function getHouseEntry(houseId)
  211. return getHouseInfo(houseId).entry
  212. end
  213.  
  214. function getHouseRent(houseId)
  215. return getHouseInfo(houseId).rent
  216. end
  217.  
  218. function getHousePrice(houseId)
  219. return getHouseInfo(houseId).price
  220. end
  221.  
  222. function getHouseTown(houseId)
  223. return getHouseInfo(houseId).town
  224. end
  225.  
  226. function getHouseTilesCount(houseId)
  227. return getHouseInfo(houseId).tiles
  228. end
  229.  
  230. function getItemNameById(itemid)
  231. return getItemDescriptionsById(itemid).name
  232. end
  233.  
  234. function getItemPluralNameById(itemid)
  235. return getItemDescriptionsById(itemid).plural
  236. end
  237.  
  238. function getItemArticleById(itemid)
  239. return getItemDescriptionsById(itemid).article
  240. end
  241.  
  242. function getItemName(uid)
  243. return getItemDescriptions(uid).name
  244. end
  245.  
  246. function getItemPluralName(uid)
  247. return getItemDescriptions(uid).plural
  248. end
  249.  
  250. function getItemArticle(uid)
  251. return getItemDescriptions(uid).article
  252. end
  253.  
  254. function getItemText(uid)
  255. return getItemDescriptions(uid).text
  256. end
  257.  
  258. function getItemSpecialDescription(uid)
  259. return getItemDescriptions(uid).special
  260. end
  261.  
  262. function getItemWriter(uid)
  263. return getItemDescriptions(uid).writer
  264. end
  265.  
  266. function getItemDate(uid)
  267. return getItemDescriptions(uid).date
Add Comment
Please, Sign In to add comment