Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- |---------------------------------------------------------------------------------------|
- | __________ _____ |
- | \______ \_______ ____ _/ ____\ ____ ______ ______ ____ _______ |
- | | ___/\_ __ \ / _ \\ __\_/ __ \ / ___/ / ___// _ \\_ __ \ |
- | | | | | \/( <_> )| | \ ___/ \___ \ \___ \( <_> )| | \/ |
- | |____| |__| \____/ |__| \___ >/____ >/____ >\____/ |__| |
- | \/ \/ \/ |
- | ___________ __ |
- | \_ _____/ ____ _/ |_ ____ |
- | | __)_ / \\ __\_/ __ \ |
- | | \| | \| | \ ___/ |
- | /_______ /|___| /|__| \___ > |
- | \/ \/ \/ |
- |---------------------------------------------------------------------------------------|
- ]]
- quest guildstorage begin
- state start begin
- when login begin
- cmdchat("GUILDSTORAGE QID/"..q.getcurrentquestindex())
- pc.setqf('login',get_time()+15)
- end
- when 9005.chat. "Magazyn Gildii" begin
- setskin(NOWINDOW)
- guildstorage.open_gs()
- end
- function open_gs()
- if pc.getqf('login') >= get_time() then syschat'Nie możesz używać magazynu gildii przez 15 sekund.' return end --NEU 06.07.2014
- if game.get_event_flag('gildenlager') == 0 then syschat'Magazyn Gildii jest wyłączony.' return end
- if not pc.has_guild() then syschat'Musisz posiadać gildię żeby korzystać z magazynu.' setskin(NOWINDOW) return end
- if not guildstorage.has_guildstorage() then guildstorage.create_guildstorage() end
- if pc.is_polymorphed() then syschat'Nie możesz być przemieniony.' return end -- NEW
- if pc.is_guild_master() then
- cmdchat('GUILDSTORAGE OPEN/1')
- else
- cmdchat('GUILDSTORAGE OPEN/0')
- end
- guildstorage.refresh()
- pc.setqf("GUILDSTORAGE",1)
- end
- when button begin
- if game.get_event_flag('gildenlager') == 0 then syschat'Magazyn Gildii jest wyłączony.' return end
- local cmd = guildstorage.client_command(getinput("GUILDSTORAGE QUESTCMD"))
- if pc.is_polymorphed() and cmd[1] != 'UPDATE' then syschat'Nie możesz być przemieniony.' return end -- NEW
- -- [ITEM]
- if cmd[1] == 'TAKE_ITEM' then
- if not guildstorage.get_authority(1) then syschat'Nie masz praw.' return end
- -- if pc.get_empty_inventory_count() < 3 then syschat'Nie masz wystarczająco dużo miejsca.' return end
- local slot = tonumber(cmd[2])+120*tonumber(cmd[3])
- local item = guildstorage.get_slot_item(slot)
- if not pc.enough_inventory(item[1]) then syschat'Nie masz wystarczająco dużo miejsca.' return end
- if guildstorage.slot_empty(slot) then syschat'Ten element jest już umieszczony.' return end
- if game.get_event_flag('GUILDS_USE_'..pc.get_guild()) == 1 then syschat'Błąd #101' return end
- guildstorage.remove_item(slot)
- guildstorage.give_item(item)
- elseif cmd[1] == 'MOVE_ITEM' then
- item.select_cell(tonumber(cmd[3]))
- if not guildstorage.get_authority(0) then syschat'Nie masz uprawnień. ' return end
- --possible to store the item? antiflag/flag
- if cmd[2] == 'INVENTORY' then
- if not guildstorage.slot_empty(tonumber(cmd[4])+120*tonumber(cmd[5])) then syschat'Ten slot jest zajęty.' return end
- guildstorage.insert_item(tonumber(cmd[3]),tonumber(cmd[4]),tonumber(cmd[5]))
- elseif cmd[2] == 'GUILDSTORAGE' then
- if not guildstorage.slot_empty(tonumber(cmd[5])+120*tonumber(cmd[6])) then syschat'Ten slot jest zajęty lub przedmiot nie istnieje.' return end
- guildstorage.move_item(tonumber(cmd[3])+120*tonumber(cmd[4]),tonumber(cmd[5])+120*tonumber(cmd[6]))
- end
- -- [MONEY]
- elseif cmd[1] == 'TAKE_MONEY' then
- if not guildstorage.get_authority(3) then syschat'Nie masz praw.' return end
- local old_money = guildstorage.get_money()
- if old_money < tonumber(cmd[2]) then syschat'Nie ma tyle Yang.' return end
- local new_money = tonumber(cmd[2])
- if new_money < 0 then return end
- if new_money+pc.get_money() >= 1999999999 then syschat'Nie możesz posiadać 2.000.000.000 Yang.' return end
- guildstorage.change_money(-new_money)
- pc.change_money(new_money)
- guildstorage.add_log(pc.get_name(),'Yang','wypłata',new_money)
- cmdchat('GUILDSTORAGE REFRESH_MONEY/'..(old_money-new_money))
- elseif cmd[1] == 'GIVE_MONEY' then
- if not guildstorage.get_authority(2) then syschat'Nie masz praw.' return end
- local old_money = guildstorage.get_money()
- local new_money = tonumber(cmd[2])
- if new_money < 0 then return end
- if new_money > pc.get_money() then syschat'Nie ma tyle Yang.' return end
- pc.change_money(-new_money)
- guildstorage.change_money(new_money)
- guildstorage.add_log(pc.get_name(),'Yang','wpłata',new_money)
- cmdchat('GUILDSTORAGE REFRESH_MONEY/'..(old_money+new_money))
- -- [MEMBER]
- elseif cmd[1] == 'ADD_MEMBER' then
- if not pc.is_guild_master() then syschat'Nie jesteś liderem.' return end
- local members = guildstorage.get_members()
- if table.getn(members) >= 12 then syschat'Możesz wprowadzić maksymalnie 12 członków.' return end
- guildstorage.add_member(cmd[2])
- cmdchat('GUILDSTORAGE MEMBER_COMPLETE')
- elseif cmd[1] == 'DELETE_MEMBER' then
- if not pc.is_guild_master() then syschat'Nie jesteś liderem.' return end
- guildstorage.delete_member(cmd[2])
- cmdchat('GUILDSTORAGE MEMBER_COMPLETE')
- elseif cmd[1] == 'AUTHORITY' then
- if not pc.is_guild_master() then syschat'Nie jesteś liderem.' return end
- guildstorage.set_authority(cmd[2],tonumber(cmd[3]),cmd[4])
- local members = guildstorage.get_members()
- for i = 1, table.getn(members) do
- -- id, membername, authority 1-4
- cmdchat('GUILDSTORAGE_ADDMEMBER '..(i-1)..' '..members[i][1]..' '..members[i][2]..' '..members[i][3]..' '..members[i][4]..' '..members[i][5])
- end
- elseif cmd[1] == 'GETMEMBERLIST' then
- if not pc.is_guild_master() then syschat'Nie jesteś liderem.' return end
- local members = guildstorage.get_members()
- for i = 1, table.getn(members) do
- -- id, membername, authority 1-4
- cmdchat('GUILDSTORAGE_ADDMEMBER '..(i-1)..' '..members[i][1]..' '..members[i][2]..' '..members[i][3]..' '..members[i][4]..' '..members[i][5])
- end
- cmdchat('GUILDSTORAGE REFRESH_MEMBERS')
- elseif cmd[1] == 'UPDATE' then
- guildstorage.refresh_tempslots()
- elseif cmd[1] == 'OPEN' then
- guildstorage.open_gs()
- elseif cmd[1] == 'LOAD_LOGS' then
- if not pc.is_guild_master() then syschat'Nie jesteś liderem.' return end
- local logs = guildstorage.load_logs()
- local logsLen = table.getn(logs)
- for i = 0, logsLen-1 do
- local var = (logsLen-i)
- cmdchat('GUILDSTORAGE_ADDLOG '..(var-1)..' '..logs[var][1]..' '..logs[var][2]..' '..logs[var][3]..' '..logs[var][4]..' '..logs[var][5])
- end
- elseif cmd[1] == 'DELETE_LOGS' then
- if not pc.is_guild_master() then syschat'Nie jesteś liderem.' return end
- guildstorage.clear_logs()
- end
- end
- function item_can_store(itemvnum)
- local antiflags = guildstorage.item_get_real_antiflags(guildstorage.item_antiflag(itemvnum))
- local blackListItem = {50821,50822,50823,50824,50825,50826,51002}
- for i = 1, table.getn(blackListItem) do
- if blackListItem[i] == itemvnum then
- return false
- end
- end
- for i = 1 , table.getn(antiflags) do
- if antiflags[i] == 128 or antiflags[i] == 131072 or antiflags[i] == 8192 or antiflags[i] == 64 then return false end
- -- Wenn das item die Antiflag hat wird es nicht eingelagert.
- end
- return true
- end
- function item_get_real_antiflags(antiflag_)
- antiflags = {131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1}
- tab2 = {}
- table.foreach(antiflags,function(_,v) if antiflag_ >= v then table.insert(tab2,v) antiflag_ = antiflag_ - v end end)
- return tab2
- end
- function item_antiflag(item_vnum)
- local result = mysql_query("SELECT antiflag from player.item_proto where vnum = "..item_vnum..";")
- return tonumber(result.antiflag[1])
- end
- ----------------------
- --LOGS START
- ----------------------
- function load_logs()
- local logs = {}
- local gs_logs = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/logs.txt", "r")
- for line in gs_logs:lines() do
- table.insert(logs,guildstorage.split_(line,"#"))
- end
- return logs
- end
- function clear_logs()
- local gs_log = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/logs.txt", "w+")
- gs_log:flush()
- gs_log:close()
- end
- function add_log(name_,type_,do_,desc_)
- local gs_logs = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/logs.txt", "r")
- local lineCount = 0
- for line in gs_logs:lines() do
- lineCount = lineCount + 1
- end
- if lineCount >= 1000 then
- local gs_log = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/logs.txt", "w+")
- gs_log:flush()
- gs_log:close()
- end
- local gs_log = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/logs.txt", "a+")
- local date_ = os.date()
- date_ = string.gsub(date_," ", "+-+")
- desc_ = string.gsub(desc_," ", "+-+")
- gs_log:write(name_..'#'..date_..'#'..type_..'#'..do_..'#'..desc_..'\\n')
- gs_log:flush()
- gs_log:close()
- end
- ----------------------
- --LOGS END
- ----------------------
- ----------------------
- --MEMBER & AUTHORITY START
- ----------------------
- -- Auth 0 = einlagern
- -- Auth 1 = rausnehmen
- -- Auth 2 = einzahlen
- -- Auth 3 = auszahlen
- function get_members()
- local members = {}
- local gs_member = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/authority.txt", "r")
- for line in gs_member:lines() do
- table.insert(members,guildstorage.split_(line,"#"))
- end
- return members
- end
- function get_authority(authID)
- if pc.is_guild_master() then return true end
- local members = guildstorage.get_members()
- for i = 1, table.getn(members) do
- if members[i][1] == pc.get_name() then
- if tonumber(members[i][authID+2]) == 0 then return false else return true end
- end
- end
- return false
- end
- function set_authority(member,authID,auth)
- local members = guildstorage.get_members()
- for i = 1, table.getn(members) do
- if members[i][1] == member then
- members[i][authID+2] = auth
- break
- end
- end
- local gs_member = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/authority.txt", "w+")
- for i = 1, table.getn(members) do
- gs_member:write(members[i][1]..'#'..members[i][2]..'#'..members[i][3]..'#'..members[i][4]..'#'..members[i][5]..'\\n')
- end
- gs_member:flush()
- gs_member:close()
- end
- function add_member(member)
- local members = guildstorage.get_members()
- for i = 1, table.getn(members) do
- if members[i][1] == member then
- syschat'Member ist schon eingetragen.'
- return
- end
- end
- local gs_member = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/authority.txt", "a+")
- gs_member:write(member..'#0#0#0#0\\n')
- gs_member:flush()
- gs_member:close()
- end
- function delete_member(member)
- local members = guildstorage.get_members()
- for i = 1, table.getn(members) do
- if members[i][1] == member then
- table.remove(members,i)
- break
- end
- end
- local gs_member = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/authority.txt", "w+")
- for i = 1, table.getn(members) do
- gs_member:write(members[i][1]..'#'..members[i][2]..'#'..members[i][3]..'#'..members[i][4]..'#'..members[i][5]..'\\n')
- end
- gs_member:flush()
- gs_member:close()
- end
- ----------------------
- --MEMBER & AUTHORITY END
- ----------------------
- ----------------------
- --MONEY START
- ----------------------
- function get_money()
- local gs_money = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/money.txt", "r")
- for line in gs_money:lines() do
- return tonumber(line)
- end
- end
- function change_money(money)
- local old_money = guildstorage.get_money()
- local gs_money = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/money.txt", "w+")
- gs_money:write(old_money+money)
- gs_money:flush()
- gs_money:close()
- end
- ----------------------
- --MONEY END
- ----------------------
- ----------------------
- --STORAGE START
- ----------------------
- function has_guildstorage()
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/storage.txt", "r")
- if guildstorage == nil then
- return false
- else
- return true
- end
- end
- function give_item(itemTab)
- pc.give_item2_select(itemTab[1],itemTab[2])
- local attr,socket = {},{}
- for i = 10,23 do table.insert(attr,{itemTab[i],itemTab[i+1]}) i = i+1 end
- for i = 4,6 do table.insert(socket,itemTab[i]) end
- for i = 1, table.getn(attr) do
- item.set_value(i-1, attr[i][1], attr[i][2])
- end
- for i = 1, table.getn(socket) do if tonumber(socket[i]) > 0 then item.set_socket(i-1, socket[i]) end end
- game.set_event_flag('GUILDS_USE_'..pc.get_guild(),0)
- end
- function get_slot_item(slot)
- local items = guildstorage.get_items()
- for i = 1, table.getn(items) do
- local item = guildstorage.split_(items[i],"#")
- if tonumber(item[3]) == slot then
- return item
- end
- end
- return 0
- end
- function refresh()
- cmdchat('GUILDSTORAGE REFRESH_MONEY/'..guildstorage.get_money())
- local items = guildstorage.get_items()
- if items != 0 then
- for i = 1, table.getn(items) do
- local item = guildstorage.split_(items[i],"#")
- -- chat(table.getn(item))
- cmdchat('GUILDSTORAGE_ADDITEM '..item[3]..' '..item[1]..' '..item[2]..' '..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])
- end
- end
- cmdchat('GUILDSTORAGE REFRESH')
- end
- function refresh_tempslots()
- cmdchat('GUILDSTORAGE REFRESH_MONEY/'..guildstorage.get_money())
- cmdchat('GUILDSTORAGE CLEAR_TEMPSLOTS')
- local items = guildstorage.get_items()
- if items != 0 then
- for i = 1, table.getn(items) do
- local item = guildstorage.split_(items[i],"#")
- cmdchat('GUILDSTORAGE_ADDTEMPSLOT '..item[3]..' '..item[1]..' '..item[2]..' '..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])
- end
- end
- cmdchat('GUILDSTORAGE COMPARE_TEMPSLOTS')
- end
- function slot_empty(slot)
- local itemList = guildstorage.get_items()
- for i = 1 , table.getn(itemList) do
- local item = guildstorage.split_(itemList[i],"#")
- if tonumber(item[3]) == slot then
- return false
- end
- end
- return true
- end
- function create_guildstorage()
- os.execute("mkdir "..guildstorage_path.."Guildstorage/"..pc.get_guild())
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/storage.txt", "w+")
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/money.txt", "w+")
- guildstorage:write("0")
- guildstorage:close()
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/authority.txt", "w+")
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/logs.txt", "w+")
- guildstorage:close()
- end
- function insert_item(cell,slot,tab)
- local result = item.select_cell(cell)
- if not result then syschat'Probier es nochmal.' return end
- local itemId1 = item.get_id()
- local itemVnum1 = item.get_vnum()
- item.select_cell(cell)
- local attr = {{item3.get_attr(0)}, {item3.get_attr(1)}, {item3.get_attr(2)}, {item3.get_attr(3)},{item3.get_attr(4)},{item3.get_attr(5)}, {item3.get_attr(6)}}
- local socket, itemCount, itemVnum = {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_count(),item.get_vnum()
- if itemId1 != item.get_id() or itemVnum1 != itemVnum then syschat'wtf?' return end
- if not guildstorage.item_can_store(itemVnum) then syschat'Nie możesz dodać tego przedmiotu.' return end
- if itemCount > 1 then
- for i = 1, itemCount do
- item.remove()
- item.select_cell(cell)
- end
- elseif itemCount == 1 then
- item.remove()
- else
- chat'Fehler'
- return
- end
- cmdchat('GUILDSTORAGE_ADDITEMSLOT '..slot..' '..tab..' '..itemVnum..' '..itemCount..' '..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])
- guildstorage.add_log(pc.get_name(),'Item','umieszczenie',item_name(itemVnum)..' ('..itemCount..')')
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/storage.txt", "a+")
- -- syschat(itemVnum.."#"..itemCount.."#"..(slot+120*tab).."#"..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])
- guildstorage:write(itemVnum.."#"..itemCount.."#"..(slot+120*tab).."#"..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].."\\n")
- guildstorage:flush()
- guildstorage:close()
- end
- function remove_item(slot)
- game.set_event_flag('GUILDS_USE_'..pc.get_guild(),1)
- local gsPath = guildstorage_path.."Guildstorage/"..pc.get_guild().."/storage.txt"
- local items = {}
- local itemList = guildstorage.get_items()
- if slot > 720 then syschat'Ten slot nie istnieje.' return end
- for i = 1 , table.getn(itemList) do
- table.insert(items,guildstorage.split_(itemList[i],"#"))
- end
- for i = 1, table.getn(items) do
- if items[i][3] == tostring(slot) then
- guildstorage.add_log(pc.get_name(),'Item','pobranie',item_name(items[i][1])..' ('..items[i][2]..')')
- table.remove(items,i)
- break
- end
- end
- local gs = io.open(gsPath, "w+")
- for i = 1, table.getn(items) do
- gs: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]..'\\n')
- end
- gs:flush()
- gs:close()
- end
- function get_items()
- local guildstorageTab = {}
- local guildstorage = io.open(guildstorage_path.."Guildstorage/"..pc.get_guild().."/storage.txt", "r")
- for item in guildstorage:lines() do
- table.insert(guildstorageTab,item)
- end
- return guildstorageTab or 0
- end
- function move_item(from,to)
- local gsPath = guildstorage_path.."Guildstorage/"..pc.get_guild().."/storage.txt"
- local items = {}
- local itemList = guildstorage.get_items()
- for i = 1 , table.getn(itemList) do
- table.insert(items,guildstorage.split_(itemList[i],"#"))
- end
- for i = 1, table.getn(items) do
- if items[i][3] == tostring(from) then items[i][3] = tostring(to) end
- end
- local gs = io.open(gsPath, "w+")
- for i = 1, table.getn(items) do
- gs: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]..'\\n')
- end
- gs:flush()
- gs:close()
- end
- ----------------------
- --STORAGE END
- ----------------------
- function client_command(command_)
- return guildstorage.split_(command_,"#")
- end
- function split_(string_,delimiter)
- local result = { }
- local from = 1
- local delim_from, delim_to = string.find( string_, delimiter, from )
- while delim_from do
- table.insert( result, string.sub( string_, from , delim_from-1 ) )
- from = delim_to + 1
- delim_from, delim_to = string.find( string_, delimiter, from )
- end
- table.insert( result, string.sub( string_, from ) )
- return result
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement