From 9df2a958f82d2ad85d93a45ea846089241dd7df9 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 9 Apr 2019 21:33:11 +0100 Subject: [PATCH] Changed kill and tag to use role system --- config/roles.lua | 5 ++++- expcore/locale/en.cfg | 3 ++- expcore/roles.lua | 20 +++++++++++++------- locale/en/expcore.cfg | 3 ++- modules/commands/kill.lua | 16 ++++++++++++++-- modules/commands/tag.lua | 11 +++++++++-- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/config/roles.lua b/config/roles.lua index e8baf7b9..4de02f5c 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -67,7 +67,9 @@ Roles.new_role('Trainee','TrMod') 'command/admin-chat', 'command/teleport', 'command/bring', - 'command/goto' + 'command/goto', + 'command/kill/always', + 'command/tag-clear/always', } Roles.new_role('Sponsor','Spon') @@ -122,6 +124,7 @@ Roles.new_role('Regular','Reg') :set_permission_group('Standard') :set_parent('Guest') :allow{ + 'command/kill' } :set_auto_promote_condition(playtime(3*hours)) diff --git a/expcore/locale/en.cfg b/expcore/locale/en.cfg index 2a9b5451..f064aa41 100644 --- a/expcore/locale/en.cfg +++ b/expcore/locale/en.cfg @@ -20,4 +20,5 @@ command-error-log-format=[ERROR] command/__1__ :: __2__ error-log-format-flag=[ERROR] roleFlag/__1__ :: __2__ error-log-format-promote=[ERROR] rolePromote/__1__ :: __2__ game-message-assign=__1__ has been assigned to __2__ by __3__ -game-message-unassign=__1__ has been unassigned from __2__ by __3__ \ No newline at end of file +game-message-unassign=__1__ has been unassigned from __2__ by __3__ +command-error-higher-role=Unauthorized, __1__ has a higher role than you. \ No newline at end of file diff --git a/expcore/roles.lua b/expcore/roles.lua index d865122c..f380c58b 100644 --- a/expcore/roles.lua +++ b/expcore/roles.lua @@ -103,6 +103,18 @@ function Roles.get_player_roles(player) return rtn end +function Roles.get_player_highest_role(player) + local roles = Roles.get_player_roels(player) + if not roles then return end + local highest + for _,role in pairs(roles) do + if not highest or role.index < highest.index then + highest = role + end + end + return highest +end + function Roles.assign_player(player,roles,by_player_name) player = Game.get_player_from_any(player) if not player then return end @@ -410,13 +422,7 @@ local function role_update(event) end end -- Updates the players permission group - local highest - local roles = Roles.get_player_roles(player) - for _,role in pairs(roles) do - if not highest or role.index < highest.index then - highest = role - end - end + local highest = Roles.get_player_highest_role(player) if highest.permission_group then if highest.permission_group[1] then local group = game.permissions.get_group(highest.permission_group[2]) diff --git a/locale/en/expcore.cfg b/locale/en/expcore.cfg index ee6f558d..68a1f9f9 100644 --- a/locale/en/expcore.cfg +++ b/locale/en/expcore.cfg @@ -22,4 +22,5 @@ command-error-log-format=[ERROR] command/__1__ :: __2__ error-log-format-flag=[ERROR] roleFlag/__1__ :: __2__ error-log-format-promote=[ERROR] rolePromote/__1__ :: __2__ game-message-assign=__1__ has been assigned to __2__ by __3__ -game-message-unassign=__1__ has been unassigned from __2__ by __3__ \ No newline at end of file +game-message-unassign=__1__ has been unassigned from __2__ by __3__ +command-error-higher-role=Unauthorized, __1__ has a higher role than you. \ No newline at end of file diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua index 24dc16bc..2467f5a7 100644 --- a/modules/commands/kill.lua +++ b/modules/commands/kill.lua @@ -1,4 +1,5 @@ local Commands = require 'expcore.commands' +local Roles = require 'expcore.roles' require 'config.command_parse_general' Commands.new_command('kill','Kills yourself or another player.') @@ -9,11 +10,22 @@ Commands.new_command('kill','Kills yourself or another player.') return player end end} -:set_flag('admin_only',true) :register(function(player,action_player,raw) if not action_player then -- can only be nil if no player given and the user is dead return Commands.error{'exp-commands.kill-already-dead'} end - action_player.character.die() + if player == action_player then + action_player.character.die() + elseif Roles.player_allowed(player,'command/kill/always') then + local player_highest = Roles.get_player_highest_role(player) + local action_player_highest = Roles.get_player_highest_role(action_player) + if player_highest.index < action_player_highest.index then + action_player.character.die() + else + return Commands.error{'expcore-roles.command-error-higher-role',action_player.name} + end + else + return Commands.error{'expcore-commands.unauthorized'} + end end) \ No newline at end of file diff --git a/modules/commands/tag.lua b/modules/commands/tag.lua index 4105d92a..c335e892 100644 --- a/modules/commands/tag.lua +++ b/modules/commands/tag.lua @@ -1,4 +1,5 @@ local Commands = require 'expcore.commands' +local Roles = require 'expcore.roles' require 'config.command_parse_general' Commands.new_command('tag','Sets your player tag.') @@ -17,9 +18,15 @@ end} if action_player.index == player.index then -- no player given so removes your tag action_player.tag = '' - elseif player.admin then + elseif Roles.player_allowed(player,'command/clear-tag/always') then -- player given and user is admin so clears that player's tag - action_player.tag = '' + local player_highest = Roles.get_player_highest_role(player) + local action_player_highest = Roles.get_player_highest_role(action_player) + if player_highest.index < action_player_highest.index then + action_player.tag = '' + else + return Commands.error{'expcore-roles.command-error-higher-role',action_player.name} + end else -- user is not admin and tried to clear another users tag return Commands.error{'expcore-commands.unauthorized'}