Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------- File Info Start ---------------------------------------
- ----------- Project name: In Game Shop & Trade -----------
- ----------- Author: masodikbela@Hungary -----------
- ----------- Version: v2.0 -----------
- ----------- Original relase date: 2014. 12. 02. 21:23:42 -----------
- ----------- Previous released version: v1.0 with some fixes -----------
- ----------- Developed for: Everyone -----------
- ----------- Aviable languages: Hungarian, English -----------
- ----------- Last edited: 2015. 08. 17. 23:54 -----------
- --------------------------------------- File Info End -----------------------------------------
- quest mb_igshop begin
- state start begin
- --------------------------
- --Client commander Start--
- --------------------------
- when button begin
- local cmd = client_command(getinput("IGSHOP QUESTCMD"))
- if cmd[1] == "GROUP" then
- if table.getn(cmd) != 3 then syschat("mb_igshop Error->invalid_packet_size(GROUP)") return end
- mb_igshop.clearAllArraySell(pc.get_player_id())
- if cmd[2] == "" then return end
- for i = 1, table.getn(availableGroups) do
- if availableGroups[i] == cmd[2] then break end
- if i == table.getn(availableGroups) then syschat("mb_igshop Error->WrongGroup|"..cmd[2]) return end
- end
- local get = {}
- if cmd[2] == "my_buys" then
- get = mb_igshop.get_myboughtitems()
- elseif cmd[2] == "my_sales" then
- get = mb_igshop.get_myitems()
- elseif cmd[2] == "get_trade_items" then
- local fOpen = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "r")
- if fOpen != nil then
- for i in fOpen:lines() do
- table.insert(get, i)
- end
- end
- else
- get = mb_igshop.get_items(cmd[2])
- end
- mb_igshop.refresh_pages(get)
- local lines = table.getn(get)
- if lines > 0 then
- mb_igshop.add_items(tonumber(pc.getqf("pages")),tonumber(cmd[3]),get, tonumber(pc.getqf("itemsOnLastPage")), cmd[2])
- cmdchat("IGSHOP MANAGEPAGES/"..tonumber(pc.getqf("pages")).."/1")
- end
- if cmd[2] != "my_buys" and cmd[2] != "get_trade_items" then
- cmdchat("IGSHOP SETGOLD/"..mb_igshop.get_gold(pc.get_account_id()))
- if cmd[2] != "my_sales" then
- cmdchat("IGSHOP SETCASH/"..get_coins())
- end
- end
- elseif cmd[1] == "SWITCHPAGE" then
- if table.getn(cmd) != 3 then syschat("mb_igshop Error->invalid_packet_size(SWITCHPAGE)") return end
- mb_igshop.clearAllArraySell(pc.get_player_id())
- if cmd[2] == "" then return end
- for i = 1, table.getn(availableGroups) do
- if availableGroups[i] == cmd[2] then break end
- if i == table.getn(availableGroups) then syschat("mb_igshop Error->WrongGroup|"..cmd[2]) return end
- end
- local get = {}
- if cmd[2] == "my_buys" then
- get = mb_igshop.get_myboughtitems()
- elseif cmd[2] == "my_sales" then
- get = mb_igshop.get_myitems()
- elseif cmd[2] == "get_trade_items" then
- local fOpen = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "r")
- if fOpen != nil then
- for i in fOpen:lines() do
- table.insert(get, i)
- end
- end
- else
- get = mb_igshop.get_items(cmd[2])
- end
- mb_igshop.refresh_pages(get)
- local lines = table.getn(get)
- if lines > 0 then
- local page = tonumber(cmd[3])
- if page > tonumber(pc.getqf("pages")) then page = tonumber(pc.getqf("pages")) end
- mb_igshop.add_items(tonumber(pc.getqf("pages")), page, get, tonumber(pc.getqf("itemsOnLastPage")), cmd[2])
- cmdchat("IGSHOP MANAGEPAGES/"..tonumber(pc.getqf("pages")).."/"..page)
- end
- if cmd[2] != "my_buys" and cmd[2] != "get_trade_items" then
- cmdchat("IGSHOP SETGOLD/"..mb_igshop.get_gold(pc.get_account_id()))
- if cmd[2] != "my_sales" then
- cmdchat("IGSHOP SETCASH/"..get_coins())
- end
- end
- elseif cmd[1] == "BUYITEM" then
- if table.getn(cmd) != 8 then syschat("mb_igshop Error->invalid_packet_size(BUYITEM)") return end
- if not mb_igshop.gm_buy_check() then syschat(loadLang(56)) return end
- local itemID = math.floor(tonumber(cmd[2]))
- local buytype = cmd[3]
- local page = math.floor(tonumber(cmd[4]))
- local slot = math.floor(tonumber(cmd[5]))
- local count = math.floor(tonumber(cmd[6]))
- local money = math.floor(tonumber(cmd[7]))
- for i = 1, table.getn(availableGroups) do
- if availableGroups[i] == cmd[8] then break end
- if i == table.getn(availableGroups) then syschat("mb_igshop Error->WrongGroup|"..cmd[8]) return end
- end
- local group = cmd[8]
- if count < 0 then syschat("mb_igshop Error->negative_count_of_item") return end
- if buytype == "CASH" then
- local coins = get_coins()
- if coins < money then
- syschat("mb_igshop Error->wrong_money_data")
- cmdchat("IGSHOP SETCASH/"..coins)
- else
- mb_igshop.BuyItem(itemID, buytype, page, slot, count, coins, group)
- end
- elseif buytype == "GOLD" then
- local gold = mb_igshop.get_gold(pc.get_account_id())
- if gold < money then
- syschat("mb_igshop Error->wrong_money_data")
- cmdchat("IGSHOP SETGOLD/"..gold)
- else
- mb_igshop.BuyItem(itemID, buytype, page, slot, count, gold, group)
- end
- else
- syschat("mb_igshop Error-> "..tostring(buytype))
- syschat("unknownError")
- end
- elseif cmd[1] == "CLAIMITEM" then
- if table.getn(cmd) != 4 then syschat("mb_igshop Error->invalid_packet_size(CLAIMITEM)") return end
- local itemID = math.floor(tonumber(cmd[2]))
- local page = math.floor(tonumber(cmd[3]))
- local slot = math.floor(tonumber(cmd[4]))
- mb_igshop.ClaimItem(itemID, page, slot)
- elseif cmd[1] == "CLAIMMYITEM" then
- if table.getn(cmd) != 4 then syschat("mb_igshop Error->invalid_packet_size(CLAIMMYITEM)") return end
- local itemID = math.floor(tonumber(cmd[2]))
- local page = math.floor(tonumber(cmd[3]))
- local slot = math.floor(tonumber(cmd[4]))
- mb_igshop.ClaimMyItem(itemID, page, slot)
- elseif cmd[1] == "SELLITEM" then
- if table.getn(cmd) != 3 then syschat("mb_igshop Error->invalid_packet_size(SELLITEM)") return end
- if not mb_igshop.gm_sell_check() then syschat(loadLang(55)) return end
- if not mb_igshop.expandable_limited_storage("get") then syschat(loadLang(2)) return end
- if not mb_igshop.check_itemc() then return syschat(loadLang(6)) end
- if not mb_igshop.check_accIC() then return syschat(loadLang(6)) end
- if not mb_igshop.char_filters() then return syschat(loadLang(4)) end
- local cell = tonumber(cmd[3])
- local slot = tonumber(cmd[2])
- if not item.select_cell(cell) then syschat(loadLang(54)) return end
- local id, vnum, count, itype, isubtype = item.get_id(), item.get_vnum(), item.get_count(), item.get_type(), item.get_sub_type()
- if not mb_igshop.check_always_available(vnum) then
- if not mb_igshop.check_antiflag(vnum) then return syschat(loadLang(5)) end
- if not mb_igshop.check_type(itype, isubtype) then return syschat(loadLang(3)) end
- if not mb_igshop.check_sellableItems(vnum) then return syschat(loadLang(5)) end
- end
- if itype == 0 then return end
- if count < 0 then syschat("mb_igshop Error->negative_count_of_item") return end
- if mb_igshop.igshop_gold_manager("put_in", vnum, count, cell) then return end
- pc.setqf("sellitemid",id)
- pc.setqf("itemcell",cell)
- pc.setqf("itemcount", pc.count_item(vnum))
- local attr = {{item.get_attr_type(0), item.get_attr_value(0)}, {item.get_attr_type(1), item.get_attr_value(1)}, {item.get_attr_type(2), item.get_attr_value(2)}, {item.get_attr_type(3), item.get_attr_value(3)},{item.get_attr_type(4), item.get_attr_value(4)},{item.get_attr_type(5), item.get_attr_value(5)}, {item.get_attr_type(6), item.get_attr_value(6)}, {item.get_attr_type(7), item.get_attr_value(7)}}
- local socket = {item.get_socket(0), item.get_socket(1), item.get_socket(2),item.get_socket(3),item.get_socket(4),item.get_socket(5)}
- cmdchat('IGSHOP_ADDTOTEMPSLOT '..slot..' '..vnum..' '..count..' '..socket[1]..' '..socket[2]..' '..socket[3]..' '..socket[4]..' '..socket[5]..' '..socket[6]..' '..attr[1][1]..' '..attr[1][2]..' '..attr[2][1]..' '..attr[2][2]..' '..attr[3][1]..' '..attr[3][2]..' '..attr[4][1]..' '..attr[4][2]..' '..attr[5][1]..' '..attr[5][2]..' '..attr[6][1]..' '..attr[6][2]..' '..attr[7][1]..' '..attr[7][2]..' '..attr[8][1]..' '..attr[8][2])
- elseif cmd[1] == "FINISHSALE" then
- if table.getn(cmd) != 3 then syschat("mb_igshop Error->invalid_packet_size(FINISHSALE)") return end
- if not mb_igshop.gm_sell_check() then syschat(loadLang(55)) return end
- if cmd[2] == "" then cmd[2] = 0 end
- if cmd[3] == "" then cmd[3] = 0 end
- local priceY = math.floor(tonumber(cmd[2]))
- local priceS = math.floor(tonumber(cmd[3]))
- if priceY <0 or priceS <0 then syschat(loadLang(7)) return end
- if not mb_igshop.char_filters() then return syschat(loadLang(4)) end
- if not mb_igshop.check_itemc() then return syschat(loadLang(6)) end
- if not mb_igshop.check_accIC() then return syschat(loadLang(6)) end
- mb_igshop.SellItem(priceY, priceS)
- elseif cmd[1] == "SEARCH" then
- if table.getn(cmd) < 4 then syschat("mb_igshop Error->invalid_packet_size(SEARCH)") return end
- if table.getn(cmd) > 4 then
- for i = 4, table.getn(cmd)-1 do
- cmd[3] = ""..cmd[3].."#"..cmd[i]
- end
- cmd[4] = cmd[table.getn(cmd)]
- end
- local fOwner = cmd[2]
- local fItem = string.lower(cmd[3])
- if fOwner == "" and fItem == "" then syschat(loadLang(8)) return end
- local file = io.open(igshop_path.."data/"..pc.get_name().."/search.txt", "w+")
- file:write(fOwner.."#"..fItem)
- file:flush()
- file:close()
- mb_igshop.searchItem(fOwner, fItem, tonumber(cmd[4]), 1)
- elseif cmd[1] == "GETMONEY" then
- if table.getn(cmd) != 2 then syschat("mb_igshop Error->invalid_packet_size(GETMONEY)") return end
- local money = cmd[2]
- if pc.get_empty_inventory_count() < 1 then syschat(loadLang(9)) return end
- local tbl = split_(money, "|")
- local once = 0
- for i = 1, table.getn(tbl) do
- local mymoney = math.pow(1000, table.getn(tbl)-i)*tbl[i]
- local ret = mb_igshop.igshop_gold_manager("get_out",mymoney)
- if ret >= 0 then
- mb_igshop.set_gold(pc.get_account_id(),0 - mymoney + ret)
- end
- if ret != 0 and once == 0 and ret > 0 then syschat(loadLang(10)) once = 1 end
- end
- local gold = mb_igshop.get_gold(pc.get_account_id())
- cmdchat("IGSHOP SETGOLD/"..gold)
- cmdchat("IGSHOP EMPTYINPUTGOLD")
- elseif cmd[1] == "ChangeLang" then
- if table.getn(cmd) != 2 then syschat("mb_igshop Error->invalid_packet_size(ChangeLang)") return end
- local langNum = math.floor(tonumber(cmd[2])) + 1
- if langNum <= 0 or langNum > table.getn(igshopLangTable) then syschat("mb_igshop Error->no_lang_found") return end
- pc.setqf("langVar", langNum)
- mb_igshop.OpenIgShop()
- elseif igshopEnableTrade then
- if cmd[1] == "trade.FindItemAndPut" then
- if table.getn(cmd) < 3 then syschat("mb_igshop Error->invalid_packet_size(trade.FindItemAndPut)") return end
- if table.getn(cmd) > 3 then
- for i = 3, table.getn(cmd)-1 do
- cmd[2] = ""..cmd[2].."#"..cmd[i]
- end
- cmd[3] = cmd[table.getn(cmd)]
- end
- local findName = trim(tostring(cmd[2]))
- if string.len(findName) < 2 then
- syschat(loadLang(11))
- return
- end
- mb_igshop.FindTradeItemAndPut(string.lower(findName), cmd[3])
- elseif cmd[1] == "trade.ApplyWantsItem" then
- if table.getn(cmd) != 4+2*7 then syschat("mb_igshop Error->invalid_packet_size(trade.ApplyWantsItem)") return end
- local slotNum = tonumber(cmd[2])
- if slotNum < 1 or slotNum > igshop_maximumSlotSize then syschat("mb_igshop Error->wrong_slot_number") return end
- local itemVnum = tonumber(cmd[3])
- local itemCount = tonumber(cmd[4])
- if itemCount <= 0 then itemCount = 1 end
- if itemCount != math.floor(itemCount) then syschat(loadLang(12)) return end
- local tbl = {{tonumber(cmd[5]),tonumber(cmd[6])},{tonumber(cmd[7]),tonumber(cmd[8])},{tonumber(cmd[9]),tonumber(cmd[10])},{tonumber(cmd[11]),tonumber(cmd[12])},{tonumber(cmd[13]),tonumber(cmd[14])},{tonumber(cmd[15]),tonumber(cmd[16])},{tonumber(cmd[17]),tonumber(cmd[18])},{tonumber(cmd[19]),tonumber(cmd[20])}}
- if mb_igshop.applyNewTempSell(pc.get_player_id(), slotNum, itemVnum, itemCount, tbl) then
- cmdchat("IGSHOP trade.ApplyWantsItem")
- end
- elseif cmd[1] == "trade.RemoveFromTempSell" then
- if table.getn(cmd) != 2 then syschat("mb_igshop Error->invalid_packet_size(trade.RemoveFromTempSell)") return end
- local slot = tonumber(cmd[2])
- mb_igshop.removeFromTempSell(pc.get_player_id(), slot)
- elseif cmd[1] == "trade.RestoreFromSavedSell" then
- if table.getn(cmd) != 1 then syschat("mb_igshop Error->invalid_packet_size(trade.RestoreFromSavedSell)") return end
- mb_igshop.restoreFromSavedSell(pc.get_player_id())
- elseif cmd[1] == "trade.SaveFromTempSlotSell" then
- if table.getn(cmd) != 1 then syschat("mb_igshop Error->invalid_packet_size(trade.SaveFromTempSlotSell)") return end
- mb_igshop.saveFromTempSell(pc.get_player_id())
- elseif cmd[1] == "trade.ClearAllArraySell" then
- if table.getn(cmd) != 1 then syschat("mb_igshop Error->invalid_packet_size(trade.ClearAllArraySell)") return end
- mb_igshop.clearAllArraySell(pc.get_player_id())
- elseif cmd[1] == "trade.AppendSocket" then
- if table.getn(cmd) < 3 then syschat("mb_igshop Error->invalid_packet_size(trade.AppendSocket)") return end
- if table.getn(cmd) > 3 then
- for i = 4, table.getn(cmd)-1 do
- cmd[3] = ""..cmd[3].."#"..cmd[i]
- end
- end
- local pos = tonumber(cmd[2])
- local findItem = trim(cmd[3])
- mb_igshop.FindStoneItemAndPut(pos, string.lower(findItem))
- elseif cmd[1] == "trade.RemoveSocket" then
- if table.getn(cmd) != 2 then syschat("mb_igshop Error->invalid_packet_size(trade.RemoveSocket)") return end
- mb_igshop.clearStoneSlotArraySpec(pc.get_player_id(), tonumber(cmd[2]))
- elseif cmd[1] == "trade.RequestTrade" then
- if table.getn(cmd) != 5 then syschat("mb_igshop Error->invalid_packet_size(trade.RequestTrade)") return end
- mb_igshop.MakeRequestTrade(tonumber(cmd[2]), tonumber(cmd[3]), tonumber(cmd[4]), cmd[5])
- elseif cmd[1] == "trade.CheckTradeItem" then
- if table.getn(cmd) != 5 then syschat("mb_igshop Error->invalid_packet_size(trade.CheckTradeItem)") return end
- local representedPos = math.floor(tonumber(cmd[2]))
- local inventoryPos = math.floor(tonumber(cmd[3]))
- local lastPYArrayPos = math.floor(tonumber(cmd[4]))
- local givePos = math.floor(tonumber(cmd[5]))
- if representedPos <= 0 or representedPos > igshop_maximumSlotSize then syschat("mb_igshop Error->invalid_slot_num") return end
- if givePos <= 0 or givePos > igshop_maximumSlotSize then syschat("mb_igshop Error->invalid_give_slot_num") return end
- mb_igshop.CheckTradeItem(representedPos, inventoryPos, lastPYArrayPos, givePos)
- elseif cmd[1] == "trade.SecondWave" then
- if table.getn(cmd) != 6 then syschat("mb_igshop Error->invalid_packet_size(trade.SecondWave)") return end
- local old_newID = math.floor(tonumber(cmd[2]))
- local old_myPos = math.floor(tonumber(cmd[3]))
- local my_ID = math.floor(tonumber(cmd[4]))
- local myPos = math.floor(tonumber(cmd[5]))
- local inventoryPos = math.floor(tonumber(cmd[6]))
- if old_newID <= 0 or old_newID > igshop_maximumSlotSize or my_ID <= 0 or my_ID > igshop_maximumSlotSize then syschat("mb_igshop Error->invalid_slot_num") return end
- if old_myPos <= 0 or old_myPos > igshop_maximumSlotSize or myPos <= 0 or myPos > igshop_maximumSlotSize then syschat("mb_igshop Error->invalid_give_slot_num") return end
- mb_igshop.SecondWave(old_newID, old_myPos, my_ID, myPos, inventoryPos)
- elseif cmd[1] == "trade.ApplyTrade" then
- if table.getn(cmd) != 1 then syschat("mb_igshop Error->invalid_packet_size(trade.ApplyTrade)") return end
- if not mb_igshop.gm_buy_check() then syschat(loadLang(56)) return end
- mb_igshop.DoTrade()
- cmdchat("IGSHOP REFRESHAFTERBUY")
- mb_igshop.clearAllArraySell(pc.get_player_id())
- elseif cmd[1] == "trade.ClaimTradeItem" then
- if table.getn(cmd) != 5 then syschat("mb_igshop Error->invalid_packet_size(trade.ClaimTradeItem)") return end
- mb_igshop.ClaimTradeItem(tonumber(cmd[2]), tonumber(cmd[3]), tonumber(cmd[4]), tonumber(cmd[5]))
- elseif cmd[1] == "trade.RemoveGivesSlot" then
- if table.getn(cmd) != 2 then syschat("mb_igshop Error->invalid_packet_size(trade.RemoveGivesSlot)") return end
- local pos = math.floor(tonumber(cmd[2]))
- mb_igshop.removeGivesItem(pc.get_player_id(), pos)
- end
- end
- end
- ------------------------
- --Client commander End--
- ------------------------
- ------------------------------------
- --Temporary array controller Start--
- ------------------------------------
- -- array struct: tempTradeItemContainer[playerID] = {playerID, {}, {}, {{1,0}, {1,0}, {1,0}, {1,0}}, {}, {}, {}}
- --#1 = playerID; #2 = temporary sell item container ; #3 = saved sell item container ; #4 = socked finder temp container ; #5 = wants container ; #6 gives container ; #7 safe item data container
- when logout with mb_igshop.hasTempArray(pc.get_player_id()) begin
- mb_igshop.deleteTempArray(pc.get_player_id())
- end
- function checkTradeDataSell(playerID)
- if not mb_igshop.hasTempArray(playerID) then return false end
- if tempTradeItemContainer[playerID][3] == {} then return false end
- local allNil = false
- for i = 1, igshop_maximumSlotSize do
- if tempTradeItemContainer[playerID][3][i] == nil then
- allNil = false
- else
- allNil = true
- break
- end
- end
- return allNil
- end
- function hasSameSocket(playerID, currSlot, aType)
- mb_igshop.makeTempArray(playerID)
- for i = 1, table.getn(tempTradeItemContainer[playerID][4]) do
- if i != currSlot then
- if tempTradeItemContainer[playerID][4][i][2] == aType then
- return true
- end
- end
- end
- return false
- end
- function registerSocketTempArray(playerID, stoneSlot, stoneVnum, aType)
- if not mb_igshop.hasTempArray(playerID) then return end
- if table.getn(tempTradeItemContainer[playerID][4]) < stoneSlot then return end
- tempTradeItemContainer[playerID][4][stoneSlot][1] = stoneVnum
- tempTradeItemContainer[playerID][4][stoneSlot][2] = aType
- end
- function clearStoneSlotsArray(playerID)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][4] = {{1,0}, {1,0}, {1,0}, {1,0}}
- end
- function clearStoneSlotArraySpec(playerID, pos)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][4][pos] = {1,0}
- end
- function clearAllArraySell(playerID)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][2] = {}
- tempTradeItemContainer[playerID][3] = {}
- tempTradeItemContainer[playerID][4] = {{1,0}, {1,0}, {1,0}, {1,0}}
- tempTradeItemContainer[playerID][5] = {}
- tempTradeItemContainer[playerID][6] = {}
- tempTradeItemContainer[playerID][7] = {}
- end
- function saveFromTempSell(playerID)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][3] = deepcopy(tempTradeItemContainer[playerID][2])
- end
- function removeFromTempSell(playerID, slotNum)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][2][slotNum] = nil
- end
- function restoreFromSavedSell(playerID)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][2] = deepcopy(tempTradeItemContainer[playerID][3])
- end
- function applyNewTempSell(playerID, slotNum, itemVnum, itemCount, attrTable)
- mb_igshop.makeTempArray(playerID)
- if tempTradeItemContainer[playerID][2][slotNum] == nil then
- tempTradeItemContainer[playerID][2][slotNum] = {}
- else
- syschat(loadLang(13))
- return false
- end
- local sqlrec = game.mysql_query("SELECT socket_pct FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = "..itemVnum.." LIMIT 1")
- if table.getn(sqlrec) != 1 then syschat("mb_igshop Error->failed_read_socket_pct_durningTempSell") return false end
- local socketNum = tonumber(sqlrec[1][1])
- if socketNum < 4 then tempTradeItemContainer[playerID][4][4] = {0,0} end
- if socketNum < 3 then tempTradeItemContainer[playerID][4][3] = {0,0} end
- if socketNum < 2 then tempTradeItemContainer[playerID][4][2] = {0,0} end
- if socketNum < 1 then tempTradeItemContainer[playerID][4][1] = {0,0} end
- tempTradeItemContainer[playerID][2][slotNum][1] = itemVnum
- tempTradeItemContainer[playerID][2][slotNum][2] = itemCount
- tempTradeItemContainer[playerID][2][slotNum][3] = {}
- for i = 1, table.getn(tempTradeItemContainer[playerID][4]) do
- table.insert(tempTradeItemContainer[playerID][2][slotNum][3], {})
- table.insert(tempTradeItemContainer[playerID][2][slotNum][3][i], tempTradeItemContainer[playerID][4][i][1])
- table.insert(tempTradeItemContainer[playerID][2][slotNum][3][i], tempTradeItemContainer[playerID][4][i][2])
- table.insert(tempTradeItemContainer[playerID][2][slotNum][3][i], tempTradeItemContainer[playerID][4][i][3])
- end
- tempTradeItemContainer[playerID][2][slotNum][4] = attrTable
- return true
- end
- function hasTempArray(playerID)
- if tempTradeItemContainer[playerID] != nil then
- if tempTradeItemContainer[playerID][1] == playerID then
- return true
- end
- return false
- else
- return false
- end
- end
- function makeTempArray(playerID)
- if mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID] = {playerID, {}, {}, {{1,0}, {1,0}, {1,0}, {1,0}}, {}, {}, {}}
- end
- function deleteTempArray(playerID)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID] = nil
- end
- function prepareSellDataForTxt(playerID)
- if not mb_igshop.hasTempArray(playerID) then return {} end
- if tempTradeItemContainer[playerID][3] == {} then return {} end
- local returnTable = {}
- local temp = {}
- local unsusedShit = 0
- for i = 1, igshop_maximumSlotSize do
- if tempTradeItemContainer[playerID][3][i] == nil then unsusedShit = 0
- else
- temp = {}
- table.insert(temp, i) --slotID
- table.insert(temp, tempTradeItemContainer[playerID][3][i][1]) --itemVnum
- table.insert(temp, tempTradeItemContainer[playerID][3][i][2]) --itemCount
- table.insert(temp, tempTradeItemContainer[playerID][3][i][3]) --socketTable (only the first record used on save (socketVnum))
- table.insert(temp, tempTradeItemContainer[playerID][3][i][4]) --attrTable -> type, value
- table.insert(returnTable, temp)
- end
- end
- return returnTable
- end
- function appendWantsContainer(playerID, item)
- if not mb_igshop.hasTempArray(playerID) then return false end
- local pos = tonumber(item[1])
- tempTradeItemContainer[playerID][5][pos] = {}
- table.insert(tempTradeItemContainer[playerID][5][pos], tonumber(item[2])) --vnum
- table.insert(tempTradeItemContainer[playerID][5][pos], tonumber(item[3])) --count
- table.insert(tempTradeItemContainer[playerID][5][pos], {}) --table for sockets
- table.insert(tempTradeItemContainer[playerID][5][pos][3], tonumber(item[4]))
- table.insert(tempTradeItemContainer[playerID][5][pos][3], tonumber(item[5]))
- table.insert(tempTradeItemContainer[playerID][5][pos][3], tonumber(item[6]))
- table.insert(tempTradeItemContainer[playerID][5][pos][3], tonumber(item[7]))
- table.insert(tempTradeItemContainer[playerID][5][pos], {}) --table for attrs
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr1
- table.insert(tempTradeItemContainer[playerID][5][pos][4][1], tonumber(item[8])) --attr1 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][1], tonumber(item[9])) --attr1 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr2
- table.insert(tempTradeItemContainer[playerID][5][pos][4][2], tonumber(item[10])) --attr2 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][2], tonumber(item[11])) --attr2 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr3
- table.insert(tempTradeItemContainer[playerID][5][pos][4][3], tonumber(item[12])) --attr3 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][3], tonumber(item[13])) --attr3 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr4
- table.insert(tempTradeItemContainer[playerID][5][pos][4][4], tonumber(item[14])) --attr4 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][4], tonumber(item[15])) --attr4 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr5
- table.insert(tempTradeItemContainer[playerID][5][pos][4][5], tonumber(item[16])) --attr5 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][5], tonumber(item[17])) --attr5 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr6
- table.insert(tempTradeItemContainer[playerID][5][pos][4][6], tonumber(item[18])) --attr6 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][6], tonumber(item[19])) --attr6 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr7
- table.insert(tempTradeItemContainer[playerID][5][pos][4][7], tonumber(item[20])) --attr7 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][7], tonumber(item[21])) --attr7 value
- table.insert(tempTradeItemContainer[playerID][5][pos][4], {}) --attr8
- table.insert(tempTradeItemContainer[playerID][5][pos][4][8], tonumber(item[22])) --attr8 type
- table.insert(tempTradeItemContainer[playerID][5][pos][4][8], tonumber(item[23])) --attr8 value
- return true
- end
- function loadWantsData(playerID)
- if not mb_igshop.hasTempArray(playerID) then return {} end
- return tempTradeItemContainer[playerID][5]
- end
- function loadGivesData(playerID)
- if not mb_igshop.hasTempArray(playerID) then return {} end
- return tempTradeItemContainer[playerID][6]
- end
- function appendGivesItem(playerID, appendTable, pos)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][6][pos] = appendTable
- end
- function removeGivesItem(playerID, pos)
- if not mb_igshop.hasTempArray(playerID) then return end
- tempTradeItemContainer[playerID][6][pos] = nil
- end
- function registerSafeItemData(playerID, safeItemData)
- mb_igshop.makeTempArray(playerID)
- tempTradeItemContainer[playerID][7] = safeItemData
- end
- function getSafeItemData(playerID)
- if not mb_igshop.hasTempArray(playerID) then return {} end
- return tempTradeItemContainer[playerID][7]
- end
- ----------------------------------
- --Temporary array controller End--
- ----------------------------------
- --------------------------
- --New trade system Start--
- --------------------------
- function DoTrade()
- local safeData = mb_igshop.getSafeItemData(pc.get_player_id())
- if table.getn(safeData) <= 0 then syschat(loadLang(14)) return end
- if mb_igshop.IsTradeItem(safeData[1]) != 1 then syschat(loadLang(15)) return end
- local givesData = mb_igshop.loadGivesData(pc.get_player_id())
- local wantsData = mb_igshop.loadWantsData(pc.get_player_id())
- local itemsInList = 0
- local maxItem = 0
- for i = 1, igshop_maximumSlotSize do
- if givesData[i] != nil then
- itemsInList = 1 + itemsInList
- if not item.select_cell(givesData[i][6]) then syschat(loadLang(16)) return end
- if item.get_id() != givesData[i][1] or item.get_count() != givesData[i][3] or item.get_vnum() != givesData[i][2] then syschat(loadLang(16)) return end
- end
- if wantsData[i] != nil then
- maxItem = maxItem + 1
- end
- end
- if maxItem <= 0 or maxItem != itemsInList then syschat(loadLang(17)) return end
- local stringWriter = ""
- for i = 1, igshop_maximumSlotSize do
- if givesData[i] != nil then
- stringWriter = stringWriter..""..i.."#"
- stringWriter = stringWriter..""..givesData[i][2].."#"
- stringWriter = stringWriter..""..givesData[i][3]
- for x = 1, table.getn(givesData[i][4]) do
- stringWriter = stringWriter.."".."#"..givesData[i][4][x]
- end
- for x = 1, table.getn(givesData[i][5]) do
- stringWriter = stringWriter.."".."#"..givesData[i][5][x][1]
- stringWriter = stringWriter.."".."#"..givesData[i][5][x][2]
- end
- stringWriter = stringWriter.."\\n"
- item.select_cell(givesData[i][6])
- item.remove()
- end
- end
- local fOpen = io.open(igshop_path.."data/"..safeData[4].."/"..safeData[1]..".txt", "w+")
- fOpen:write(stringWriter)
- fOpen:flush()
- fOpen:close()
- local itemdata = split_(tostring(safeData[7][((safeData[2]-1)*5)+safeData[3]]), "#")
- local fOpen = io.open(igshop_path.."data/"..safeData[4].."/trade_data_list.txt", "a+")
- fOpen:write(safeData[1].."#"..itemdata[2].."#"..itemdata[3].."#"..pc.get_name().."#"..itemdata[7].."#"..itemdata[8].."#"..itemdata[9].."#"..itemdata[10].."#"..itemdata[11].."#"..itemdata[12].."#"..itemdata[13].."#"..itemdata[14].."#"..itemdata[15].."#"..itemdata[16].."#"..itemdata[17].."#"..itemdata[18].."#"..itemdata[19].."#"..itemdata[20].."#"..itemdata[21].."#"..itemdata[22].."#"..itemdata[23].."#"..itemdata[24].."#"..itemdata[25].."#"..itemdata[26].."#"..itemdata[27].."#"..itemdata[28].."\\n")
- fOpen:flush()
- fOpen:close()
- os.remove(igshop_path.."tradedata/"..safeData[1]..".txt")
- mb_igshop.ItemRemoveFromOwnerTxt(safeData[4], safeData[1], safeData[5], safeData[5])
- mb_igshop.ItemRemoveFromGroupTxt(safeData[6], safeData[7], ((safeData[2]-1)*5)+safeData[3], safeData[5], safeData[5])
- mb_igshop.GiveItemToTxt(tostring(safeData[7][((safeData[2]-1)*5)+safeData[3]]), safeData[5], safeData[5])
- end
- function SecondChance(itemVnum, itemCount, sockets, attrs, representedPos, wantsData)
- if itemVnum != wantsData[representedPos][1] or itemCount != wantsData[representedPos][2] then syschat(loadLang(18)) return false end
- for x = 1, 4 do
- if wantsData[representedPos][3][x] == 1 then
- if sockets[x] < 1 then syschat(loadLang(18)) return false end
- elseif wantsData[representedPos][3][x] > 1 and wantsData[representedPos][3][x] != 28960 then
- for y = 1, 4 do
- if wantsData[representedPos][3][x] == sockets[y] then break end
- if y >= 4 then syschat(loadLang(18)) return false end
- end
- end
- end
- for x = 1, 6 do
- if wantsData[representedPos][4][x][1] > 0 then
- for y = 1, 6 do
- if wantsData[representedPos][4][x][1] == attrs[y][1] then
- if attrs[y][2] >= wantsData[representedPos][4][x][2] then break end
- end
- if y >= 6 then syschat(loadLang(18)) return false end
- end
- end
- end
- for x = 7, 8 do
- if wantsData[representedPos][4][x][1] > 0 then
- for y = 7, 8 do
- if wantsData[representedPos][4][x][1] == attrs[y][1] then
- if attrs[y][2] >= wantsData[representedPos][4][x][2] then break end
- end
- if y >= 8 then syschat(loadLang(18)) return false end
- end
- end
- end
- return true
- end
- function SecondWave(old_newID, old_myPos, my_ID, myPos, inventoryPos)
- local wantsData = mb_igshop.loadWantsData(pc.get_player_id())
- if not mb_igshop.gm_buy_check() then syschat(loadLang(56)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if wantsData[my_ID] == nil then syschat(loadLang(19)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if table.getn(wantsData[my_ID]) != 4 then syschat(loadLang(19)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- local givesData = mb_igshop.loadGivesData(pc.get_player_id())
- if not item.select_cell(inventoryPos) then syschat(loadLang(54)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- local itemID = item.get_id()
- local maxItem = 0
- local itemsInList = 0
- for i = 1, igshop_maximumSlotSize do
- if givesData[i] != nil then
- if givesData[i][1] == itemID then syschat(loadLang(20)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- itemsInList = 1 + itemsInList
- end
- if wantsData[i] != nil then
- maxItem = maxItem + 1
- end
- end
- if itemsInList >= maxItem then syschat(loadLang(21)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if givesData[myPos] != nil then syschat(loadLang(13)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- local itemVnum = item.get_vnum()
- if not mb_igshop.check_always_available(itemVnum) then
- if not mb_igshop.check_type(iType, iSubType) then syschat(loadLang(57)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if not mb_igshop.check_antiflag(itemVnum) then syschat(loadLang(57)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if not mb_igshop.check_sellableItems(itemVnum) then syschat(loadLang(57)) cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- end
- local itemCount = item.get_count()
- local sockets = {item.get_socket(0), item.get_socket(1), item.get_socket(2), item.get_socket(3)}
- local attrs = {{item.get_attr_type(0), item.get_attr_value(0)}, {item.get_attr_type(1), item.get_attr_value(1)}, {item.get_attr_type(2), item.get_attr_value(2)}, {item.get_attr_type(3), item.get_attr_value(3)},{item.get_attr_type(4), item.get_attr_value(4)},{item.get_attr_type(5), item.get_attr_value(5)}, {item.get_attr_type(6), item.get_attr_value(6)}, {item.get_attr_type(7), item.get_attr_value(7)}}
- if givesData[old_myPos] == nil then syschat("mb_igshop Error->previous_item_not_found") cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if table.getn(givesData[old_myPos]) != 6 then syschat("mb_igshop Error->previous_item_not_found") cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if not mb_igshop.SecondChance(itemVnum, itemCount, sockets, attrs, my_ID, wantsData) then cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- if not mb_igshop.SecondChance(givesData[old_myPos][2], givesData[old_myPos][3], givesData[old_myPos][4], givesData[old_myPos][5], old_newID, wantsData) then cmdchat("IGSHOP SecondFail/"..old_newID.."/"..my_ID) return end
- local appendTable = {}
- table.insert(appendTable, itemID)
- table.insert(appendTable, itemVnum)
- table.insert(appendTable, itemCount)
- table.insert(appendTable, sockets)
- table.insert(appendTable, attrs)
- table.insert(appendTable, inventoryPos)
- mb_igshop.appendGivesItem(pc.get_player_id(), appendTable, myPos)
- cmdchat("IGSHOP SuccessAppend/"..myPos)
- end
- function CheckTradeItem(representedPos, inventoryPos, lastPYArrayPos, givePos)
- local wantsData = mb_igshop.loadWantsData(pc.get_player_id())
- if not mb_igshop.gm_buy_check() then syschat(loadLang(56)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- if wantsData[representedPos] == nil then syschat(loadLang(19)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- if table.getn(wantsData[representedPos]) != 4 then syschat(loadLang(19)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- local givesData = mb_igshop.loadGivesData(pc.get_player_id())
- if not item.select_cell(inventoryPos) then syschat(loadLang(54)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- local itemID = item.get_id()
- local maxItem = 0
- local itemsInList = 0
- for i = 1, igshop_maximumSlotSize do
- if givesData[i] != nil then
- if givesData[i][1] == itemID then syschat(loadLang(20)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- itemsInList = 1 + itemsInList
- end
- if wantsData[i] != nil then
- maxItem = maxItem + 1
- end
- end
- if itemsInList >= maxItem then syschat(loadLang(21)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- if givesData[givePos] != nil then syschat(loadLang(13)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- local itemVnum = item.get_vnum()
- if not mb_igshop.check_always_available(itemVnum) then
- if not mb_igshop.check_type(item.get_type(), item.get_sub_type()) then syschat(loadLang(57)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- if not mb_igshop.check_antiflag(itemVnum) then syschat(loadLang(57)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- if not mb_igshop.check_sellableItems(itemVnum) then syschat(loadLang(57)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- end
- local itemCount = item.get_count()
- local sockets = {item.get_socket(0), item.get_socket(1), item.get_socket(2), item.get_socket(3)}
- local attrs = {{item.get_attr_type(0), item.get_attr_value(0)}, {item.get_attr_type(1), item.get_attr_value(1)}, {item.get_attr_type(2), item.get_attr_value(2)}, {item.get_attr_type(3), item.get_attr_value(3)},{item.get_attr_type(4), item.get_attr_value(4)},{item.get_attr_type(5), item.get_attr_value(5)}, {item.get_attr_type(6), item.get_attr_value(6)}, {item.get_attr_type(7), item.get_attr_value(7)}}
- if itemVnum != wantsData[representedPos][1] or itemCount != wantsData[representedPos][2] then syschat(loadLang(18)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- for x = 1, 4 do
- if wantsData[representedPos][3][x] == 1 then
- if sockets[x] < 1 then syschat(loadLang(18)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- elseif wantsData[representedPos][3][x] > 1 and wantsData[representedPos][3][x] != 28960 then
- for y = 1, 4 do
- if wantsData[representedPos][3][x] == sockets[y] then break end
- if y >= 4 then syschat(loadLang(18)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- end
- end
- end
- for x = 1, 6 do
- if wantsData[representedPos][4][x][1] > 0 then
- for y = 1, 6 do
- if wantsData[representedPos][4][x][1] == attrs[y][1] then
- if attrs[y][2] >= wantsData[representedPos][4][x][2] then break end
- end
- if y >= 6 then syschat(loadLang(18)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- end
- end
- end
- for x = 7, 8 do
- if wantsData[representedPos][4][x][1] > 0 then
- for y = 7, 8 do
- if wantsData[representedPos][4][x][1] == attrs[y][1] then
- if attrs[y][2] >= wantsData[representedPos][4][x][2] then break end
- end
- if y >= 8 then syschat(loadLang(18)) cmdchat("IGSHOP RecvTradeError/"..lastPYArrayPos.."/"..representedPos) return end
- end
- end
- end
- local appendTable = {}
- table.insert(appendTable, itemID)
- table.insert(appendTable, itemVnum)
- table.insert(appendTable, itemCount)
- table.insert(appendTable, sockets)
- table.insert(appendTable, attrs)
- table.insert(appendTable, inventoryPos)
- mb_igshop.appendGivesItem(pc.get_player_id(), appendTable, givePos)
- cmdchat("IGSHOP SuccessAppend/"..givePos)
- end
- function ClaimTradeItem(itemID, page, slot, itemPos)
- local data = {}
- local fOpen = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "r")
- if fOpen != nil then
- for i in fOpen:lines() do
- table.insert(data, i)
- end
- end
- if table.getn(data) <= 0 then syschat(loadLang(22)) return end
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then syschat(loadLang(22)) return end
- local item = split_(data[((page-1)*5)+slot],"#")
- if tonumber(item[1]) != itemID then syschat(loadLang(22)) return end
- local sOpen = io.open(igshop_path.."data/"..pc.get_name().."/"..item[1]..".txt", "r")
- if sOpen == nil then syschat(loadLang(22)) return end
- local tradeItems = {}
- for i in sOpen:lines() do
- table.insert(tradeItems, i)
- end
- if table.getn(tradeItems) <= 0 then syschat(loadLang(22)) mb_igshop.RemoveClaimedTradeItem(tonumber(item[1]), data, ((page-1)*5)+slot) cmdchat("IGSHOP REFRESHAFTERBUY") return end
- local foundItem = {}
- for i = 1, table.getn(tradeItems) do
- local thisItem = split_(tradeItems[i], "#")
- if tonumber(thisItem[1]) == itemPos then foundItem = thisItem break end
- end
- if table.getn(foundItem) <= 0 then syschat(loadLang(22)) return end
- pc.give_item_with(tonumber(foundItem[2]), tonumber(foundItem[3]), tonumber(foundItem[7]), tonumber(foundItem[8]), tonumber(foundItem[9]), tonumber(foundItem[10]), tonumber(foundItem[11]), tonumber(foundItem[12]), tonumber(foundItem[13]), tonumber(foundItem[14]), tonumber(foundItem[15]), tonumber(foundItem[16]), tonumber(foundItem[17]), tonumber(foundItem[18]), tonumber(foundItem[19]), tonumber(foundItem[20]), tonumber(foundItem[4]), tonumber(foundItem[5]), tonumber(foundItem[6]))
- if table.getn(tradeItems) > 1 then
- local sOpen2 = io.open(igshop_path.."data/"..pc.get_name().."/"..item[1]..".txt", "w+")
- for i = 1, table.getn(tradeItems) do
- local thisItem = split_(tradeItems[i], "#")
- if tonumber(thisItem[1]) != itemPos then
- sOpen2:write(tradeItems[i].."\\n")
- end
- end
- sOpen2:flush()
- sOpen2:close()
- else
- mb_igshop.RemoveClaimedTradeItem(tonumber(item[1]), data, ((page-1)*5)+slot)
- cmdchat("IGSHOP REFRESHAFTERBUY")
- end
- end
- function RemoveClaimedTradeItem(itemID, itemdata, pos)
- os.remove(igshop_path.."data/"..pc.get_name().."/"..itemID..".txt")
- table.remove(itemdata, pos)
- local fOpen = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "w+")
- for i = 1, table.getn(itemdata) do
- fOpen:write(itemdata[i].."\\n")
- end
- fOpen:flush()
- fOpen:close()
- end
- function OpenTradeToPreview(itemID, page, slot)
- local data = mb_igshop.get_myitems()
- if table.getn(data) <= 0 then syschat(loadLang(23)) return end
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then syschat(loadLang(23)) return end
- local item = split_(data[((page-1)*5)+slot],"#")
- if tonumber(item[1]) != itemID then syschat(loadLang(23)) return end
- local sOpen = io.open(igshop_path.."tradedata/"..item[1]..".txt", "r")
- if sOpen == nil then syschat(loadLang(23)) return end
- local tradeItems = {}
- for i in sOpen:lines() do
- table.insert(tradeItems, i)
- end
- cmdchat("IGSHOP OpenGetDialog/"..itemID.."/"..page.."/"..slot.."/1")
- for i = 1, table.getn(tradeItems) do
- local thisItem = split_(tradeItems[i], "#")
- cmdchat("trade.AppendGetItem "..thisItem[1].." "..thisItem[2].." "..thisItem[3].." "..thisItem[4].." "..thisItem[5].." "..thisItem[6].." "..thisItem[7].." "..thisItem[8].." "..thisItem[9].." "..thisItem[10].." "..thisItem[11].." "..thisItem[12].." "..thisItem[13].." "..thisItem[14].." "..thisItem[15].." "..thisItem[16].." "..thisItem[17].." "..thisItem[18].." "..thisItem[19].." "..thisItem[20].." "..thisItem[21].." "..thisItem[22])
- end
- end
- function OpenTradeToGet(itemID, page, slot)
- local data = {}
- local fOpen = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "r")
- if fOpen != nil then
- for i in fOpen:lines() do
- table.insert(data, i)
- end
- end
- if table.getn(data) <= 0 then syschat(loadLang(22)) return end
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then syschat(loadLang(22)) return end
- local item = split_(data[((page-1)*5)+slot],"#")
- if tonumber(item[1]) != itemID then syschat(loadLang(22)) return end
- local sOpen = io.open(igshop_path.."data/"..pc.get_name().."/"..item[1]..".txt", "r")
- if sOpen == nil then syschat(loadLang(22)) return end
- local tradeItems = {}
- for i in sOpen:lines() do
- table.insert(tradeItems, i)
- end
- cmdchat("IGSHOP OpenGetDialog/"..itemID.."/"..page.."/"..slot.."/0")
- for i = 1, table.getn(tradeItems) do
- local thisItem = split_(tradeItems[i], "#")
- cmdchat("trade.AppendGetItem "..thisItem[1].." "..thisItem[2].." "..thisItem[3].." "..thisItem[4].." "..thisItem[5].." "..thisItem[6].." "..thisItem[7].." "..thisItem[8].." "..thisItem[9].." "..thisItem[10].." "..thisItem[11].." "..thisItem[12].." "..thisItem[13].." "..thisItem[14].." "..thisItem[15].." "..thisItem[16].." "..thisItem[17].." "..thisItem[18].." "..thisItem[19].." "..thisItem[20].." "..thisItem[21].." "..thisItem[22])
- end
- end
- function MakeRequestTrade(itemID, page, slot, group)
- for i = 1, table.getn(availableBuyClass) do
- if availableBuyClass[i] == group then break end
- if i == table.getn(availableBuyClass) then syschat("mb_igshop Error->WrongGroup") syschat(group) return end
- end
- if group == "get_trade_items" then
- mb_igshop.OpenTradeToGet(itemID, page, slot)
- return
- elseif group == "my_sales" then
- mb_igshop.OpenTradeToPreview(itemID, page, slot)
- return
- end
- local data
- if group == "Kereses" then
- local file = io.open(igshop_path.."data/"..pc.get_name().."/search.txt", "r")
- local tbl = {}
- for item in file:lines() do
- table.insert(tbl, split_(item, "#"))
- end
- file:close()
- data = mb_igshop.searchItem(tbl[1][1],tbl[1][2], page, 2)
- else
- data = mb_igshop.get_items(group)
- end
- if table.getn(data) > 0 then
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then syschat(loadLang(15)) return end
- local item = split_(data[((page-1)*5)+slot],"#")
- if tonumber(item[1]) != itemID then syschat(loadLang(15)) return end
- if mb_igshop.IsTradeItem(itemID) != 1 then syschat(loadLang(24)) return end
- local mOpen = io.open(igshop_path.."tradedata/"..itemID..".txt", r)
- if mOpen == nil then return end
- local iData = {}
- for i in mOpen:lines() do
- table.insert(iData, i)
- end
- if iData == {} then return end
- mb_igshop.clearAllArraySell(pc.get_player_id())
- local safeItemData = {}
- table.insert(safeItemData, itemID)
- table.insert(safeItemData, page)
- table.insert(safeItemData, slot)
- table.insert(safeItemData, item[4])
- table.insert(safeItemData, tonumber(item[3]))
- table.insert(safeItemData, group)
- table.insert(safeItemData, data)
- mb_igshop.registerSafeItemData(pc.get_player_id(), safeItemData)
- local item = {}
- cmdchat("IGSHOP OpenTradeDiag")
- for x = 1, table.getn(iData) do
- item = split_(iData[x], "#")
- if not mb_igshop.appendWantsContainer(pc.get_player_id(), item) then syschat(loadLang(25)) return end
- cmdchat("trade.SendData "..item[1].." "..item[2].." "..item[3].." "..item[4].." "..item[5].." "..item[6].." "..item[7].." "..item[8].." "..item[9].." "..item[10].." "..item[11].." "..item[12].." "..item[13].." "..item[14].." "..item[15].." "..item[16].." "..item[17].." "..item[18].." "..item[19].." "..item[20].." "..item[21].." "..item[22])
- end
- else
- syschat(loadLang(15))
- end
- end
- function IsTradeItem(iID)
- local mOpen = io.open(igshop_path.."tradedata/"..iID..".txt", "r")
- if mOpen == nil then
- return 0
- else
- return 1
- end
- end
- function FindTradeItemAndPut(iName, slot)
- local object = mb_igshop.get_itemdata()
- local itemIDs = {}
- local gtype
- if string.len(iName) < 2 then syschat(loadLang(26)) return end
- if iName != "" then
- for i = 1, table.getn(object) do
- if string.lower(tostring(item_name(tonumber(object[i])))) == iName then
- table.insert(itemIDs, tonumber(object[i]))
- end
- end
- if table.getn(itemIDs) < 1 then syschat(loadLang(27)) syschat(string.gsub(iName,"%%","").." ") return end
- if table.getn(itemIDs) > 1 then syschat(loadLang(28)) return end
- end
- local iFlag = mb_igshop.get_flag(itemIDs[1])
- local flags = {2^14, 2^13, 2^12, 2^11, 2^10, 2^9, 2^8, 2^7, 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^0}
- local flag_table = {}
- local isStackable = 0
- table.foreach(flags, function(_, v) if iFlag >= v then table.insert(flag_table, v) iFlag = iFlag - v end end)
- for i = 1, table.getn(flag_table) do
- if flag_table[i] == 4 then isStackable = 1 break end
- end
- local recv = game.mysql_query("SELECT type, subtype, socket_pct FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..itemIDs[1].."' LIMIT 1")
- local iType = 0
- local iSubType = 0
- local maxStoneSlot = 0
- if table.getn(recv) != 1 then syschat(loadLang(29)) return end
- iType = tonumber(recv[1][1])
- iSubType = tonumber(recv[1][2])
- maxStoneSlot = tonumber(recv[1][3])
- local itemVnum = tonumber(itemIDs[1])
- if not mb_igshop.check_always_available(itemVnum) then
- if not mb_igshop.check_type(iType, iSubType) then syschat(loadLang(57)) return end
- if not mb_igshop.check_antiflag(itemVnum) then syschat(loadLang(57)) return end
- if not mb_igshop.check_sellableItems(itemVnum) then syschat(loadLang(57)) return end
- end
- local addOns = 0
- if (iType == 1 and iSubType != 6) or (iType == 2 and iSubType == 0) then --stone items
- addOns = 2
- elseif (iType == 2 and iSubType == 1) or (iType == 2 and iSubType == 2) or (iType == 2 and iSubType == 4) then -- attr only items
- addOns = 1
- elseif (iType == 2 and iSubType == 3) or (iType == 2 and iSubType == 5) or (iType == 2 and iSubType == 6) then --ore items
- addOns = 3
- end
- pc.setqf("lastSearch", itemVnum)
- mb_igshop.clearStoneSlotsArray(pc.get_player_id())
- cmdchat("trade.ReturnSearchItem "..itemVnum.." "..slot.." "..isStackable.." "..addOns.." "..maxStoneSlot)
- end
- function FindStoneItemAndPut(slot, iName)
- local object = mb_igshop.get_itemdata()
- local itemIDs = {}
- local gtype
- if string.len(iName) < 2 then syschat(loadLang(26)) return end
- if iName != "" then
- for i = 1, table.getn(object) do
- if string.lower(tostring(item_name(tonumber(object[i])))) == iName then
- table.insert(itemIDs, tonumber(object[i]))
- end
- end
- if table.getn(itemIDs) < 1 then syschat(loadLang(27)) syschat(string.gsub(iName,"%%","").." ") return end
- if table.getn(itemIDs) > 1 then syschat(loadLang(28)) return end
- end
- local lastVnum = pc.getqf("lastSearch")
- if lastVnum <= 0 then syschat(loadLang(30)) return end
- local recv = game.mysql_query("SELECT type, subtype, wearflag, applytype0 FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..itemIDs[1].."' LIMIT 1")
- local iType = 0
- local iSubType = 0
- local iWearflag = 0
- local iApplyType = 0
- if table.getn(recv) != 1 then syschat(loadLang(29)) return end
- iType = tonumber(recv[1][1])
- iSubType = tonumber(recv[1][2])
- iWearflag = tonumber(recv[1][3])
- iApplyType = tonumber(recv[1][4])
- if iType != 10 and iSubType != 0 then syschat(loadLang(31)) return end
- if mb_igshop.hasSameSocket(pc.get_player_id(), slot, iApplyType) and itemIDs[1] != 28960 then syschat(loadLang(32)) return end
- local targetType = 0
- local targetSubType = 0
- local socket_pct = 0
- local recv2 = game.mysql_query("SELECT type, subtype, socket_pct FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..lastVnum.."' LIMIT 1")
- if table.getn(recv2) != 1 then syschat(loadLang(29)) return end
- targetType = tonumber(recv2[1][1])
- targetSubType = tonumber(recv2[1][2])
- socket_pct = tonumber(recv2[1][3])
- if socket_pct < slot then syschat(loadLang(33)) return end
- if targetType == 1 and targetSubType != 6 and iWearflag != 16 then
- if itemIDs[1] != 28960 then
- syschat(loadLang(34))
- return
- end
- elseif targetType == 2 and targetSubType == 0 and iWearflag != 1 then
- if itemIDs[1] != 28960 then
- syschat(loadLang(34))
- return
- end
- end
- mb_igshop.registerSocketTempArray(pc.get_player_id(), slot, itemIDs[1], iApplyType)
- cmdchat("trade.ApplySocket "..slot.." "..itemIDs[1])
- end
- ------------------------
- --New trade system End--
- ------------------------
- -- send quest index
- when login begin
- os.setlocale("fr_FR.ISO8859-1","ctype")
- cmdchat("IGShopqID "..q.getcurrentquestindex())
- end
- -----------------
- --Put Item Start-
- -----------------
- function SellItem(priceY, priceS)
- if igshopEnableTrade then mb_igshop.restoreFromSavedSell(pc.get_player_id()) end
- if not mb_igshop.gm_sell_check() then syschat(loadLang(55)) return end
- if not mb_igshop.expandable_limited_storage("get") then syschat(loadLang(2)) return end
- if not mb_igshop.has_itemlist() then mb_igshop.make_igshop() end
- if priceY < 1 and priceS < 1 and not mb_igshop.checkTradeDataSell(pc.get_player_id()) then syschat(loadLang(35)) return end
- local cell = tonumber(pc.getqf("itemcell"))
- if not item.select_cell(cell) then syschat(loadLang(54)) return end
- if item.get_cell() != cell then syschat(loadLang(36)) return end
- if item.get_id() != pc.getqf("sellitemid") then syschat(loadLang(36)) return end
- local attr = {{item.get_attr_type(0), item.get_attr_value(0)}, {item.get_attr_type(1), item.get_attr_value(1)}, {item.get_attr_type(2), item.get_attr_value(2)}, {item.get_attr_type(3), item.get_attr_value(3)},{item.get_attr_type(4), item.get_attr_value(4)},{item.get_attr_type(5), item.get_attr_value(5)}, {item.get_attr_type(6), item.get_attr_value(6)}, {item.get_attr_type(7), item.get_attr_value(7)}}
- local socket, itemVnum, itemCount, itemID = {item.get_socket(0), item.get_socket(1), item.get_socket(2),item.get_socket(3),item.get_socket(4),item.get_socket(5)}, item.get_vnum(), item.get_count(), item.get_id()
- local iType = item.get_type()
- local iSubType = item.get_sub_type()
- if not mb_igshop.check_always_available(itemVnum) then
- if not mb_igshop.check_type(iType, iSubType) then syschat(loadLang(3)) return end
- if not mb_igshop.check_antiflag(itemVnum) then syschat(loadLang(5)) return end
- if not mb_igshop.check_sellableItems(itemVnum) then syschat(loadLang(5)) return end
- end
- for i = 1, 6 do
- if itype == 1 or itype == 2 then
- if tonumber(socket[i]) == 1 then
- socket[i] = 28960
- end
- end
- end
- if pc.count_item(itemVnum) != pc.getqf("itemcount")then syschat(loadLang(36)) return end
- if item.get_cell() != cell then syschat(loadLang(36)) return end
- for i = 1, itemCount do
- item.select_cell(cell)
- item.remove()
- end
- local open = io.open(igshop_path.."data/"..pc.get_name().."/itemlist.txt", "a+")
- open:write(itemID.."#"..itemVnum.."#"..itemCount.."#"..pc.get_name().."#"..priceS.."#"..priceY.."#"..socket[1].."#"..socket[2].."#"..socket[3].."#"..socket[4].."#"..socket[5].."#"..socket[6].."#"..attr[1][1].."#"..attr[1][2].."#"..attr[2][1].."#"..attr[2][2].."#"..attr[3][1].."#"..attr[3][2].."#"..attr[4][1].."#"..attr[4][2].."#"..attr[5][1].."#"..attr[5][2].."#"..attr[6][1].."#"..attr[6][2].."#"..attr[7][1].."#"..attr[7][2].."#"..attr[8][1].."#"..attr[8][2].."#"..pc.get_account_id().."#"..(get_global_time() + 60*60*48).."\\n")
- open:flush()
- open:close()
- local gtype = ""
- if iType == 1 and iSubType != 6 then
- gtype = "Fegyverek"
- elseif iType == 2 and iSubType == 0 then
- gtype = "Vertek"
- elseif iType == 2 and iSubType == 1 then
- gtype = "Sisakok"
- elseif iType == 2 and iSubType == 2 then
- gtype = "Pajzsok"
- elseif iType == 2 and iSubType == 3 then
- gtype = "Karkotok"
- elseif iType == 2 and iSubType == 4 then
- gtype = "Cipok"
- elseif iType == 2 and iSubType == 5 then
- gtype = "Nyaklancok"
- elseif iType == 2 and iSubType == 6 then
- gtype = "Fulbevalok"
- elseif iType == 28 then
- gtype = "Kosztumok"
- else
- gtype = "Egyebek"
- end
- local open = io.open(igshop_path.."data/"..gtype..".txt", "a+")
- open:write(itemID.."#"..itemVnum.."#"..itemCount.."#"..pc.get_name().."#"..priceS.."#"..priceY.."#"..socket[1].."#"..socket[2].."#"..socket[3].."#"..socket[4].."#"..socket[5].."#"..socket[6].."#"..attr[1][1].."#"..attr[1][2].."#"..attr[2][1].."#"..attr[2][2].."#"..attr[3][1].."#"..attr[3][2].."#"..attr[4][1].."#"..attr[4][2].."#"..attr[5][1].."#"..attr[5][2].."#"..attr[6][1].."#"..attr[6][2].."#"..attr[7][1].."#"..attr[7][2].."#"..attr[8][1].."#"..attr[8][2].."#"..pc.get_account_id().."#"..(get_global_time() + 60*60*48).."\\n")
- open:flush()
- open:close()
- if not igshopEnableTrade then cmdchat("IGSHOP recvSuccessSaleItem") return end
- if not mb_igshop.checkTradeDataSell(pc.get_player_id()) then cmdchat("IGSHOP recvSuccessSaleItem") return end
- local tbl = mb_igshop.prepareSellDataForTxt(pc.get_player_id())
- if tbl == {} then syschat("igshop Error -> sell_table_ret_zero") return end
- local open = io.open(igshop_path.."tradedata/"..itemID..".txt", "r")
- if open == nil then
- open = io.open(igshop_path.."tradedata/"..itemID..".txt", "w+")
- for i = 1, table.getn(tbl) do
- open:write(tbl[i][1].."#"..tbl[i][2].."#"..tbl[i][3].."#"..tbl[i][4][1][1].."#"..tbl[i][4][2][1].."#"..tbl[i][4][3][1].."#"..tbl[i][4][4][1].."#"..tbl[i][5][1][1].."#"..tbl[i][5][1][2].."#"..tbl[i][5][2][1].."#"..tbl[i][5][2][2].."#"..tbl[i][5][3][1].."#"..tbl[i][5][3][2].."#"..tbl[i][5][4][1].."#"..tbl[i][5][4][2].."#"..tbl[i][5][5][1].."#"..tbl[i][5][5][2].."#"..tbl[i][5][6][1].."#"..tbl[i][5][6][2].."#"..tbl[i][5][7][1].."#"..tbl[i][5][7][2].."#"..tbl[i][5][8][1].."#"..tbl[i][5][8][2].."\\n")
- end
- open:flush()
- open:close()
- mb_igshop.clearAllArraySell(pc.get_player_id(9))
- cmdchat("IGSHOP recvSuccessSaleItem")
- else
- syschat("igshop Error -> sell_itemID_exists")
- end
- end
- ---------------
- --Put Item End-
- ---------------
- function check_itemc() -- ez a funkció neve, lol
- if igshop_maxitem_per_char == 0 then return true end -- amennyiben maxitem változó értéke 0, nincs limit
- local data = mb_igshop.get_myitems() -- lekérjük a játékos kirakott itemeit tartalmazó txt tartalmát, és táblában kapjuk vissza a sorokat (1 item 1 sor)
- if table.getn(data) >= igshop_maxitem_per_char then -- amennyiben a táblában lévő rekordok száma nagyobb vagy egyenlő mint maxitem változó értéke hamis állítást válaszol a funkció, tehát a visszatérő érték a hamis
- return false
- else -- ellenkező esetben, ha kisebb mint maxitem, igaz értéket küld vissza a funkció
- return true
- end
- end
- function gm_sell_check()
- if not pc.is_gm() or not igshop_gm_sell_check_enabled then return true end
- if igshop_minimum_gm_level_to_sell <= 0 then return false end
- if pc.get_gm_level() < igshop_minimum_gm_level_to_sell then return false end
- return true
- end
- function gm_buy_check()
- if not pc.is_gm() or not igshop_gm_buy_check_enabled then return true end
- if igshop_minimum_gm_level_to_buy <= 0 then return false end
- if pc.get_gm_level() < igshop_minimum_gm_level_to_buy then return false end
- return true
- end
- function get_account_caracters()
- local playersInAccount = {}
- local query = "SELECT name FROM "..igshop_player_database_name.."."..igshop_player_table_name.." WHERE account_id = '"..pc.get_account_id().."' LIMIT "..igshop_player_per_account
- local retQuery = game.mysql_query(query)
- for i = 1, table.getn(retQuery) do
- table.insert(playersInAccount,retQuery[i][1])
- end
- return playersInAccount or {}
- end
- function check_accIC()
- if igshop_maxitem_per_acc == 0 then return true end -- amennyiben maxitem változó értéke 0, nincs limit
- local playersInAccount = mb_igshop.get_account_caracters() -- lekérjük a felhasználón lévő karaktereket
- local total_items = 0 -- ebben a változóban lesz összeadva az összes berakott tárgy
- for i = 1, table.getn(playersInAccount) do -- 1-től x-ig-szer lefuttatja a megadott függvényt, ahol az x értéke egyenlő a karakterek neveit tartalmazó tábla méretével(rekordjainak számával)
- if io.open(igshop_path.."data/"..playersInAccount[i].."/itemlist.txt", "r") != nil then -- ellenőrzi, hogy az aktuális karakternek van e itemlist.txt fájlja, ez azért kell, hogy legyen egyáltalán mit megnyitni, és ne errorozzon
- total_items = table.getn(mb_igshop.get_itemsfromowner(playersInAccount[i])) + total_items -- hozzáadja az aktuális karakter itemlist.txt-ben szerepő tárgyak számát a fent említett változó értékéhez
- end
- end
- if total_items >= igshop_maxitem_per_acc then -- ismét ha nagyobb vagy egyenlő a bepakolt tárgyak száma, mint a berakható tárgyak száma, akkor hamis értéket küld vissza
- return false
- else
- return true
- end
- end
- function check_always_available(vnum)
- if table.getn(igshop_always_available) <= 0 then return false end
- for i = 1, table.getn(igshop_always_available) do
- if igshop_always_available[i] == vnum then return true end
- end
- return false
- end
- function check_antiflag(vnum, only_table)
- if not igshop_enable_antiflag_check and not only_table then return true end
- local antiflags = igshop_antiflag_table -- antiflagok CSÖKKENŐ sorrendben
- local anti_table = {} -- ide kerülnek majd a valódi antiflagok
- local sql = {}
- if string.find(vnum, ";") == nil and string.find(vnum, " ") == nil then
- sql = game.mysql_query("SELECT antiflag FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..vnum.."' LIMIT 1")
- else
- syschat("mb_igshop Error->potential_sql_inject_string#1")
- return false
- end
- local antiflag = tonumber(sql[1][1])
- table.foreach(antiflags, function(_, v) if antiflag >= v then table.insert(anti_table, v) antiflag = antiflag - v end end) -- itt kapjuk meg a valódi antiflagot, a lényeg, hogy ha az antiflag nagyobb vagy egyenlő mint az éppen soron lévő antiflag az antiflags táblából, akkor levonja azt az értéket az mysqlből szedett antiflag értékéből, és beírja ezt az antiflagot az anti_table-ba
- if only_table then return anti_table end
- if table.getn(igshop_antiflag_filter) <= 0 then return true end
- for i = 1, table.getn(anti_table) do
- for x = 1, table.getn(igshop_antiflag_filter) do
- if anti_table[i] == igshop_antiflag_filter[x] then return false end
- end
- end
- return true
- end
- function check_sellableItems(vnum)
- if table.getn(igshop_not_sellable_items) <= 0 then return true end
- for i = 1, table.getn(igshop_not_sellable_items) do
- if igshop_not_sellable_items[i] == vnum then return false end
- end
- return true
- end
- function check_type(item_type, item_sub_type)
- if igshop_enable_type_filtering then
- for i = 1, table.getn(igshop_disabled_types) do
- if igshop_disabled_types[i] == item_type then return false end
- end
- end
- if igshop_enable_sub_type_filtering then
- for i = 1, table.getn(igshop_disabled_sub_types) do
- if igshop_disabled_sub_types[i] == item_sub_type then return false end
- end
- end
- return true
- end
- function char_filters()
- if igshop_enable_char_level_filter and pc.get_level() < igshop_min_level then return false end
- if igshop_enable_char_playtime_filter and pc.get_playtime() < igshop_min_playtime then return false end
- return true
- end
- function get_prevdata()
- local prev_data = 0
- local open2 = io.open(igshop_path.."accids/"..pc.get_account_id().."/storage_limit.txt", "r")
- for line in open2:lines() do
- prev_data = prev_data + tonumber(line)
- end
- open2:close()
- return prev_data
- end
- function expandable_limited_storage(s_type)
- local current_items = 0
- if expandable_limited_storage_enable == 0 and s_type == "get" then
- return true
- elseif expandable_limited_storage_enable == 1 and s_type == "get" then
- local base_limit = base_limit_for_expandable_storage + mb_igshop.get_prevdata()
- local caracters = mb_igshop.get_account_caracters()
- for i = 1, table.getn(caracters) do
- if io.open(igshop_path.."data/"..caracters[i].."/itemlist.txt", "r") != nil then -- ellenőrzi, hogy az aktuális karakternek van e itemlist.txt fájlja, ez azért kell, hogy legyen egyáltalán mit megnyitni, és ne errorozzon
- current_items = table.getn(mb_igshop.get_itemsfromowner(caracters[i])) + current_items -- hozzáadja az aktuális karakter itemlist.txt-ben szerepő tárgyak számát a fent említett változó értékéhez
- end
- end
- if base_limit <= current_items then return false end
- return true
- elseif string.find(tostring(s_type), "set") != nil then
- local a = split_(s_type, "|")
- local old = mb_igshop.get_prevdata()
- local open = io.open(igshop_path.."accids/"..pc.get_account_id().."/storage_limit.txt", "w+")
- open:write(old+tonumber(a[2]))
- open:flush()
- open:close()
- end
- end
- function igshop_gold_manager(what, vnum, count, cell)
- local gold_items = {}
- for i = 1, table.getn(igshop_gold_items) do
- table.insert(gold_items, {})
- table.insert(gold_items[table.getn(gold_items)], igshop_gold_items[i][1])
- table.insert(gold_items[table.getn(gold_items)], igshop_gold_items[i][2])
- table.insert(gold_items[table.getn(gold_items)], igshop_gold_items[i][3])
- end
- if what == "put_in" then
- for i = 1, table.getn(gold_items) do
- if gold_items[i][1] == vnum then
- mb_igshop.set_gold(pc.get_account_id(), gold_items[i][2]*count)
- for i = 1, count do item.select_cell(cell) item.remove() end
- return true
- end
- end
- return false
- elseif what == "get_out" then
- table.sort(gold_items, function(i,v) return i[2]>v[2] end)
- local money = vnum
- local base_money = vnum
- local gold = mb_igshop.get_gold(pc.get_account_id())
- if money > gold then
- syschat(loadLang(37))
- return (-1)
- end
- local temp_money = 0
- local id = pc.get_account_id()
- for i = 1, table.getn(gold_items) do
- if money >= gold_items[i][2] then
- local calculated = math.floor(money / gold_items[i][2])
- gold_items[i][3] = calculated + gold_items[i][3]
- money = money - gold_items[i][2] * calculated
- end
- end
- local append_antiflag = {}
- for i = 1, table.getn(gold_items) do
- if gold_items[i][3] > 0 then
- append_antiflag = mb_igshop.check_antiflag(gold_items[i][1], true)
- for x = 1, table.getn(append_antiflag) do
- if append_antiflag[x] == 32768 then
- table.insert(gold_items[i], 4, false)
- break
- end
- end
- local mItemFlag = game.mysql_query("SELECT flag FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = "..gold_items[i][1].." LIMIT 1")
- local rItemFlag = tonumber(mItemFlag[1][1])
- local fItemFlag = {}
- table.foreach(igshop_flag_table, function(_, v) if rItemFlag >= v then table.insert(fItemFlag, v) rItemFlag = rItemFlag - v end end)
- if table.getn(gold_items[i]) != 4 then
- table.foreachi(fItemFlag, function (pos, val) if val == 4 then table.insert(gold_items[i], 4, true) end end)
- if table.getn(gold_items[i]) != 4 then
- table.insert(gold_items[i], 4, false)
- end
- end
- if gold_items[i][4] then
- while (gold_items[i][3] > 0) do
- if pc.get_empty_inventory_count() < 1 then return (base_money - temp_money) end
- if gold_items[i][3] > 999 then
- temp_money = temp_money + 999 * gold_items[i][2]
- pc.give_item2(gold_items[i][1], 999)
- gold_items[i][3] = gold_items[i][3] - 999
- else
- temp_money = temp_money + gold_items[i][3] * gold_items[i][2]
- pc.give_item2(gold_items[i][1], gold_items[i][3])
- gold_items[i][3] = 0
- end
- end
- else
- while (gold_items[i][3] > 0) do
- if pc.get_empty_inventory_count() < 1 then return (base_money - temp_money) end
- temp_money = temp_money + gold_items[i][2]
- pc.give_item2(gold_items[i][1], 1)
- gold_items[i][3] = gold_items[i][3] - 1
- end
- end
- end
- end
- if 50000000000 < pc.get_gold()+money then return (base_money - temp_money) end
- pc.changemoney(money)
- temp_money = temp_money + money
- money = 0
- return (base_money - temp_money)
- end
- end
- function can_change_name(playerName)
- local tab = mb_igshop.get_itemsfromowner(playerName)
- if table.getn(tab) > 0 then return false end
- local tab2 = {}
- local mOpen = io.open(igshop_path.."data/"..playerName.."/trade_data_list.txt", "r")
- if mOpen != nil then
- for i in mOpen:lines() do
- table.insert(tab2, i)
- end
- if table.getn(tab2) > 0 then return false end
- end
- local tab2 = {}
- local mOpen = io.open(igshop_path.."data/"..playerName.."/boughtitems.txt", "r")
- if mOpen != nil then
- for i in mOpen:lines() do
- table.insert(tab2, i)
- end
- if table.getn(tab2) > 0 then return false end
- end
- return true
- end
- function expand_storage()
- if not igshop_enable_storage_expand then return end
- if item.get_vnum() <= 0 then return end
- for i = 1, table.getn(igshop_storage_expand_table) do
- if vnum == igshop_storage_expand_table[i][1] then
- mb_igshop.expandable_limited_storage("set|"..igshop_storage_expand_table[i][2])
- item.remove()
- break
- end
- end
- end
- function openallrecord()
- local records = {}
- local file = io.open(igshop_path.."data/Fegyverek.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Egyebek.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Vertek.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Cipok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Karkotok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Pajzsok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Fulbevalok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Kosztumok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Nyaklancok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- file = io.open(igshop_path.."data/Sisakok.txt", "r")
- for items in file:lines() do
- table.insert(records, items)
- end
- file:close()
- return records or 0
- end
- function searchItem(oname, iname, page, ftype)
- local data = {}
- local tempdata1, tempdata2, tempdata3, tempdata4, tempdata5, tempdata6, tempdata7, tempdata8, tempdata9, tempdata10 = {}
- local object = mb_igshop.get_itemdata()
- local itemIDs = {}
- local gtype
- if string.len(iname) < 2 and oname == "" then syschat(loadLang(26)) return end
- if iname != "" then
- for i = 1, table.getn(object) do
- if string.find(string.lower(tostring(item_name(tonumber(object[i])))), tostring(iname)) != nil then
- table.insert(itemIDs, tonumber(object[i]))
- end
- end
- if table.getn(itemIDs) < 1 then syschat(loadLang(27)) syschat(string.gsub(iname,"%%","").." ") return end
- end
- if oname != "" then
- data = mb_igshop.get_itemsfromowner(oname)
- if table.getn(data) < 1 then syschat(loadLang(38)) return end
- else
- data = mb_igshop.openallrecord()
- if table.getn(data) < 1 then syschat(loadLang(39)) return end
- end
- local records = {}
- local items = {}
- for i = 1, table.getn(data) do
- table.insert(items, split_(data[i], "#"))
- end
- if iname != "" then
- for i = 1, table.getn(data) do
- for x = 1, table.getn(itemIDs) do
- if tonumber(items[i][2]) == itemIDs[x] then
- table.insert(records, data[i])
- end
- end
- end
- else
- records = data
- end
- if table.getn(records) < 1 then syschat(loadLang(40)) return end
- mb_igshop.refresh_pages(records)
- if page > tonumber(pc.getqf("pages")) then page = tonumber(pc.getqf("pages")) end
- if ftype == 1 then
- mb_igshop.add_items(tonumber(pc.getqf("pages")), page, records, tonumber(pc.getqf("itemsOnLastPage")), "SpecS")
- cmdchat("IGSHOP MANAGEPAGES/"..tonumber(pc.getqf("pages")).."/"..page)
- cmdchat("IGSHOP SETGOLD/"..mb_igshop.get_gold(pc.get_account_id()))
- cmdchat("IGSHOP SETCASH/"..get_coins())
- else
- return records or 0
- end
- end
- function ClaimItem(id, page, slot)
- local data = mb_igshop.get_myboughtitems()
- if table.getn(data) > 0 then
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then
- syschat(loadLang(41))
- else
- local itema = split_(data[((page-1)*5)+slot],"#")
- if tonumber(itema[1]) != id then
- syschat(loadLang(41))
- else
- if pc.get_empty_inventory_count() < 3 then syschat(loadLang(42)) return end
- if not pc.give_item_with(tonumber(itema[2]), tonumber(itema[3]), itema[13], itema[14], itema[15], itema[16], itema[17], itema[18], itema[19], itema[20], itema[21], itema[22], itema[23], itema[24], itema[25], itema[26], itema[26], itema[27], itema[7], itema[8], itema[9], itema[10]) then syschat("<Kereskedőház> Nem sikerült átvenni a tárgyat!") end
- mb_igshop.RemoveAfterClaim(tostring(pc.get_name()), id, 1, 1)
- cmdchat("IGSHOP REFRESHAFTERBUY")
- syschat(loadLang(43))
- end
- end
- else
- syschat(loadLang(41))
- end
- end
- function ClaimMyItem(id, page, slot)
- local data = mb_igshop.get_myitems()
- if table.getn(data) > 0 then
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then
- syschat(loadLang(44))
- else
- local itema = split_(data[((page-1)*5)+slot],"#")
- if tonumber(itema[1]) != id then
- syschat(loadLang(44))
- else
- if pc.get_empty_inventory_count() < 3 then syschat(loadLang(42)) return end
- if not pc.give_item_with(tonumber(itema[2]), tonumber(itema[3]), itema[13], itema[14], itema[15], itema[16], itema[17], itema[18], itema[19], itema[20], itema[21], itema[22], itema[23], itema[24], itema[25], itema[26], itema[27], itema[28], itema[7], itema[8], itema[9], itema[10]) then syschat("<Kereskedőház> Nem sikerült átvenni a tárgyat!") end
- local iType = mb_igshop.get_type(itema[2])
- local iSubType = mb_igshop.get_sub_type(itema[2])
- local gtype = ""
- if iType == 1 and iSubType != 6 then
- gtype = "Fegyverek"
- elseif iType == 2 and iSubType == 0 then
- gtype = "Vertek"
- elseif iType == 2 and iSubType == 1 then
- gtype = "Sisakok"
- elseif iType == 2 and iSubType == 2 then
- gtype = "Pajzsok"
- elseif iType == 2 and iSubType == 3 then
- gtype = "Karkotok"
- elseif iType == 2 and iSubType == 4 then
- gtype = "Cipok"
- elseif iType == 2 and iSubType == 5 then
- gtype = "Nyaklancok"
- elseif iType == 2 and iSubType == 6 then
- gtype = "Fulbevalok"
- elseif iType == 28 then
- gtype = "Kosztumok"
- else
- gtype = "Egyebek"
- end
- mb_igshop.ItemRemoveFromGTxt(gtype, id)
- mb_igshop.ItemRemoveFromOwnerTxt(tostring(pc.get_name()), id, 1, 1)
- if mb_igshop.IsTradeItem(tonumber(id)) then os.remove(igshop_path.."tradedata/"..id..".txt") end
- cmdchat("IGSHOP REFRESHAFTERBUY")
- syschat(loadLang(45))
- end
- end
- else
- syschat(loadLang(46))
- end
- end
- function BuyItem(id, buytype, page, slot, count, money, group)
- if math.floor(count) != count then syschat(loadLang(47)) return end
- local data
- if group == "Kereses" then
- local file = io.open(igshop_path.."data/"..pc.get_name().."/search.txt", "r")
- local tbl = {}
- for item in file:lines() do
- table.insert(tbl, split_(item, "#"))
- end
- file:close()
- data = mb_igshop.searchItem(tbl[1][1],tbl[1][2], page, 2)
- else
- data = mb_igshop.get_items(group)
- end
- if table.getn(data) > 0 then
- mb_igshop.refresh_pages(data)
- if tonumber(pc.getqf("pages")) < page then
- syschat(loadLang(15))
- else
- local item = split_(data[((page-1)*5)+slot],"#")
- if tonumber(item[1]) != id then
- syschat(loadLang(15))
- else
- if buytype == "CASH" then
- if money < tonumber(item[5])*count then
- cmdchat("IGSHOP SETCASH/"..money)
- syschat(loadLang(48))
- else
- if count > tonumber(item[3]) then
- syschat(loadLang(49)..tonumber(item[3])..loadLangOnly(50))
- elseif count > 0 then
- if igshopEnableTrade then
- if mb_igshop.IsTradeItem(id) == 1 then count = tonumber(item[3]) end
- end
- set_coins(money - tonumber(item[5])*count)
- mb_igshop.set_coins_accid(tonumber(item[5])*count, tonumber(item[27]))
- mb_igshop.GiveItemToTxt(tostring(data[((page-1)*5)+slot]), count, tonumber(item[3]))
- mb_igshop.ItemRemoveFromGroupTxt(group, data, ((page-1)*5)+slot, count, tonumber(item[3]))
- mb_igshop.ItemRemoveFromOwnerTxt(tostring(item[4]), id, count, tonumber(item[3]))
- cmdchat("IGSHOP REFRESHAFTERBUY")
- syschat(loadLang(51))
- end
- end
- else
- if money < tonumber(item[6])*count then
- cmdchat("IGSHOP SETGOLD/"..money)
- syschat(loadLang(52))
- else
- if count > tonumber(item[3]) then
- syschat(loadLang(49)..tonumber(item[3])..loadLangOnly(50))
- elseif count > 0 then
- if igshopEnableTrade then
- if mb_igshop.IsTradeItem(id) == 1 then count = tonumber(item[3]) end
- end
- mb_igshop.GiveItemToTxt(tostring(data[((page-1)*5)+slot]), count, tonumber(item[3]))
- mb_igshop.ItemRemoveFromGroupTxt(group, data, ((page-1)*5)+slot, count, tonumber(item[3]))
- mb_igshop.ItemRemoveFromOwnerTxt(tostring(item[4]), id, count, tonumber(item[3]))
- cmdchat("IGSHOP REFRESHAFTERBUY")
- mb_igshop.set_gold(tonumber(item[27]), tonumber(item[6]*count))
- mb_igshop.set_gold(pc.get_account_id(), 0 - tonumber(item[6])*count)
- syschat(loadLang(51))
- end
- end
- end
- end
- end
- else
- syschat(loadLang(15))
- end
- end
- function get_type(vnum)
- if string.find(vnum, ";") == nil and string.find(vnum, " ") == nil then
- local tbl = 0
- local query = game.mysql_query("SELECT type FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..vnum.."' LIMIT 1")
- tbl = tonumber(query[1][1])
- return tbl
- else
- syschat("mb_igshop Error->potential_sql_inject_string#2")
- return 0
- end
- end
- function get_sub_type(vnum)
- if string.find(vnum, ";") == nil and string.find(vnum, " ") == nil then
- local tbl = 0
- local query = game.mysql_query("SELECT subtype FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..vnum.."' LIMIT 1")
- tbl = tonumber(query[1][1])
- return tbl
- else
- syschat("mb_igshop Error->potential_sql_inject_string#3")
- return false
- end
- end
- function get_flag(vnum)
- if string.find(vnum, ";") == nil and string.find(vnum, " ") == nil then
- local tbl = 0
- local query = game.mysql_query("SELECT flag FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name.." WHERE vnum = '"..vnum.."' LIMIT 1")
- tbl = tonumber(query[1][1])
- return tbl
- else
- syschat("mb_igshop Error->potential_sql_inject_string#4")
- return false
- end
- end
- function ItemRemoveFromGroupTxt(group, data, line, count, all)
- local items = {}
- for i = 1 , table.getn(data) do
- table.insert(items,split_(data[i],"#"))
- end
- local id = tonumber(items[line][1])
- if group == "Kereses" then
- local iType = mb_igshop.get_type(tonumber(items[line][2]))
- local iSubType = mb_igshop.get_sub_type(tonumber(items[line][2]))
- local gtype = ""
- if iType == 1 and iSubType != 6 then
- gtype = "Fegyverek"
- elseif iType == 2 and iSubType == 0 then
- gtype = "Vertek"
- elseif iType == 2 and iSubType == 1 then
- gtype = "Sisakok"
- elseif iType == 2 and iSubType == 2 then
- gtype = "Pajzsok"
- elseif iType == 2 and iSubType == 3 then
- gtype = "Karkotok"
- elseif iType == 2 and iSubType == 4 then
- gtype = "Cipok"
- elseif iType == 2 and iSubType == 5 then
- gtype = "Nyaklancok"
- elseif iType == 2 and iSubType == 6 then
- gtype = "Fulbevalok"
- elseif iType == 28 then
- gtype = "Kosztumok"
- else
- gtype = "Egyebek"
- end
- items = {}
- group = gtype
- data = mb_igshop.get_items(gtype)
- for i = 1 , table.getn(data) do
- table.insert(items,split_(data[i],"#"))
- end
- for i = 1, table.getn(items) do
- if tonumber(items[i][1]) == id then
- if all > 1 and all != count then
- local oldcount = tonumber(items[i][3])
- items[i][3] = tostring(oldcount - count)
- else
- table.remove(items, i)
- end
- break
- end
- end
- else
- if all > 1 and all != count then
- local oldcount = tonumber(items[line][3])
- items[line][3] = tostring(oldcount - count)
- else
- table.remove(items, line)
- end
- end
- local open = io.open(igshop_path.."data/"..group..".txt", "w+")
- for i = 1, table.getn(items) do
- open:write(items[i][1]..'#'..items[i][2]..'#'..items[i][3]..'#'..items[i][4]..'#'..items[i][5]..'#'..items[i][6]..'#'..items[i][7]..'#'..items[i][8]..'#'..items[i][9]..'#'..items[i][10]..'#'..items[i][11]..'#'..items[i][12]..'#'..items[i][13]..'#'..items[i][14]..'#'..items[i][15]..'#'..items[i][16]..'#'..items[i][17]..'#'..items[i][18]..'#'..items[i][19]..'#'..items[i][20]..'#'..items[i][21]..'#'..items[i][22]..'#'..items[i][23]..'#'..items[i][24]..'#'..items[i][25]..'#'..items[i][26]..'#'..items[i][27]..'#'..items[i][28]..'#'..items[i][29]..'#'..items[i][30]..'\\n')
- end
- open:flush()
- open:close()
- end
- function ItemRemoveFromGTxt(group, id)
- local data = mb_igshop.get_items(group)
- local open = io.open(igshop_path.."data/"..group..".txt", "w+")
- local items = {}
- for i = 1 , table.getn(data) do
- table.insert(items,split_(data[i],"#"))
- end
- for i = 1, table.getn(items) do
- if tonumber(items[i][1]) == id then
- table.remove(items, i)
- break
- end
- end
- for i = 1, table.getn(items) do
- open:write(items[i][1]..'#'..items[i][2]..'#'..items[i][3]..'#'..items[i][4]..'#'..items[i][5]..'#'..items[i][6]..'#'..items[i][7]..'#'..items[i][8]..'#'..items[i][9]..'#'..items[i][10]..'#'..items[i][11]..'#'..items[i][12]..'#'..items[i][13]..'#'..items[i][14]..'#'..items[i][15]..'#'..items[i][16]..'#'..items[i][17]..'#'..items[i][18]..'#'..items[i][19]..'#'..items[i][20]..'#'..items[i][21]..'#'..items[i][22]..'#'..items[i][23]..'#'..items[i][24]..'#'..items[i][25]..'#'..items[i][26]..'#'..items[i][27]..'#'..items[i][28]..'#'..items[i][29]..'#'..items[i][30]..'\\n')
- end
- open:flush()
- open:close()
- end
- function RemoveAfterClaim(owner, id, count, all)
- local data = mb_igshop.get_myboughtitems()
- local open = io.open(igshop_path.."data/"..owner.."/boughtitems.txt", "w+")
- local items = {}
- for i = 1 , table.getn(data) do
- table.insert(items,split_(data[i],"#"))
- end
- for i = 1, table.getn(items) do
- if tonumber(items[i][1]) == id then
- if all > 1 and all != count then
- local oldcount = tonumber(items[i][3])
- items[i][3] = tostring(oldcount - count)
- else
- table.remove(items, i)
- end
- break
- end
- end
- for i = 1, table.getn(items) do
- open:write(items[i][1]..'#'..items[i][2]..'#'..items[i][3]..'#'..items[i][4]..'#'..items[i][5]..'#'..items[i][6]..'#'..items[i][7]..'#'..items[i][8]..'#'..items[i][9]..'#'..items[i][10]..'#'..items[i][11]..'#'..items[i][12]..'#'..items[i][13]..'#'..items[i][14]..'#'..items[i][15]..'#'..items[i][16]..'#'..items[i][17]..'#'..items[i][18]..'#'..items[i][19]..'#'..items[i][20]..'#'..items[i][21]..'#'..items[i][22]..'#'..items[i][23]..'#'..items[i][24]..'#'..items[i][25]..'#'..items[i][26]..'#'..items[i][27]..'#'..items[i][28]..'#'..items[i][29]..'#'..items[i][30]..'\\n')
- end
- open:flush()
- open:close()
- end
- function ItemRemoveFromOwnerTxt(owner, id, count, all)
- local data = mb_igshop.get_itemsfromowner(owner)
- local items = {}
- for i = 1 , table.getn(data) do
- table.insert(items,split_(data[i],"#"))
- end
- for i = 1, table.getn(items) do
- if tonumber(items[i][1]) == id then
- if all > 1 and all != count then
- local oldcount = tonumber(items[i][3])
- items[i][3] = tostring(oldcount - count)
- else
- table.remove(items, i)
- end
- break
- end
- end
- local open = io.open(igshop_path.."data/"..owner.."/itemlist.txt", "w+")
- for i = 1, table.getn(items) do
- open:write(items[i][1]..'#'..items[i][2]..'#'..items[i][3]..'#'..items[i][4]..'#'..items[i][5]..'#'..items[i][6]..'#'..items[i][7]..'#'..items[i][8]..'#'..items[i][9]..'#'..items[i][10]..'#'..items[i][11]..'#'..items[i][12]..'#'..items[i][13]..'#'..items[i][14]..'#'..items[i][15]..'#'..items[i][16]..'#'..items[i][17]..'#'..items[i][18]..'#'..items[i][19]..'#'..items[i][20]..'#'..items[i][21]..'#'..items[i][22]..'#'..items[i][23]..'#'..items[i][24]..'#'..items[i][25]..'#'..items[i][26]..'#'..items[i][27]..'#'..items[i][28]..'#'..items[i][29]..'#'..items[i][30]..'\\n')
- end
- open:flush()
- open:close()
- end
- function GiveItemToTxt(data, count, all)
- if all >= 1 then
- local items = {}
- table.insert(items,split_(data,"#"))
- local myitemsTable = {}
- local myitems = mb_igshop.get_myboughtitems()
- for i = 1, table.getn(myitems) do
- table.insert(myitemsTable, split_(myitems[i], "#"))
- end
- alertson = 0
- for i = 1, table.getn(myitemsTable) do
- if tonumber(myitemsTable[i][1]) == tonumber(items[1][1]) then
- myitemsTable[i][3] = tonumber(myitemsTable[i][3]) + count
- alertson = 1
- break
- end
- end
- if alertson == 0 then
- if all != count then
- local open = io.open(igshop_path.."data/"..pc.get_name().."/boughtitems.txt", "a+")
- for i = 1, table.getn(items) do
- open:write(items[i][1]..'#'..items[i][2]..'#'..count..'#'..items[i][4]..'#'..items[i][5]..'#'..items[i][6]..'#'..items[i][7]..'#'..items[i][8]..'#'..items[i][9]..'#'..items[i][10]..'#'..items[i][11]..'#'..items[i][12]..'#'..items[i][13]..'#'..items[i][14]..'#'..items[i][15]..'#'..items[i][16]..'#'..items[i][17]..'#'..items[i][18]..'#'..items[i][19]..'#'..items[i][20]..'#'..items[i][21]..'#'..items[i][22]..'#'..items[i][23]..'#'..items[i][24]..'#'..items[i][25]..'#'..items[i][26]..'#'..items[i][27]..'#'..items[i][28]..'#'..items[i][29]..'#'..items[i][30]..'\\n')
- end
- open:flush()
- open:close()
- else
- local open = io.open(igshop_path.."data/"..pc.get_name().."/boughtitems.txt", "a+")
- open:write(data.."\\n")
- open:flush()
- open:close()
- end
- else
- local open = io.open(igshop_path.."data/"..pc.get_name().."/boughtitems.txt", "w+")
- for i = 1, table.getn(myitemsTable) do
- open:write(myitemsTable[i][1]..'#'..myitemsTable[i][2]..'#'..myitemsTable[i][3]..'#'..myitemsTable[i][4]..'#'..myitemsTable[i][5]..'#'..myitemsTable[i][6]..'#'..myitemsTable[i][7]..'#'..myitemsTable[i][8]..'#'..myitemsTable[i][9]..'#'..myitemsTable[i][10]..'#'..myitemsTable[i][11]..'#'..myitemsTable[i][12]..'#'..myitemsTable[i][13]..'#'..myitemsTable[i][14]..'#'..myitemsTable[i][15]..'#'..myitemsTable[i][16]..'#'..myitemsTable[i][17]..'#'..myitemsTable[i][18]..'#'..myitemsTable[i][19]..'#'..myitemsTable[i][20]..'#'..myitemsTable[i][21]..'#'..myitemsTable[i][22]..'#'..myitemsTable[i][23]..'#'..myitemsTable[i][24]..'#'..myitemsTable[i][25]..'#'..myitemsTable[i][26]..'#'..myitemsTable[i][27]..'#'..myitemsTable[i][28]..'#'..myitemsTable[i][29]..'#'..myitemsTable[i][30]..'\\n')
- end
- open:flush()
- open:close()
- end
- end
- end
- function add_items(maxpage, page, items, itemsOnLastPage, group)
- if page <= 0 then page = 1 end
- if page > maxpage then page = maxpage end
- local from = (page - 1)*5 + 1
- local to = 0
- if maxpage > page then
- to = ((page - 1 )*5) + 5
- else
- to = ((page - 1)*5) + itemsOnLastPage
- end
- local slot = 1
- local item
- local commandL
- if group == "my_buys" then
- commandL = "IGShop_BOUGHTITEMS"
- elseif group == "my_sales" then
- commandL = "IGShop_MYSALES"
- else
- commandL = "IGShop_ITEMS"
- end
- for i = from, to do
- item = split_(items[i],"#")
- if igshopEnableTrade then
- if group == "get_trade_items" then
- cmdchat("trade.GetTradeItems "..slot.." "..item[1].." "..item[2].." "..item[3].." "..item[4].." "..item[5].." "..item[6].." "..item[7].." "..item[8].." "..item[9].." "..item[10].." "..item[11].." "..item[12].." "..item[13].." "..item[14].." "..item[15].." "..item[16].." "..item[17].." "..item[18].." "..item[19].." "..item[20].." "..item[21].." "..item[22].." "..item[23].." "..item[24].." "..item[25].." "..item[26])
- else
- cmdchat(commandL.." "..slot.." "..item[1].." "..item[2].." "..item[3].." "..item[4].." "..item[5].." "..item[6].." "..item[4+3]..' '..item[5+3]..' '..item[6+3]..' '..item[7+3]..' '..item[8+3]..' '..item[9+3]..' '..item[10+3]..' '..item[11+3]..' '..item[12+3]..' '..item[13+3]..' '..item[14+3]..' '..item[15+3]..' '..item[16+3]..' '..item[17+3]..' '..item[18+3]..' '..item[19+3]..' '..item[20+3]..' '..item[21+3]..' '..item[22+3]..' '..item[23+3]..' '..item[24+3]..' '..item[25+3]..' '..item[30]..' '..mb_igshop.IsTradeItem(item[1]))
- end
- else
- cmdchat(commandL.." "..slot.." "..item[1].." "..item[2].." "..item[3].." "..item[4].." "..item[5].." "..item[6].." "..item[4+3]..' '..item[5+3]..' '..item[6+3]..' '..item[7+3]..' '..item[8+3]..' '..item[9+3]..' '..item[10+3]..' '..item[11+3]..' '..item[12+3]..' '..item[13+3]..' '..item[14+3]..' '..item[15+3]..' '..item[16+3]..' '..item[17+3]..' '..item[18+3]..' '..item[19+3]..' '..item[20+3]..' '..item[21+3]..' '..item[22+3]..' '..item[23+3]..' '..item[24+3]..' '..item[25+3]..' '..item[30]..' -1')
- end
- -- 1. slot, 2. item id, 3. item vnum, 4. item count, 5. owner name, 6. price se, 7. price yang
- slot = slot + 1
- end
- end
- function get_items(group)
- local igshoplist = {}
- local file = io.open(igshop_path.."data/"..group..".txt", "r")
- for item in file:lines() do
- table.insert(igshoplist,item)
- end
- return igshoplist or 0
- end
- function get_itemdata()
- if igshop_itemindex_readlevel == 1 then
- local itemdata = game.mysql_query("SELECT vnum FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name)
- local retTable = {}
- for i = 1, table.getn(itemdata) do
- table.insert(retTable, tonumber(itemdata[i][1]))
- end
- return retTable
- elseif igshop_itemindex_readlevel == 2 then
- if igshop_savedVnums == nil then
- local itemdata = game.mysql_query("SELECT vnum FROM "..igshop_player_database_name.."."..igshop_player_item_proto_table_name)
- igshop_savedVnums = {}
- for i = 1, table.getn(itemdata) do
- table.insert(igshop_savedVnums, tonumber(itemdata[i][1]))
- end
- end
- return igshop_savedVnums
- else
- local itemdata = {}
- local mfile = io.open(igshop_path.."itemindex.txt", "r")
- if mfile == nil then syschat("mb_igshop Error->unable_to_read_itemindex.txt") return {} end
- for item in mfile:lines() do
- table.insert(itemdata,tonumber(item))
- end
- return itemdata or 0
- end
- end
- function get_myboughtitems()
- local igshoplist = {}
- local file = io.open(igshop_path.."data/"..pc.get_name().."/boughtitems.txt", "r")
- for item in file:lines() do
- table.insert(igshoplist,item)
- end
- return igshoplist or 0
- end
- function get_myitems()
- local igshoplist = {}
- local file = io.open(igshop_path.."data/"..pc.get_name().."/itemlist.txt", "r")
- for item in file:lines() do
- table.insert(igshoplist,item)
- end
- return igshoplist or 0
- end
- function get_itemsfromowner(owner)
- local igshoplist = {}
- local file = io.open(igshop_path.."data/"..owner.."/itemlist.txt", "r")
- if file == nil then syschat(loadLang(53)) return 0 end
- for item in file:lines() do
- table.insert(igshoplist,item)
- end
- return igshoplist or 0
- end
- when 9005.chat."Tradehouse" begin
- setskin(NOWINDOW)
- mb_igshop.OpenIgShop()
- end
- function OpenIgShop()
- if not mb_igshop.has_itemlist() then mb_igshop.make_igshop() end
- local tradeVar = 0
- if igshopEnableTrade then
- tradeVar = 1
- end
- if pc.getqf("langVar") <= 0 then pc.setqf("langVar", igshop_default_language) end
- cmdchat("IGSHOP OPEN/"..get_coins().."/"..tradeVar.."/"..pc.getqf("langVar"))
- end
- function has_itemlist()
- local igshop = io.open(igshop_path.."data/"..pc.get_name().."/itemlist.txt", "r")
- if igshop == nil then
- return false
- else
- local fix2 = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "r")
- if fix2 == nil then
- fix2 = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "w+")
- fix2:close()
- end
- local fix = io.open(igshop_path.."accids/"..pc.get_account_id().."/storage_limit.txt", "r")
- if fix == nil then
- local open2 = io.open(igshop_path.."accids/"..pc.get_account_id().."/storage_limit.txt", "w+")
- open2:write("0")
- open2:flush()
- open2:close()
- end
- return true
- end
- end
- function make_igshop()
- local igshop1 = io.open(igshop_path.."accids/"..pc.get_account_id().."/gold.txt", "r")
- if igshop1 == nil then
- os.execute("mkdir "..igshop_path.."accids/"..pc.get_account_id())
- local igshop = io.open(igshop_path.."accids/"..pc.get_account_id().."/gold.txt", "w+")
- igshop:write("0")
- igshop:flush()
- igshop:close()
- local open2 = io.open(igshop_path.."accids/"..pc.get_account_id().."/storage_limit.txt", "w+")
- open2:write("0")
- open2:flush()
- open2:close()
- end
- os.execute("mkdir "..igshop_path.."data/"..pc.get_name())
- local igshop = io.open(igshop_path.."data/"..pc.get_name().."/itemlist.txt", "w+")
- igshop:close()
- local igshop = io.open(igshop_path.."data/"..pc.get_name().."/boughtitems.txt", "w+")
- igshop:close()
- local igshop = io.open(igshop_path.."data/"..pc.get_name().."/search.txt", "w+")
- igshop:close()
- local igshop = io.open(igshop_path.."data/"..pc.get_name().."/trade_data_list.txt", "w+")
- igshop:close()
- end
- function get_gold(accid)
- local open = io.open(igshop_path.."accids/"..accid.."/gold.txt", "r")
- for line in open:lines() do
- return tonumber(line)
- end
- end
- function set_gold(accid, gold)
- local oldgold = mb_igshop.get_gold(accid)
- local open = io.open(igshop_path.."accids/"..accid.."/gold.txt", "w+")
- open:write(oldgold+gold)
- open:flush()
- open:close()
- end
- function set_coins_accid(coins, id)
- if string.find(coins, ";") == nil and string.find(coins, " ") == nil and string.find(id, ";") == nil and string.find(id, " ") == nil then
- game.mysql_query("UPDATE "..igshop_account_database_name.."."..igshop_account_table_name.." SET "..igshop_coins_column_name.." = "..igshop_coins_column_name.." + "..tonumber(coins).." WHERE id = "..tonumber(id)..";")
- else
- syschat("mb_igshop Error->potential_sql_inject_string#5")
- end
- return
- end
- function refresh_pages(get)
- local lines = table.getn(get)
- local formated = math.floor(lines/5)
- if formated != lines/5 then
- pc.setqf("pages",formated + 1)
- local tempiOLP = lines - formated * 5
- if formated < 1 then tempiOLP = lines end
- pc.setqf("itemsOnLastPage",tempiOLP)
- else
- pc.setqf("pages",lines/5)
- pc.setqf("itemsOnLastPage",5)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement