Advertisement
Prawdziwynrtn

Untitled

Apr 19th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.53 KB | None | 0 0
  1. --[[
  2. Offline player to player item trader (Auction System) by vDk
  3. Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
  4. ]]--
  5. local config = {
  6. levelRequiredToAdd = 200,
  7. maxOffersPerPlayer = 20,
  8. SendOffersOnlyInPZ = true,
  9. blocked_items = {2152, 2148, 2160, 2162}
  10. }
  11.  
  12. local upgrading = {
  13. getLevel = function (item)
  14. local name = string.explode(getItemName(item), '+')
  15. return (#name == 1) and 0 or math.abs(name[2])
  16. end,
  17. }
  18. function onSay(cid, words, param, channel)
  19. if(param == '') then
  20. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
  21. return true
  22. end
  23.  
  24. local t = string.explode(param, ",")
  25. if(t[1] == "add") then
  26. if((not t[2]) or (not t[3]) or (not t[4])) then
  27. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
  28. return true
  29. end
  30.  
  31. if(not tonumber(t[3]) or (not tonumber(t[4]))) then
  32. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
  33. return true
  34. end
  35.  
  36. if(string.len(t[3]) > 7 or (string.len(t[4]) > 3)) then
  37. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
  38. return true
  39. end
  40.  
  41. local item = getItemIdByName(t[2], false)
  42. local info = getItemInfo(item)
  43. if(not item) then
  44. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
  45. return true
  46. end
  47.  
  48. if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
  49. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
  50. return true
  51. end
  52.  
  53. if(isInArray(config.blocked_items, item)) then
  54. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
  55. return true
  56. end
  57.  
  58. if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
  59. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you don't have this item(s).")
  60. return true
  61. end
  62.  
  63. local check = db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. getPlayerGUID(cid) .. ";")
  64. if(check:getID() == -1) then
  65. elseif(check:getRows(true) >= config.maxOffersPerPlayer) then
  66. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")")
  67. return true
  68. end
  69.  
  70. if(config.SendOffersOnlyInPZ) then
  71. if(not getTilePzInfo(getPlayerPosition(cid))) then
  72. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you add offert to database.")
  73. return true
  74. end
  75. end
  76.  
  77. if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
  78. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
  79. return true
  80. end
  81.  
  82. local itemcount, costgp = math.floor(t[4]), math.floor(t[3])
  83. local upgrade = upgrading.getLevel(info.uid)
  84. doPlayerRemoveItem(cid, item, itemcount)
  85. db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `upgrade`, `date`) VALUES (" .. getPlayerGUID(cid) .. ", \"" .. t[2] .. "\", " .. getItemIdByName(t[2]) .. ", " .. itemcount .. ", " .. costgp ..", " .. upgrade ..", " .. os.time() .. ")")
  86. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. t[2] .." " .. upgrade .." for " .. costgp .. " gps to offerts database.")
  87. end
  88.  
  89. if(t[1] == "buy") then
  90. if(not tonumber(t[2])) then
  91. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  92. return true
  93. end
  94.  
  95. local buy = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
  96. if(buy:getID() ~= -1) then
  97. if(getPlayerMoney(cid) < buy:getDataInt("cost")) then
  98. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh GP.")
  99. buy:free()
  100. return true
  101. end
  102.  
  103. if(getPlayerName(cid) == getPlayerNameByGUID(buy:getDataInt("player"))) then
  104. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can't buy your own items.")
  105. buy:free()
  106. return true
  107. end
  108.  
  109. if(getPlayerFreeCap(cid) < getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")))then
  110. 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.")
  111. buy:free()
  112. return true
  113. end
  114.  
  115. if(isItemStackable((buy:getDataString("item_id")))) then
  116. doPlayerAddItem(cid, buy:getDataString("item_id"), buy:getDataInt("count"))
  117. else
  118. for i = 1, buy:getDataInt("count") do
  119. doPlayerAddItem(cid, buy:getDataString("item_id"), 1)
  120. end
  121. end
  122.  
  123. doPlayerRemoveMoney(cid, buy:getDataInt("cost"))
  124. db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
  125. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. buy:getDataInt("count") .. " ".. buy:getDataString("item_name") .. " for " .. buy:getDataInt("cost") .. " gps!")
  126. db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
  127. buy:free()
  128. else
  129. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  130. end
  131. end
  132.  
  133. if(t[1] == "remove") then
  134. if((not tonumber(t[2]))) then
  135. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  136. return true
  137. end
  138.  
  139. if(config.SendOffersOnlyInPZ) then
  140. if(not getTilePzInfo(getPlayerPosition(cid))) then
  141. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from database.")
  142. return true
  143. end
  144. end
  145.  
  146. local delete = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
  147. if(delete:getID() ~= -1) then
  148. if(getPlayerGUID(cid) == delete:getDataInt("player")) then
  149. db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
  150. if(isItemStackable(delete:getDataString("item_id"))) then
  151. doPlayerAddItem(cid, delete:getDataString("item_id"), delete:getDataInt("count"))
  152. else
  153. for i = 1, delete:getDataInt("count") do
  154. doPlayerAddItem(cid, delete:getDataString("item_id"), 1)
  155. end
  156. end
  157.  
  158. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your offert has been deleted from offerts database.")
  159. else
  160. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offert!")
  161. end
  162. delete:free()
  163. else
  164. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  165. end
  166. end
  167.  
  168. if(t[1] == "withdraw") then
  169. local balance = db.getResult("SELECT `auction_balance` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";")
  170. if(balance:getDataInt("auction_balance") < 1) then
  171. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have money on your auction balance.")
  172. balance:free()
  173. return true
  174. end
  175.  
  176. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got " .. balance:getDataInt("auction_balance") .. " gps from auction system!")
  177. doPlayerAddMoney(cid, balance:getDataInt("auction_balance"))
  178. db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. getPlayerGUID(cid) .. ";")
  179. balance:free()
  180. end
  181. return true
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement