Advertisement
Guest User

Trade Off tfs 1.2

a guest
Aug 23rd, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.63 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. function onSay(player, words, param)
  8.     if(param == '') then
  9.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
  10.         return true
  11.     end
  12.     local split = param:split(",")
  13.     if(split[1] == "add") then
  14.         if split[2] == null then
  15.             return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  16.         end
  17.         if((not split[2]) or (not split[3]) or (not split[4])) then
  18.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
  19.             return true
  20.         end
  21.         if(not tonumber(split[3]) or (not tonumber(split[4]))) then
  22.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
  23.             return true
  24.         end
  25.         if(string.len(split[3]) > 7 or (string.len(split[4]) > 3)) then
  26.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
  27.             return true
  28.         end
  29.         local itemType = ItemType(split[2])
  30.         local item_s =  ItemType(split[2]):getId()
  31.         if(not item_s) then
  32.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.".. item_s .." ")
  33.             return true
  34.         end
  35.         if(player:getLevel() < config.levelRequiredToAdd) then
  36.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
  37.             return true
  38.         end
  39.         if(isInArray(config.blocked_items, item_s)) then
  40.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
  41.             return true
  42.         end
  43.         if(player:getItemCount(item_s) < tonumber(split[4])) then
  44.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you don't have this item.")
  45.             return true
  46.         end
  47.  
  48.         local resultId = db.storeQuery("SELECT `id` FROM `auction_system` WHERE `player` = " .. player:getGuid())
  49.         local qtd = result.getNumber(resultId, "id")
  50.         local amount = 0
  51.         local tmpResultId = resultId
  52.         while tmpResultId ~= false do
  53.             tmpResultId = result.next(resultId)
  54.             amount = amount + 1
  55.         end
  56.         if resultId ~= false then
  57.             local limit = amount >= config.maxOffersPerPlayer
  58.             if limit then
  59.                 player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")")
  60.                 return true
  61.             end
  62.             if(config.SendOffersOnlyInPZ) then    
  63.             if(not getTilePzInfo(player:getPosition())) then
  64.                 player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you add offert to database.")
  65.                 return true
  66.             end
  67.         end
  68.     end
  69.     if(tonumber(split[4]) < 1 or (tonumber(split[3]) < 1)) then
  70.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
  71.         return true
  72.     end
  73.     local itemcount, costgp = math.floor(split[4]), math.floor(split[3])
  74.     player:removeItem(item_s, itemcount)
  75.     db.query("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`) VALUES (" .. player:getGuid() .. ", \"" .. split[2] .. "\", " .. item_s .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ")")
  76.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. split[2] .." for " .. costgp .. " gps to offerts database.")
  77. end
  78. if(split[1] == "comprar") then
  79.     if split[2] == null then
  80.         return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  81.     end
  82.     local resultado = db.storeQuery("SELECT * FROM `auction_system` WHERE `id` = ".. tonumber(split[2]))
  83.     local player_id = player:getGuid()
  84.     local player_vendas = result.getNumber(resultado, "player")
  85.     local item_ids = result.getNumber(resultado, "item_id")
  86.     local costs = result.getNumber(resultado, "cost")
  87.     local item_ns = result.getNumber(resultado, "item_name")
  88.     local item_names = getItemName(item_ids)
  89.     local counts = result.getNumber(resultado, "count")
  90.     if(not tonumber(split[2])) then
  91.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  92.         return true
  93.     end
  94.  
  95.     if(resultado ~= false) then
  96.         if(player:getMoney() < costs) then
  97.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh GP.")
  98.             return true
  99.         end
  100.         if(player_id == player_vendas) then
  101.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can't buy your own items.")
  102.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, " "..player_id.."\n"..player_vendas.." ")
  103.         return true
  104.     end
  105.     if(player:getFreeCapacity() < getItemWeight(item_ids, counts))then
  106.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You try to buy a " .. item_names .. ". It weight " .. getItemWeightByUID(item_ids, counts) .. " cap oz. and you have only " .. player:getFreeCapacity() .. " oz. free capacity. Put some items to depot and try again.")
  107.         return true
  108.     end
  109.     if(isItemStackable((item_ids))) then
  110.         player:addItem(item_ids, counts)
  111.     else
  112.         for i = 1, count do
  113.             player:addItem(item_ids, 1)
  114.         end
  115.     end
  116.     player:removeMoney(costs)
  117.     db.query("DELETE FROM `auction_system` WHERE `id` = " .. split[2] .. ";")
  118.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought " .. counts .. " ".. item_names .. " for " .. costs .. " gps!")
  119.     db.query("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. costs .. " WHERE `id` = " .. player_vendas .. ";")
  120. else
  121.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  122. end
  123. end
  124. if(split[1] == "remover") then
  125.     if split[2] == null then
  126.         return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  127.     end
  128.     local resultado = db.storeQuery("SELECT * FROM `auction_system` WHERE `id` = ".. tonumber(split[2]))
  129.     local player_id = player:getGuid()
  130.     local player_vendas = result.getNumber(resultado, "player")
  131.     local item_ids = result.getNumber(resultado, "item_id")
  132.     local costs = result.getNumber(resultado, "cost")
  133.     local item_ns = result.getNumber(resultado, "item_name")
  134.     local item_names = getItemName(item_ids)
  135.     local counts = result.getNumber(resultado, "count")
  136.     if((not tonumber(split[2]))) then
  137.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  138.         return true
  139.     end
  140.     if(config.SendOffersOnlyInPZ) then    
  141.     if(not getTilePzInfo(player:getPosition())) then
  142.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from database.")
  143.         return true
  144.     end
  145. end  
  146. if(resultado ~= false) then
  147.     if(player:getGuid() == player_vendas) then
  148.     db.query("DELETE FROM `auction_system` WHERE `id` = " .. split[2] .. ";")
  149.     if(isItemStackable(item_ids)) then
  150.         player:addItem(item_ids, counts)
  151.     else
  152.         for i = 1, counts do
  153.             player:addItem(item_ids, 1)
  154.         end
  155.     end
  156.     player:sendTextMessage(MESSAGE_INFO_DESCR, "Your offert has been deleted from offerts database.")
  157. else
  158.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offert!")
  159. end
  160. result.free(resultado)
  161. else
  162.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
  163. end
  164. end
  165. if(split[1] == "sacar") then
  166.     local balance = db.storeQuery("SELECT * FROM `players` WHERE `id` = " .. player:getGuid() .. ";")
  167.     local auction_balance = result.getNumber(balance, "auction_balance")
  168.     if(auction_balance < 1) then
  169.         player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have money on your auction balance.")
  170.         result.free(balance)
  171.         return true
  172.     end
  173.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You got " .. auction_balance .. " gps from auction system!")
  174.     player:addMoney(auction_balance)
  175.     db.query("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. player:getGuid() .. ";")
  176.     result.free(balance)
  177. end
  178. return true
  179. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement