O cofreLimits retorna quanto dinheiro o jogador gastou em qualquer situação durante o mês ou o dinheiro movido nesse cofre secundário no período?
- Fórum
- xTibia - Notícias e Suporte
- Soluções
- Archived
- [Pedido] Cofre Staff
info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino

o cofreLimits retorna o dinheiro movimentado no banco secundario pelo jogador que utilizar o comando
Primeiramente, em 000-constant.lua (data/lib), coloque as seguintes variáveis:
STAFF_VAULT = 49391 STAFF_VAULT_LIMITS = 49392
Depois, em data/globalevents/scripts:
local salary = {
--[group_id] = money,
}
local func = db.executeQuery or db.query
function onTime()
if os.date("%d") == "1" then
for group_id, money in pairs(salary) do
local query = db.getResult("SELECT id, online FROM players WHERE group_id = "..group_id)
if query:getID() ~= -1 then
repeat
if query:getDataInt("online") > 0 then
local pid = getPlayerByName(getPlayerNameByGUID(query:getDataInt("id")))
setPlayerStorageValue(pid, STAFF_VAULT, (getPlayerStorageValue(pid, STAFF_VAULT) < 0 and 0 or getPlayerStorageValue(pid, STAFF_VAULT)) + money)
setPlayerStorageValue(pid, STAFF_VAULT_LIMITS, 0)
else
local verify_query = db.getResult("SELECT * FROM player_storage WHERE player_id = "..query:getDataInt("id").." AND key = "..STAFF_VAULT)
if verify_query:getID() ~= -1 then
func("UPDATE player_storage SET value = value + "..money.." WHERE player_id = "..query:getDataInt("id").." AND key = "..STAFF_VAULT)
func("UPDATE player_storage SET value = 0 WHERE player_id = "..query:getDataInt("id").." AND key = "..STAFF_VAULT_LIMITS)
verify_query:free()
else
func("INSERT INTO player_storage VALUES ("..query:getDataInt("id")..", "..STAFF_VAULT..", "..money..")")
func("INSERT INTO player_storage VALUES ("..query:getDataInt("id")..", "..STAFF_VAULT_LIMITS..", 0)")
end
end
until not query:next()
query:free()
end
end
end
return true
end
Tag:
<globalevent name="staff_salary" time="00:00" event="script" value="nome_do_arquivo.lua"/>
function onSay(cid, words, param)
local balance, wasted_this_month = getPlayerStorageValue(cid, STAFF_VAULT) < 0 and 0 or getPlayerStorageValue(cid, STAFF_VAULT), getPlayerStorageValue(cid, STAFF_VAULT_LIMITS) < 0 and 0 or getPlayerStorageValue(cid, STAFF_VAULT_LIMITS)
if words == "/cofreLimits" then
local popup_message = [[
*** Informations about your personal vault ***
You wasted this month: %d gold.
At the moment, you have %d gold in your personal vault.]]
doPlayerPopupFYI(cid, popup_message:format(wasted_this_month, balance))
else
if param == "" then
return doPlayerSendCancel(cid, "Please, specify the player name and the money you want transfer.")
end
local info = param:explode(",")
local player, money = getPlayerByName(info[1]), tonumber(info[2])
if not isPlayer(player) then
return doPlayerSendCancel(cid, "This player doesn't exist or is offline.")
elseif not money then
return doPlayerSendCancel(cid, "Please, write a valid number.")
elseif money > balance then
return doPlayerSendCancel(cid, "You can't transfer this quantity of money.")
end
local player_balance = getPlayerBalance(player)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You successfully transfered "..money.." gold from your personal vault to "..(player == cid and "yourself" or info[1])..".")
if player ~= cid then
doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..money.." gold from "..getCreatureName(cid)..". The money was sent to your bank.")
end
doPlayerSetBalance(player, player_balance + money)
setPlayerStorageValue(cid, STAFF_VAULT, balance - money)
setPlayerStorageValue(cid, STAFF_VAULT_LIMITS, wasted_this_month + money)
end
return true
end<talkaction words="/cofreLimits;/cofreTransfer" access="4" event="script" value="nome_do_arquivo.lua"/>
Editado Setembro 26 por zipter98
info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino

assim?
PLAYERCUSTOMFLAG_HASFULLLIGHT = 26
STAFF_VAULT = 49391
STAFF_VAULT_LIMITS = 49392
maleOutfits = {128, 129, 130, 131, 132, 133, 134, 143, 144, 145, 146, 151, 152, 153, 154, 251, 268, 273, 278, 289, 325, 328, 335, 367}
Uhum, pode ser.
Editei meu comentário anterior com uma pequena modificação que você precisa fazer. Se possível, releia-o.
info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino

