82 lines
No EOL
2.6 KiB
Text
82 lines
No EOL
2.6 KiB
Text
--@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()
|
|
local requestStr = ""
|
|
if #args >= 3 then
|
|
for i = 3, #args do
|
|
requestStr = requestStr.." "..args[i]
|
|
end
|
|
end
|
|
target:requestMoney(requestStr, 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 |