From 59574278a45f8fb975d60ec57ef45f66e7f6b54d Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:40:21 +0100 Subject: [PATCH] fix: non existing groups issues --- server/commands.lua | 64 ++++++++++++++++++++++++++++++++++++++------ server/functions.lua | 18 ++++++++++--- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index 5b224e3..c264af6 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -28,14 +28,36 @@ end, true, { }) NDCore.Functions.AddCommand("setjob", "Admin command, set player job.", function(source, args, rawCommand) - if not NDCore.Functions.IsPlayerAdmin(source) then return end + if not NDCore.Functions.IsPlayerAdmin(source) then + return { + color = {255, 0, 0}, + args = {"Error", "you don't have access to this command."} + } + end local target = tonumber(args[1]) - if not target or GetPlayerPing(target) == 0 then return end + if not target or GetPlayerPing(target) == 0 then + return { + color = {255, 0, 0}, + args = {"Error", "target player not found."} + } + end + + local job = args[2] + if not job then + return { + color = {255, 0, 0}, + args = {"Error", "job required."} + } + end local character = NDCore.Functions.GetPlayer(target) - NDCore.Functions.SetPlayerJob(character.id, args[2], args[3]) -end, true, { + NDCore.Functions.SetPlayerJob(character.id, job, args[3]) + return { + color = {0, 255, 0}, + args = {"Success", GetPlayerName(target) .. " job set to " .. job .. (args[3] and " rank " .. args[3] or " rank 1.")} + } +end, false, { { name="player", help="Player server id" }, { name="job name" }, { name="rank", help="This should be a number, default value is 1." } @@ -43,15 +65,37 @@ end, true, { NDCore.Functions.AddCommand("setgroup", "Admin command, set player group.", function(source, args, rawCommand) if not NDCore.Functions.IsPlayerAdmin(source) then return end - + local target = tonumber(args[1]) - if not target or GetPlayerPing(target) == 0 then return end + if not target or GetPlayerPing(target) == 0 then + return { + color = {255, 0, 0}, + args = {"Error", "target player not found."} + } + end + + local group = args[3] + if not group then + return { + color = {255, 0, 0}, + args = {"Error", "group required."} + } + end local character = NDCore.Functions.GetPlayer(target) if args[2] == "remove" then - NDCore.Functions.RemovePlayerFromGroup(character.id, args[3]) + NDCore.Functions.RemovePlayerFromGroup(character.id, group) + return { + color = {0, 255, 0}, + args = {"Success", GetPlayerName(target) .. " removed from " .. group} + } elseif args[2] == "add" then - NDCore.Functions.SetPlayerToGroup(character.id, args[3], args[4]) + local rank = args[4] + NDCore.Functions.SetPlayerToGroup(character.id, group, rank) + return { + color = {0, 255, 0}, + args = {"Success", GetPlayerName(target) .. " added to " .. group .. (rank and " rank " .. rank or " rank 1.")} + } end end, false, { { name="player", help="Player server id" }, @@ -64,6 +108,10 @@ NDCore.Functions.AddCommand("pay", "give cash to a nearby player", function(sour local amount = args[1] if not amount or amount == 0 then return end NDCore.Functions.GiveCashToNearbyPlayer(source, amount) + return { + color = {0, 255, 0}, + args = {"Success", amount .. " paid."} + } end, true, { { name="Amount" }, }) \ No newline at end of file diff --git a/server/functions.lua b/server/functions.lua index 3d3059b..d6a9296 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -542,9 +542,13 @@ function NDCore.Functions.SetPlayerToGroup(characterId, group, rank) if not data.groups then data.groups = {} end + local rankName = tostring(groupRank) + if config.groups[group] and config.groups[group][groupRank] then + rankName = config.groups[group][groupRank] + end data.groups[group] = { rank = groupRank, - rankName = config.groups[group][groupRank] + rankName = rankName } NDCore.Functions.SetPlayerData(characterId, "groups", data.groups) return true @@ -556,9 +560,13 @@ function NDCore.Functions.SetPlayerToGroup(characterId, group, rank) if not data.groups then data.groups = {} end + local rankName = tostring(groupRank) + if config.groups[group] and config.groups[group][groupRank] then + rankName = config.groups[group][groupRank] + end data.groups[group] = { rank = groupRank, - rankName = config.groups[group][groupRank] + rankName = rankName } NDCore.Functions.SetPlayerData(characterId, "groups", data.groups) return true @@ -615,10 +623,12 @@ function NDCore.Functions.AddCommand(name, help, callback, argsrequired, argumen return TriggerClientEvent("chat:addMessage", source, { color = {255, 0, 0}, multiline = true, - args = {"System", "All arguments must be filled out!"} + args = {"Error", "all arguments required."} }) end - callback(source, args, rawCommand) + local message = callback(source, args, rawCommand) + if not message then return end + TriggerClientEvent("chat:addMessage", source, message) end, false) NDCore.Commands[commandName] = {