Added Way to set admin only commands

This commit is contained in:
Cooldude2606
2018-09-07 16:48:55 +01:00
parent 3a52ef2a65
commit e14c3a68b9

View File

@@ -150,7 +150,8 @@ local function run_custom_command(command)
local data = commands.data[command.name]
local player_name = Game.get_player(command) and Game.get_player(command).name or 'server'
-- is the player allowed to use this command, if no ExpGamingCore.Ranking then this is ingroned
if Ranking and Ranking.meta and Ranking.meta.rank_count > 0 and not Ranking.get_rank(player_name):allowed(command.name) then
if Ranking and Ranking.meta and Ranking.meta.rank_count > 0 and not Ranking.get_rank(player_name):allowed(command.name)
or not Ranking and data.setAdminOnly == true and game.player and not game.player.admin then
player_return({'commands.unauthorized'},defines.textcolor.crit)
if game.player then game.player.play_sound{path='utility/cannot_build'} end
game.write_file('commands.log',
@@ -212,7 +213,11 @@ commands.add_command = function(name, description, inputs, callback)
name=name,
description=description,
inputs=inputs,
callback=callback
callback=callback,
setAdminOnly=function(tbl,value)
if is_type(tbl,'table') then if is_type(value,'boolean') then tbl.setAdminOnly = value else tbl.setAdminOnly = true end
else if is_type(tbl,'boolean') then data[name].setAdminOnly = value else data[name].setAdminOnly = true end
end
}
local help = is_type(description,'string') and commands.format_inputs(name)..'- '..description
or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,commands.format_inputs(name)..'- '}
@@ -222,6 +227,7 @@ commands.add_command = function(name, description, inputs, callback)
local success, err = pcall(run_custom_command,...)
if not success then error(err) end
end)
return data[name]
end
function commands:on_init()