Added DarkRP money commands

This commit is contained in:
Logan G 2022-03-26 02:37:29 -06:00
parent 448d318dbe
commit 7977f0129a
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -0,0 +1,76 @@
--@name
--@author
--@server
do
local function giveMoney(args)
local target = core:get_entity(args[1])
if target == nil then
return
end
local amount = tonumber(args[2])
if tonumber(amount) <= 0 then
core:log(log.ERROR, "Amount must be a non zero number!")
end
if darkrp.canGiveMoney(target) then
local money = owner():getMoney()
target:giveMoney(amount)
else
core:log(log.ERROR, "Cannot give money due to a cooldown!")
end
end
local function requestMoney(args)
local target = core:get_entity(args[1])
if target == nil then
return
end
local amount = tonumber(args[2])
if tonumber(amount) <= 0 then
core:log(log.ERROR, "Amount must be a non zero number!")
end
if darkrp.canMakeMoneyRequest(target) then
local money = owner():getMoney()
target:requestMoney((#args[3] > 0 and args[3] or ""), amount,
function() --Success
if owner():getMoney() + amount >= money then
core:log(log.INFO, "Successfully received "..darkrp.formatMoney(amount).." from "..target:getName().."!")
else
-- This probably won't happen here
core:log(log.ERROR, "An unknown error occured! Transaction status is unknown.")
end
end,
function() --Failure
core:log(log.ERROR, "Money request to "..target:getName().." failed!")
end
)
core:log(log.INFO, "Requested "..darkrp.formatMoney(amount).." from "..target:getName()..".")
else
core:log(log.ERROR, "Cannot request money due to a cooldown!")
end
end
core.modules.darkrp = {
version = 1,
desc = "Provides useful commands for DarkRP servers.",
commands = {
givemoney = {
usage = "givemoney <name> <amount>",
desc = "Gives away money to <name>.",
func = giveMoney,
},
requestmoney = {
usage = "requestmoney <name> <amount> [message]",
desc = "Kindly asks <name> for <amount>. Can include an optional message.",
func = requestMoney,
},
},
}
end