Ir para conteúdo

melocom

Membro
  • Registro em

  • Última visita

Histórico de Curtidas

  1. Gostei
    melocom deu reputação a Fortation em Auto Delete   
    Em globalevents/script vc cria um arquivo chamado "dbcleaner" (sem " ) e coloca isso



    ------------------------------------------------------------------------------* ----- [[> Automated Database Cleanup 1.1 Structure //By Cybermaster <]] ------| -------------- [[> System 2.0 Revamped by Teh Maverick <3 <]] ----------------| ------------- [[> Removal of empty accounts by darkaos <]] ---------------| --------------- [[> Function getDBPlayersCount() by Elf <]] ------------------| ------------------------------------------------------------------------------| ------------------------------------------------------------------------------| --- ~!READ THIS!~ ------------------------------------------------------------| --- Be sure to back up your database and test this on your server first, -----| --- I(Teh Maverick) cannot guarantee it will work the same for every core. ---| --- It is very easy to test, with the log file and values that are printed ---| -----------------------------------Enjoy!-------------------------------------| ------------------------------------------------------------------------------* function countRowsWhereInTable(table, field, condition) local result = db.getResult("SELECT COUNT(" .. field .. ") as count FROM " .. table .. " WHERE " .. field .. " = '" .. condition .. "';") local tmp = result:getDataInt("count") result:free() return tmp end function getDBPlayersCount() local result = db.getResult("SELECT COUNT(id) as count FROM `players`;") local tmp = result:getDataInt("count") result:free() return tmp end function getDBAccountsCount() local result = db.getResult("SELECT COUNT(id) as count FROM `accounts`;") local tmp = result:getDataInt("count") result:free() return tmp end function onstartup() local DB_BEFORE = {players = getDBPlayersCount(), accounts = getDBAccountsCount()} local result,result1, ii, numPlayersToDelete, numAccountsDeleted, tmp = 0, 0, 0, 0, 0 local pid, aid = {}, {} local dropCount = {players={},accounts={}} local config = { deleteAccountWithNoPlayers = true, cleanChildTables = true, printResult = true, saveResultToFile = true, logFileName = 'db_cleanup.txt' } --In each table, players with below specified level, and days of inactivity will be deleted from db on server startup local cleanup = { [1] = {level = 100, time = 7 * 24 * 60 * 60}, [2] = {level = 300, time = 60 * 24 * 60 * 60} } local childAttributeTables = { players = { [1] = {table = "`player_viplist`", idField = "`player_id`"}, [2] = {table = "`player_storage`", idField = "`player_id`"}, [3] = {table = "`player_spells`", idField = "`player_id`"}, [4] = {table = "`player_skills`", idField = "`player_id`"}, [5] = {table = "`player_namelocks`", idField = "`player_id`"}, [6] = {table = "`player_items`", idField = "`player_id`"}, [7] = {table = "`player_depotitems`", idField = "`player_id`"}, [8] = {table = "`houses`", idField = "`owner`"}, [9] = {table = "`house_auctions`", idField = "`player_id`"}, [10] = {table = "`players`", idField = "`id`"} -- Keep this as the last item in the array --Note: `houses` and `bans` are in the DB triggers for TFS so don't worry about them. --Also I did not want to put killers, or deaths on here because that is historic data, --do so at your ouwn risk. }, accounts = { [1] = {table = "`accounts`", idField = "`id`"}, [2] = {table = "`account_viplist`", idField = "`account_id`"} } } --Clean up all the players and player data for i = 1, #cleanup do result = db.getResult("SELECT `id`,`name`,`account_id` FROM `players` WHERE `level` < ".. cleanup[i].level .." AND `name` NOT IN('Account Manager', 'Sorcerer Sample', 'Druid Sample', 'Paladin Sample', 'Knight Sample', 'Rook Sample') AND `group_id` < 2 AND `lastlogin` < UNIX_TIMESTAMP() - ".. cleanup[i].time ..";") if(result:getID() ~= -1) then ii = 1 repeat pid[ii] = result:getDataInt("id") -- list the players id into an array aid[ii] = result:getDataInt("account_id") -- list the account id of each player being removed into an array ii = ii + 1 until not(result:next()) result:free() end numPlayersToDelete = ii - 1 --Drop players and their child table attribute data such as skills, items, etc. for j = 1, numPlayersToDelete do if(config.cleanChildTables) then for k = 1, #childAttributeTables.players do dropCount.players[k] = ((dropCount.players[k] or 0) + countRowsWhereInTable(childAttributeTables.players[k].table, childAttributeTables.players[k].idField, pid[j])) db.executeQuery("DELETE FROM " .. childAttributeTables.players[k].table .. " WHERE " .. childAttributeTables.players[k].idField .. " = '" .. pid[j] .. "';") end else db.executeQuery("DELETE FROM `players` WHERE `id` = '" .. pid[j] .. "';") end end end --Drop all the accounts that have 0 players linked to them (at the moment its only checking from the list of players removed) if config.deleteAccountWithNoPlayers then --This part was scripted by Darkhaos, modified/fixed by Teh Maverick --[[ for acc = 1, #aid do result1 = db.getResult("SELECT `id` FROM `accounts` WHERE `id` = '" .. aid[acc] .. "';") if result1:getID() ~= -1 then -- check to make sure the account exists result1:free() for i = 1, #childAttributeTables.accounts do --Make sure there are no other players on the account result1 = db.getResult("SELECT COUNT(id) as count FROM `players` WHERE `account_id` = '" .. aid[acc] .. "';") tmp = result1:getDataInt("count") if(tmp <= 0) then --Remove accounts dropCount.accounts[i] = ((dropCount.accounts[i] or 0) + countRowsWhereInTable(childAttributeTables.accounts[i].table, childAttributeTables.accounts[i].idField, aid[acc])) db.executeQuery("DELETE FROM " .. childAttributeTables.accounts[i].table .. " WHERE " .. childAttributeTables.accounts[i].idField .. " = '" .. aid[acc] .. "';") end end end end end --]] --Print and Save results (configurable) local DB_NOW = {players = DB_BEFORE.players - getDBPlayersCount(), accounts = DB_BEFORE.accounts - getDBAccountsCount()} if DB_NOW.players > 0 or DB_NOW.accounts > 0 then local text = ">> [DBCLEANUP] " .. DB_NOW.players .. " inactive players" .. (config.deleteAccountWithNoPlayers and " and " .. DB_NOW.accounts .. " empty accounts" or "") .. " have been deleted from the database." --Write to console if config.printResult then print("") print(text) if config.cleanChildTables then --Write player info for i = 1,#dropCount.players do print("[!] --> Dropped: " .. dropCount.players[i] .. " from " .. childAttributeTables.players[i].table .. " table") end --Write account info if config.deleteAccountWithNoPlayers then for i = 1,#dropCount.accounts do print("[!] --> Dropped: " .. dropCount.accounts[i] .. " from " .. childAttributeTables.accounts[i].table .. " table") end end print("") end end --Write to file if config.saveResultToFile then local file = io.open("data/logs/"..config.logFileName, "a") file:write("[" .. os.date("%d %B %Y %X ", os.time()) .. "] " .. text .. "\n") if config.cleanChildTables then --Write player info for i = 1, #dropCount.players do file:write("[!] --> Dropped: " .. dropCount.players[i] .. " from " .. childAttributeTables.players[i].table .. " table\n") end --Write account info if config.deleteAccountWithNoPlayers then for i = 1, #dropCount.accounts do file:write("[!] --> Dropped: " .. dropCount.accounts[i] .. " from " .. childAttributeTables.accounts[i].table .. " table\n") end end file:write("\n") end file:close() end end return true end [/code] vai em globalevents.xml e cola isso [code]<globalevent name="dbcleaner" type="startup" event="script" value="dbcleaner.lua"/> Você só vai editar isso: [1] = {level = 100, time = 7 * 24 * 60 * 60}, [2] = {level = 300, time = 60 * 24 * 60 * 60}

    Level minimo e o tempo...
    Por exemplo: level 100- deletar acada 7 dias de inativo... level 300- deletar acada 2 meses de inativo...
  2. Gostei
    melocom deu reputação a Renato em [Talkaction] Shop System [ !sell - !buy ] Fácil Configuração!   
    Sim, tive a ideia ao ver o shop system do skyd, mas não peguei nada do script dele.


    Instalando

    talkactions/scripts/shop.lua



    local config = {
    ["demon shield"] = {id = 2520, sell = 'yes 32000', buy = 'yes 70000' },
    ["magic plate armor"] = {id = 2472, sell = 'yes 120000', buy = 'no' },
    ["boots of haste"] = {id = 2195, sell = 'yes 30000', buy = 'no' }
    }

    function upperfirst(first, rest)
    return first:upper()..rest:lower()
    end

    function onSay(cid, words, param, channel)

    if (param == nil or param == '' or param == 'lista' or param == 'list') then
    if (words == "!sell" or words == "/sell") then
    str = "Showing items that you can sell:\n\n"
    else
    str = "Showing items that you can buy:\n\n"
    end
    for item, vars in pairs(config) do
    if (words == "!sell" or words == "/sell") then
    expl = string.explode(vars.sell, " ")
    else
    expl = string.explode(vars.buy, " ")
    end
    item = item:gsub("(%a)([%w_']*)", upperfirst)
    if (expl[1] == 'no') then
    str = str
    else
    str = str .. item.. " - " .. expl[2] .. " gps\n"
    end
    end
    return doShowTextDialog(cid, 2160, str)
    end
    local item = config[param:lower()]
    param = param:lower()
    if (item) then
    local sell = string.explode(item.sell, " ")
    local buy = string.explode(item.buy, " ")
    if (words == "!sell" or words == "/sell") then
    if (sell[1] == "yes") then
    if (doPlayerRemoveItem(cid, item.id, 1)) then
    doPlayerAddMoney(cid, sell[2])
    doSendMagicEffect(getPlayerPosition(cid), 30)
    return doPlayerSendTextMessage(cid,29,"Here are, you sold "..param.." for "..sell[2].." gold coins.")
    else
    doSendMagicEffect(getPlayerPosition(cid), 2)
    return doPlayerSendTextMessage(cid,29,"You don't have anything "..param.." to sell.")
    end
    else
    doSendMagicEffect(getPlayerPosition(cid), 2)
    return doPlayerSendTextMessage(cid,29,"Sorry, "..param.." cannot be sold.")
    end
    else
    if (buy[1] == "yes") then
    if (doPlayerRemoveMoney(cid, buy[2])) then
    doPlayerAddItem(cid, item.id)
    doSendMagicEffect(getPlayerPosition(cid), 28)
    return doPlayerSendTextMessage(cid,29,"Here are, you bought "..param.." for "..buy[2].." gold coins.")
    else
    doSendMagicEffect(getPlayerPosition(cid), 2)
    return doPlayerSendTextMessage(cid,29,"You don't have enough money.")
    end
    else
    doSendMagicEffect(getPlayerPosition(cid), 2)
    return doPlayerSendTextMessage(cid,29,"Sorry, "..param.." cannot be bought.")
    end
    end

    else
    doSendMagicEffect(getPlayerPosition(cid), 2)
    if (words == "!sell") then
    return doPlayerSendTextMessage(cid,29,"Sorry, this item cannot be sold or it does't exist.")
    else
    return doPlayerSendTextMessage(cid,29,"Sorry, this item cannot be bought or it does't exist.")
    end
    end
    end
    [/code] [b]talkactions/talkactions.xml[/b] [code]<talkaction words="!sell;/sell;!buy;/buy" event="script" value="shop.lua"/> Adicionando novos itens
    ♣ Config Observem no começo do código estas linhas: local config = {
    ["demon shield"] = {id = 2520, sell = 'yes 32000', buy = 'yes 70000' },
    ["magic plate armor"] = {id = 2472, sell = 'yes 120000', buy = 'yes 60000' },
    ["boots of haste"] = {id = 2195, sell = 'yes 30000', buy = 'no' }
    }[/code] Seguindo uma ordem óbvia, adicionem abaixo do boots of haste e antes do '}' que fecha o config. assim para adicionar sigam o modelo ["nome do item"], repectivamente de suas variáveis. [b]♣ Variáveis[/b] [color=#800080][b]id[/b][/color] - é onde você coloca o id do item [color=#800080][b]sell [/b][/color]- você precisa colocar se o item pode ser vendido por "yes" ou "no", caso for yes de um espaço (se não der espaço não funciona) e bote o valor em gold coins (não é k) [color=#800080][b]buy [/b][/color]- segue a ordem igual ao sell porem é se o item pode ser comprado pelo !buy ou não, e o preço que o player pagará. [b]♣ Exemplos[/b] Assim, digamos que desejo acrescentar um mastermind shield onde o player pode vender por 60k e comprar por 120k, adicionarei: [code]["mastermind shield"] = {id = 2514, sell = 'yes 60000', buy = 'yes 120000' }, Em seguida quero adicionar uma soft boots que pode ser vendida por 300k, mas NÃO PODE ser comprada. Colocarei: ["soft boots"] = {id = 6132, sell = 'yes 300000', buy = 'no' }, local config = {
    ["demon shield"] = {id = 2520, sell = 'yes 32000', buy = 'yes 70000' },
    ["magic plate armor"] = {id = 2472, sell = 'yes 120000', buy = 'no' },
    ["boots of haste"] = {id = 2195, sell = 'yes 30000', buy = 'yes 60000' },
    ["mastermind shield"] = {id = 2514, sell = 'yes 60000', buy = 'yes 120000' },
    ["soft boots"] = {id = 6132, sell = 'yes 300000', buy = 'no' }
    }[/code]

    [color=#ff0000][size=5][b]Atenção![/b][/size][/color]
    [color=#ff0000]Reparem que em todas as linhas finalizam-se com }, mas na última há ausência da vírgula, isto ocorre por que não pode ter vírgula no último, não sei ao certo se dará erro, não cheguei a testar, mas em muitas linguagens de programação ocorre um erro. Então é melhor ficar atento.[/color]

    Creio que passei as devidas instruções corretamente, e não é nenhum bixo de sete cabeças... qualquer um que tenha uma mentalidade normal conseguirá configurar.

    [size=5][b]
    [size=6][color=#006400]Explicando as talkactions[/color][/size]
    [/b][/size]
    [b]♣ Comprando[/b]
    Bom, agora que já adicionou todos os items, vou explicar como funciona:
    O player comprará uma boh (item sugestivo) item por: [color=#800080][b]!buy boots of haste[/b][/color], caso não tenha grana, não vai conseguir, caso tenha comprará.

    [b]♣ Vendendo[/b]
    O mesmo quando ele for vender, ele falará: [color=#800080][b]!sell boots of haste[/b][/color], caso não tenha o item, o script negará, caso tenha o item some e o dinheiro aparece (:




    [center][/center]




    [center][/center]


    [b]♣ Lista de items[/b]
    [i]Ohh, não sei quais items pode ser comprados, e também não sei quanto custa, e agora?[/i]
    Diga [b][color=#800080]!buy[/color][/b], ou [b][color=#800080]!buy[/color] [color=#800080]list [/color][/b]ou [b][color=#800080]!buy[/color] [color=#800080]lista[/color][/b] para ver todos os items




    [center][/center]


    [i]O mesmo com os items que podem ser vendidos:[/i]
    [b][color=#800080]!sell[/color][/b], [b][color=#800080]!sell list[/color][/b] ou [b][color=#800080]!sell lista[/color][/b]



    [center][/center]



    [size=7][color=#006400]Versão 2[/color][/size]

    Deixo aberto sugestões para a versão 2
    E claro, caso haja, correção de bugs.

    __________________


    [b]♣ Créditos[/b]
    Renato - Desenvolvimento
    skydangerous - Ideia
    Então, meu config ficará desta forma:

Informação Importante

Confirmação de Termo