mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
feat(server): setmoney command
This commit is contained in:
@@ -24,7 +24,8 @@ server_scripts {
|
|||||||
"server/player.lua",
|
"server/player.lua",
|
||||||
"server/vehicle.lua",
|
"server/vehicle.lua",
|
||||||
"server/functions.lua",
|
"server/functions.lua",
|
||||||
"compatibility/**/server.lua"
|
"compatibility/**/server.lua",
|
||||||
|
"server/commands.lua"
|
||||||
}
|
}
|
||||||
|
|
||||||
file "init.lua"
|
file "init.lua"
|
||||||
|
|||||||
63
server/commands.lua
Normal file
63
server/commands.lua
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
local moneyTypes = {"bank", "cash"}
|
||||||
|
local moneyActions = {
|
||||||
|
remove = function(player, account, amount)
|
||||||
|
player.deductMoney(account, amount, "Staff action")
|
||||||
|
return ("Removed $%d (%s) to %s"):format(amount, account, player.name), ("removed $%d from %s"):format(amount, account)
|
||||||
|
end,
|
||||||
|
add = function(player, account, amount)
|
||||||
|
player.addMoney(account, amount, "Staff action")
|
||||||
|
return ("Added $%d (%s) to %s"):format(amount, account, player.name), ("added $%d to %s"):format(amount, account)
|
||||||
|
end,
|
||||||
|
set = function(player, account, amount)
|
||||||
|
player.setData(account, amount, "Staff action")
|
||||||
|
return ("Set %s's (%s) to $%d"):format(player.name, account, amount), ("set %s to $%d"):format(account, amount)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
lib.addCommand("setmoney", {
|
||||||
|
help = "Admin command, manage player money.",
|
||||||
|
-- restricted = "group.admin",
|
||||||
|
params = {
|
||||||
|
{
|
||||||
|
name = "target",
|
||||||
|
type = "playerId",
|
||||||
|
help = "Target player's server id"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "action",
|
||||||
|
type = "string",
|
||||||
|
help = "remove/add/set"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "type",
|
||||||
|
type = "string",
|
||||||
|
help = "bank/cash"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "amount",
|
||||||
|
type = "number",
|
||||||
|
help = "bank/cash"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}, function(source, args, raw)
|
||||||
|
local action = moneyActions[args.action]
|
||||||
|
local moneyType = args.type:lower()
|
||||||
|
if not action or not lib.table.contains(moneyTypes, moneyType) then return end
|
||||||
|
|
||||||
|
local player = NDCore.getPlayer(args.target)
|
||||||
|
local staffMessage, userMessage = action(player, moneyType, args.amount)
|
||||||
|
|
||||||
|
player.notify({
|
||||||
|
title = "Staff action",
|
||||||
|
description = userMessage,
|
||||||
|
type = "inform",
|
||||||
|
duration = 10000
|
||||||
|
})
|
||||||
|
|
||||||
|
if not source then return end
|
||||||
|
TriggerClientEvent("chat:addMessage", source, {
|
||||||
|
color = {50, 100, 235},
|
||||||
|
multiline = true,
|
||||||
|
args = {"Staff action", staffMessage}
|
||||||
|
})
|
||||||
|
end)
|
||||||
@@ -87,18 +87,18 @@ local function createCharacterTable(info)
|
|||||||
|
|
||||||
---@param key string|table
|
---@param key string|table
|
||||||
---@param value any
|
---@param value any
|
||||||
function self.setData(key, value)
|
function self.setData(key, value, reason)
|
||||||
if type(key) == "table" then
|
if type(key) == "table" then
|
||||||
for k, v in pairs(key) do
|
for k, v in pairs(key) do
|
||||||
self[k] = v
|
self[k] = v
|
||||||
if k == "cash" or k == "bank" then
|
if k == "cash" or k == "bank" then
|
||||||
TriggerEvent("ND:moneyChange", self.source, k, v, "set")
|
TriggerEvent("ND:moneyChange", self.source, k, v, "set", reason)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self[key] = value
|
self[key] = value
|
||||||
if key == "cash" or key == "bank" then
|
if key == "cash" or key == "bank" then
|
||||||
TriggerEvent("ND:moneyChange", self.source, key, value, "set")
|
TriggerEvent("ND:moneyChange", self.source, key, value, "set", reason)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.triggerEvent("ND:updateCharacter", self)
|
self.triggerEvent("ND:updateCharacter", self)
|
||||||
|
|||||||
Reference in New Issue
Block a user