Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.96 KB | None | 0 0
  1. local config = {
  2. levelRequiredToAdd = 8,
  3. maxOffersPerPlayer = 5,
  4. SendOffersOnlyInPZ = false,
  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. local Sudden_Death = 2268
  9. local Ultimate_Healing = 2273
  10. local Great_Fireball = 2304
  11. local Explosion = 2313
  12. local Heavy_Magic_Missile = 2268
  13. local backpack, rune, charges
  14.  
  15. function onSay(cid, words, param, channel)
  16. if(param == '') then
  17. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires parameters.")
  18. return true
  19. end
  20.  
  21. local t = string.explode(param, ",")
  22. if(t[1] == "add") then
  23. if((not t[2]) or (not t[3]) or (not t[4])) then
  24. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires parameters.")
  25. return false
  26. end
  27.  
  28. if(not tonumber(t[3]) or (not tonumber(t[4]))) then
  29. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
  30. return false
  31. end
  32.  
  33. if(string.len(t[3]) > 7 or (string.len(t[4]) > 3)) then
  34. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
  35. return false
  36. end
  37.  
  38. local item = getItemIdByName(t[2])
  39. if(not item) then
  40. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item with such name does not exists.")
  41. return false
  42. end
  43.  
  44. if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
  45. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
  46. return false
  47. end
  48.  
  49. if(getPlayerVocation(cid) == 0) then
  50. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have the profession to do that action!")
  51. return false
  52. end
  53.  
  54. if(isInArray(config.blocked_items, item)) then
  55. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
  56. return false
  57. end
  58.  
  59. if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
  60. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you don't have this item(s).")
  61. return false
  62. end
  63.  
  64. local check = db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. getPlayerGUID(cid) .. ";")
  65. if(check:getID() == -1) then
  66. elseif(check:getRows(true) >= config.maxOffersPerPlayer) then
  67. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")")
  68. return false
  69. end
  70.  
  71. if(config.SendOffersOnlyInPZ) then
  72. if(not getTilePzInfo(getPlayerPosition(cid))) then
  73. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you add offer to market.")
  74. return false
  75. end
  76. end
  77.  
  78. if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
  79. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
  80. return false
  81. end
  82.  
  83. local itemcount, costgp = math.floor(t[4]), math.floor(t[3])
  84. doPlayerRemoveItem(cid, item, itemcount)
  85. 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() .. ")")
  86. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. t[2] .." for " .. costgp .. " gold coins to market.")
  87. return false
  88. end
  89.  
  90. if(t[1] == "buy") then
  91. if(not tonumber(t[2])) then
  92. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  93. return false
  94. end
  95.  
  96. local buy = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
  97. if(buy:getID() ~= -1) then
  98. if(getPlayerMoney(cid) < buy:getDataInt("cost")) then
  99. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enough gold coins.")
  100. buy:free()
  101. return tfalse
  102. end
  103.  
  104. if(getPlayerName(cid) == getPlayerNameByGUID(buy:getDataInt("player"))) then
  105. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can't buy your own items.")
  106. buy:free()
  107. return false
  108. end
  109.  
  110. if(getPlayerFreeCap(cid) < getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")))then
  111. 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.")
  112. buy:free()
  113. return false
  114. end
  115.  
  116. if(getPlayerVocation(cid) == 0) then
  117. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have the profession to do that action!")
  118. return false
  119. end
  120.  
  121. if(isItemStackable((buy:getDataInt("item_id")))) then
  122. doPlayerAddItem(cid, buy:getDataInt("item_id"), buy:getDataInt("count"))
  123. else
  124. for i = 1, buy:getDataInt("count") do
  125. doPlayerAddItem(cid, buy:getDataInt("item_id"), 1)
  126. end
  127. end
  128.  
  129. -- Reserved for the code of Runes inside backpacks
  130.  
  131.  
  132. doPlayerRemoveMoney(cid, buy:getDataInt("cost"))
  133. db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
  134. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. buy:getDataInt("count") .. " ".. buy:getDataString("item_name") .. " for " .. buy:getDataInt("cost") .. " gold coins!")
  135. db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
  136. buy:free()
  137. return false
  138. else
  139. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong Auction ID.")
  140. end
  141. end
  142.  
  143. if(t[1] == "remove") then
  144. if((not tonumber(t[2]))) then
  145. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong Auction ID.")
  146. return false
  147. end
  148.  
  149. if(config.SendOffersOnlyInPZ) then
  150. if(not getTilePzInfo(getPlayerPosition(cid))) then
  151. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offers from market.")
  152. return false
  153. end
  154. end
  155.  
  156. local delete = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
  157. if(delete:getID() ~= -1) then
  158. if(getPlayerGUID(cid) == delete:getDataInt("player")) then
  159. db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
  160. if(isItemStackable(delete:getDataInt("item_id"))) then
  161. doPlayerAddItem(cid, delete:getDataInt("item_id"), delete:getDataInt("count"))
  162. else
  163. for i = 1, delete:getDataInt("count") do
  164. doPlayerAddItem(cid, delete:getDataInt("item_id"), 1)
  165. end
  166. end
  167. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your offer has been deleted from market.")
  168. return false
  169. else
  170. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offer!")
  171. return false
  172. end
  173. delete:free()
  174. else
  175. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong Auction ID.")
  176. return false
  177. end
  178. end
  179.  
  180. if(t[1] == "withdraw") then
  181. local balance = db.getResult("SELECT `auction_balance` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";")
  182. if(balance:getDataInt("auction_balance") < 1) then
  183. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have money on your auction balance.")
  184. balance:free()
  185. return false
  186. end
  187.  
  188. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got " .. balance:getDataInt("auction_balance") .. " gold coins from market!")
  189. doPlayerAddMoney(cid, balance:getDataInt("auction_balance"))
  190. db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. getPlayerGUID(cid) .. ";")
  191. balance:free()
  192. return false
  193. end
  194. return true
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement