Changed kill and tag to use role system

This commit is contained in:
Cooldude2606
2019-04-09 21:33:11 +01:00
parent 0e18002375
commit 9df2a958f8
6 changed files with 44 additions and 14 deletions

View File

@@ -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))

View File

@@ -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__
game-message-unassign=__1__ has been unassigned from __2__ by __3__
command-error-higher-role=Unauthorized, __1__ has a higher role than you.

View File

@@ -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])

View File

@@ -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__
game-message-unassign=__1__ has been unassigned from __2__ by __3__
command-error-higher-role=Unauthorized, __1__ has a higher role than you.

View File

@@ -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)

View File

@@ -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'}