Added some get commands

This commit is contained in:
Cooldude2606
2017-08-20 20:26:06 +01:00
parent 75e3c904f0
commit 3a5c73f0a0
5 changed files with 44 additions and 3 deletions

View File

@@ -78,7 +78,19 @@ See code for more details.
* name = value retured by sudo
* returens a list if the data returend by thefunction if any
* get_sudo_info(string)
* return either a list or string based on the string boliean
* return either a list or string based on the string boliean
* get_ranks(part)
* returns a list of all the ranks
* part (opt) = part of the rank you want to return ie name
* function get_rank_presets(rank)
* returns the current rank presets
* rank (opt) = rank name if only one rank is needed
* get_ranked_players(rank)
* returns the ranks and online time of every player
* rank (opt) = limits it to only this rank
* get_commands(rank)
* returns all commands that are useable
* rank (opt) = rank name to limt it to what that rank can use
## Other
* define_command(name,help,inputs,restriction,event)
* Add game commands in a way it does not cause crashes

View File

@@ -76,7 +76,15 @@ function load_command(command)
end
end)
end
-- returns all the commands in a certain rank restriction
function get_commands(rank)
local rank = rank or 'Owner'
local to_return = {}
for _,command in pairs(global.commands) do
if command.restriction <= string_to_rank(restriction).power then table.insert(to_return,command) end
end
return to_return
end
Event.register(-1,function() global.commands = Exp_commands end)
Event.register(defines.events.on_player_joined_game,function() for _,command in pairs(Exp_commands) do load_command(command) end end)
--Please Only Edit Above This Line-----------------------------------------------------------

View File

@@ -120,6 +120,16 @@ function find_new_rank(player)
if get_rank(player).power <= string_to_rank('mod').power and not player.admin then rank_print(player.name..' needs to be promoted.') end
if old_rank.name ~= get_rank(player).name then global.old_ranks[player.index]=old_rank.name end
end
-- returns a list with every players current rank, or just the players of the rank given, includes online time
function get_ranked_players(rank)
local to_return = {}
for _,player in paris(game.players) do
if not rank or rank == get_rank(player).name then
table.insert(to_return,{player.name,tick_to_display_format(player.online_time),get_rank(player).name}) set_ending_screen_data
end
end
return to_return
end
--Event handlers
Event.rank_change = script.generate_event_name()
Event.register(-1,function()

View File

@@ -73,7 +73,10 @@ local preset_ranks = {
Jail={}
}
-- returns this list, or just one rank if given
function get_rank_presets(rank)
if rank then return global.preset_ranks[rank] else return global.preset_ranks end
end
Event.register(-1,function() global.preset_ranks = preset_ranks end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits

View File

@@ -140,6 +140,14 @@ for n,rank in pairs(ranks) do
end
end
end
-- returns a list off all the ranks, return only one part if given
function get_ranks(part)
local to_return = {}
if part then
for _,rank in pairs(global.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.ranks end
return to_return
end
-- Move the ranks to the global array
Event.register(-1,function() global.ranks = ranks end)
--Please Only Edit Above This Line-----------------------------------------------------------