Advertisement
Kaiquegabriel

Untitled

Aug 2nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.99 KB | None | 0 0
  1. local config = {
  2. levelRequiredToAdd = 20,
  3. maxOffersPerPlayer = 5,
  4. SendOffersOnlyInPZ = true,
  5. blocked_items = {2165, 2152, 2148, 2160, 2166, 2167, 2168, 2169, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2343, 2433, 2640, 6132, 6300, 6301, 9932, 9933}
  6. }
  7.  
  8. function onSay(cid, words, param, channel)
  9. if(param == '') then
  10. if(not getTilePzInfo(getCreaturePosition(cid))) then
  11. return doPlayerSendCancel(cid, "Vocรƒยช precisa esta em area protegida para utilizar este comando.")
  12. end
  13. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
  14. return false
  15. end
  16. local t = string.explode(param, ",")
  17. if(t[1] == "add") then
  18. if((not t[2]) or (not t[3]) or (not t[4])) then
  19. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
  20. return true
  21. end
  22. if(not tonumber(t[3]) or (not tonumber(t[4]))) then
  23. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
  24. return true
  25. end
  26. if(string.len(t[3]) > 7 or (string.len(t[4]) > 3)) then
  27. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
  28. return true
  29. end
  30. local item = getItemIdByName(t[2])
  31. if(not item) then
  32. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
  33. return true
  34. end
  35. if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
  36. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
  37. return true
  38. end
  39. if(isInArray(config.blocked_items, item)) then
  40. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
  41. return true
  42. end
  43. if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
  44. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you don't have this item(s).")
  45. return true
  46. end
  47. local check = db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. getPlayerGUID(cid) .. ";")
  48. if(check:getID() == -1) then
  49. elseif(check:getRows(true) >= config.maxOffersPerPlayer) then
  50. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")")
  51. return true
  52. end
  53. if(config.SendOffersOnlyInPZ) then
  54. if(not getTilePzInfo(getPlayerPosition(cid))) then
  55. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you add offert to offline shopping.")
  56. return false
  57. end
  58. end
  59. if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
  60. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
  61. return true
  62. end
  63. local itemcount, costgp = math.floor(t[4]), math.floor(t[3])
  64. doPlayerRemoveItem(cid, item, itemcount)
  65. db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`) VALUES (" .. getPlayerGUID(cid) .. ", \"" .. t[2] .. "\", " .. getItemIdByName(t[2]) .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ")")
  66. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. t[2] .." for " .. costgp .. " gps to offerts database.")
  67. end
  68. if(t[1] == "buy") then
  69. if(not tonumber(t[2])) then
  70. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  71. return true
  72. end
  73. local buy = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
  74. if(buy:getID() ~= -1) then
  75. if(getPlayerMoney(cid) < buy:getDataInt("cost")) then
  76. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh GP.")
  77. buy:free()
  78. return true
  79. end
  80. if(getPlayerName(cid) == getPlayerNameByGUID(buy:getDataInt("player"))) then
  81. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can't buy your own items.")
  82. buy:free()
  83. return true
  84. end
  85. if(getPlayerFreeCap(cid) < getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")))then
  86. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You try to buy a " .. buy:getDataString("item_name") .. ". It weight " .. getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")) .. " cap oz. and you have only " .. getPlayerFreeCap(cid) .. " oz. free capacity. Put some items to depot and try again.")
  87. buy:free()
  88. return true
  89. end
  90. if(isItemStackable((buy:getDataString("item_id")))) then
  91. doPlayerAddItem(cid, buy:getDataString("item_id"), buy:getDataInt("count"))
  92. else
  93. for i = 1, buy:getDataInt("count") do
  94. doPlayerAddItem(cid, buy:getDataString("item_id"), 1)
  95. end
  96. end
  97. doPlayerRemoveMoney(cid, buy:getDataInt("cost"))
  98. db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
  99. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. buy:getDataInt("count") .. " ".. buy:getDataString("item_name") .. " for " .. buy:getDataInt("cost") .. " gps!")
  100. db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
  101. buy:free()
  102. else
  103. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  104. end
  105. end
  106. if(t[1] == "remove") then
  107. if((not tonumber(t[2]))) then
  108. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  109. return true
  110. end
  111. if(config.SendOffersOnlyInPZ) then
  112. if(not getTilePzInfo(getPlayerPosition(cid))) then
  113. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from offline shopping.")
  114. return true
  115. end
  116. end
  117. local delete = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
  118. if(delete:getID() ~= -1) then
  119. if(getPlayerGUID(cid) == delete:getDataInt("player")) then
  120. db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
  121. if(isItemStackable(delete:getDataString("item_id"))) then
  122. doPlayerAddItem(cid, delete:getDataString("item_id"), delete:getDataInt("count"))
  123. else
  124. for i = 1, delete:getDataInt("count") do
  125. doPlayerAddItem(cid, delete:getDataString("item_id"), 1)
  126. end
  127. end
  128. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your offert has been deleted from olderian offline shopping.")
  129. else
  130. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offert!")
  131. end
  132. delete:free()
  133. else
  134. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  135. end
  136. end
  137. if(t[1] == "withdraw") then
  138. local balance = db.getResult("SELECT `auction_balance` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";")
  139. if(balance:getDataInt("auction_balance") < 1) then
  140. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have money on your auction balance.")
  141. balance:free()
  142. return true
  143. end
  144. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got " .. balance:getDataInt("auction_balance") .. " gps from offline shopping system!")
  145. doPlayerAddMoney(cid, balance:getDataInt("auction_balance"))
  146. db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. getPlayerGUID(cid) .. ";")
  147. balance:free()
  148. end
  149. return true
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement