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"/>
data/talkactions/scripts:
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
Tag:
<talkaction words="/cofreLimits;/cofreTransfer" access="4" event="script" value="nome_do_arquivo.lua"/>