Então, não tem nenhum arquivo escrito start.lua no globalevents
Tem algum código com o callback onStartup?
Editado Setembro 18 por zipter98
info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino

Tem o init.lua :
local config = {
creationTime = 7 * 86400,
checkTime = 7 * 86400,
viceCount = 4,
memberCount = 10
}
function onStartup()
local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
if(result:getID() ~= -1) then
repeat
data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
until not(result:next())
result:free()
end
for id, v in ipairs(data) do
local owner, created, check = v[1], v[2], v[3]
if(created < (time - config.creationTime)) then
result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
if(result:getID() ~= -1) then
local rank, ranks = 0, {}
repeat
ranks[result:getDataInt("id")] = result:getDataInt("level")
if(result:getDataInt("level") == 1) then
rank = result:getDataInt("id")
end
until not(result:next())
result:free()
local members = {0, 0, 0, 0}
for k, v in ipairs(ranks) do
result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
if(result:getID() ~= -1) then
members[v] = members[v] + result:getDataInt("count")
result:free()
end
if(v == 2) then
result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
if(result:getID() ~= -1) then
local demote = ""
repeat
demote = demote .. result:getDataInt("id") .. ","
members[2] = members[2] - 1
members[1] = members[1] + 1
until not(result:next())
result:free()
if(demote ~= "" and rank ~= 0) then
db.query("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
end
end
end
end
for i = 1, 3 do
members[4] = members[4] + members[i]
end
if(members[2] < config.viceCount or members[4] < config.memberCount) then
if(check == 0) then
db.query("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
elseif(check < time) then
local tmp = ""
for rank, _ in ipairs(ranks) do
tmp = tmp .. rank .. ","
end
db.query("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
db.query("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
end
end
end
end
end
db.query("UPDATE `players` SET `online` = 0 WHERE `world_id` = " .. getConfigValue('worldId') .. " AND `online` > 0;")
db.query("UPDATE `bans` SET `active` = 0 WHERE `expires` <= " .. time .. " AND `expires` >= 0 AND `active` = 1")
db.query("DELETE FROM `guild_wars` WHERE `status` = 0 AND `begin` < " .. (time - 2 * 86400) .. ";")
if(getConfigValue("sqlType") ~= "sqlite") then
db.query("TRUNCATE TABLE `player_statements`;")
else
db.query("DELETE FROM `player_statements`;")
end
local query = db.getResult("SELECT `guild_id` FROM `castle_dono` WHERE `guild_id` > 0")
if query:getID() ~= -1 then
setGlobalStorageValue(1823999, query:getDataInt("guild_id"))
end
return true
end
function onGlobalSave()
if(getGameState() ~= GAMESTATE_CLOSING) then
return onStartup()
end
return true
end
Abaixo de:
function onStartup()
coloque:
db.query("UPDATE player_storage SET value = 0 WHERE key = "..STAFF_VAULT.." AND value < 0")
E, por gentileza, atualize o globalevent que passei anteriormente pelo novo.
info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino

estou tentando abrir o servidor, ele carrega só até creaturescripts e depois da erro no distro
Que erro?
info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino

não da erro, o distro simplesmente para de funcionar
@edit: quando eu tiro a linha do globalevents do globalevents.xml funfa normal
Editado Setembro 18 por Farathor
Acabo de corrigir os erros restantes do sistema e testá-lo. Pelo menos no meu servidor está funcionando perfeitamente.
Se apresentar algum erro no globalevent, troque:
function onTime()
por:
function onTimer()
Editado Setembro 19 por zipter98



info
Grupo: Visconde
Registrado: 02/10/13
Posts: 320
Reputação: +22
Gênero: Masculino
Então, esse script de Cofre da Staff seria como um segundo banco, que todo mês é adicionado uma certa quantidade de dinheiro a todos os jogador com group maior que 3 ou seja, GM e CM, quantidade de dinheiro para GM, seria menor que a de CM.
O Dinheiro desse cofre só poderia ser movimento a partir de comandos:
Quando o GM Usa o comando /cofreTransfer, a quantidade de dinheiro que ele transferiu vai para o banco do jogador, todo mês é resetado o cofreLimits e é adicionado a quantidade configurada de dinheiro para ele.
Caso não entendam, postem sua duvida que eu tento explicar melhor.
Editado Setembro 16 por Farathor