From 7977f0129af857ecb972d4fb4115c3763afb14ac Mon Sep 17 00:00:00 2001 From: Logan Gartner Date: Sat, 26 Mar 2022 02:37:29 -0600 Subject: [PATCH] Added DarkRP money commands --- modules/server/sv_darkrp.txt | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 modules/server/sv_darkrp.txt diff --git a/modules/server/sv_darkrp.txt b/modules/server/sv_darkrp.txt new file mode 100644 index 0000000..fd167d3 --- /dev/null +++ b/modules/server/sv_darkrp.txt @@ -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 ", + desc = "Gives away money to .", + func = giveMoney, + }, + requestmoney = { + usage = "requestmoney [message]", + desc = "Kindly asks for . Can include an optional message.", + func = requestMoney, + }, + }, + } +end \ No newline at end of file