mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
Merge branch 'hotfix/5.3.1'
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
--- Adds some parse functions that can be used with the role system
|
||||
local Commands = require 'expcore.commands'
|
||||
local Roles = require 'expcore.roles'
|
||||
local auto_complete = ext_require('expcore.common','auto_complete')
|
||||
require 'config.command_parse_general'
|
||||
|
||||
Commands.add_parse('role',function(input,player,reject)
|
||||
if not input then return end
|
||||
local role = Roles.get_role_from_any(input)
|
||||
local roles = Roles.config.roles
|
||||
local role = auto_complete(roles,input,true)
|
||||
if not role then
|
||||
return reject{'expcore-role.reject-role'}
|
||||
else
|
||||
|
||||
@@ -22,7 +22,7 @@ return {
|
||||
'modules.addons.advanced-starting-items',
|
||||
'modules.addons.spawn-area',
|
||||
'modules.addons.compilatron',
|
||||
'modules.addons.worn-paths',
|
||||
'modules.addons.scorched-earth',
|
||||
-- Config Files
|
||||
'config.command_auth_admin', -- commands tagged with admin_only are blocked for non admins
|
||||
'config.command_auth_roles', -- commands must be allowed via the role config
|
||||
|
||||
@@ -4,13 +4,16 @@ local Roles = require 'expcore.roles'
|
||||
-- Use these to adjust for ticks ie game.tick < 5*minutes
|
||||
local seconds, minutes, hours = 60, 3600, 216000
|
||||
|
||||
local function playtime(time_required)
|
||||
return function(player)
|
||||
if player.online_time > time_required then
|
||||
return true
|
||||
--[[
|
||||
-- cant use a factory as it has upvalues ;-;
|
||||
local function playtime(time_required)
|
||||
return function(player)
|
||||
if player.online_time > time_required then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
--- Role flags that will run when a player changes roles
|
||||
Roles.define_flag_trigger('is_admin',function(player,state)
|
||||
@@ -116,7 +119,11 @@ Roles.new_role('Veteran','Vet')
|
||||
:set_parent('Member')
|
||||
:allow{
|
||||
}
|
||||
:set_auto_promote_condition(playtime(10*hours))
|
||||
:set_auto_promote_condition(function(player)
|
||||
if player.online_time > 10*hours then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
--- Standard User Roles
|
||||
Roles.new_role('Member','Mem')
|
||||
@@ -133,7 +140,11 @@ Roles.new_role('Regular','Reg')
|
||||
:allow{
|
||||
'command/kill'
|
||||
}
|
||||
:set_auto_promote_condition(playtime(3*hours))
|
||||
:set_auto_promote_condition(function(player)
|
||||
if player.online_time > 3*hours then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
--- Guest/Default role
|
||||
Roles.new_role('Guest','')
|
||||
|
||||
@@ -420,4 +420,79 @@ function Public.clear_flying_text(surface)
|
||||
end
|
||||
end
|
||||
|
||||
--- Tests if a string contains a given substring.
|
||||
-- @tparam string s the string to check for the substring
|
||||
-- @tparam string contains the substring to test for
|
||||
-- @treturn boolean true if the substring was found in the string
|
||||
function Public.string_contains(s, contains)
|
||||
return s and string.find(s, contains) ~= nil
|
||||
end
|
||||
|
||||
--- Returns the closest match to a key
|
||||
-- @tparam options table a table of options for the auto complete
|
||||
-- @tparam input string the input string that will be completed
|
||||
-- @tparam[opt=false] use_key boolean when true the keys of options will be used as the options
|
||||
-- @tparam[opt=false] rtn_key boolean when true the the key will be returned rather than the value
|
||||
-- @return the list item found that matches the input
|
||||
function Public.auto_complete(options,input,use_key,rtn_key)
|
||||
local rtn = {}
|
||||
if type(input)~= 'string' then return end
|
||||
input = input:lower()
|
||||
for key,value in pairs(options) do
|
||||
local check = use_key and key or value
|
||||
if Public.string_contains(string.lower(check),input) then
|
||||
local result = rtn_key and key or value
|
||||
table.insert(rtn,result)
|
||||
end
|
||||
end
|
||||
return rtn[1]
|
||||
end
|
||||
|
||||
--- Returns all the keys of a table
|
||||
-- @tparam tbl table the table to get the keys of
|
||||
-- @treturn table an array of the table keys
|
||||
function Public.table_keys(tbl)
|
||||
local rtn = {}
|
||||
for key,_ in pairs(tbl) do
|
||||
table.insert(rtn,key)
|
||||
end
|
||||
return rtn
|
||||
end
|
||||
|
||||
--- Returns all the values of a table
|
||||
-- @tparam tbl table the table to get the values of
|
||||
-- @treturn table an array of the table values
|
||||
function Public.table_values(tbl)
|
||||
local rtn = {}
|
||||
for _,value in pairs(tbl) do
|
||||
table.insert(rtn,value)
|
||||
end
|
||||
return rtn
|
||||
end
|
||||
|
||||
--- Returns the list is a sorted way that would be expected by people (this is by key)
|
||||
-- @tparam table tbl the table to be sorted
|
||||
-- @treturn table the sorted table
|
||||
function Public.table_alphanumsort(tbl)
|
||||
local o = Public.table_keys(tbl)
|
||||
local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)")
|
||||
return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end
|
||||
table.sort(o, function(a,b)
|
||||
return tostring(a):gsub("%.?%d+",padnum)..("%3d"):format(#b)
|
||||
< tostring(b):gsub("%.?%d+",padnum)..("%3d"):format(#a) end)
|
||||
local _tbl = {}
|
||||
for _,k in pairs(o) do _tbl[k] = tbl[k] end
|
||||
return _tbl
|
||||
end
|
||||
|
||||
--- Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)
|
||||
-- @tparam table tbl the table to be sorted
|
||||
-- @treturn table the sorted table
|
||||
function Public.table_keysort(tbl)
|
||||
local o = Public.table_keys(tbl,true)
|
||||
local _tbl = {}
|
||||
for _,k in pairs(o) do _tbl[k] = tbl[k] end
|
||||
return _tbl
|
||||
end
|
||||
|
||||
return Public
|
||||
@@ -715,8 +715,8 @@ end
|
||||
Event.add(Roles.player_role_assigned,role_update)
|
||||
Event.add(Roles.player_role_unassigned,role_update)
|
||||
Event.add(defines.events.on_player_joined_game,role_update)
|
||||
-- Every 5 seconds the auto promote check is preformed
|
||||
Event.on_nth_tick(300,function()
|
||||
-- Every 60 seconds the auto promote check is preformed
|
||||
Event.on_nth_tick(3600,function()
|
||||
local promotes = {}
|
||||
for _,player in pairs(game.connected_players) do
|
||||
for _,role in pairs(Roles.config.roles) do
|
||||
|
||||
@@ -4,10 +4,11 @@ admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__
|
||||
tp-no-position-found=No position to teleport to was found, please try again later.
|
||||
tp-to-self=Player can not be teleported to themselves.
|
||||
chelp-title=Help results for "__1__":
|
||||
chelp-footer=(__1__ results found; page __2__ of __3__)
|
||||
chelp-footer=[__1__ results found; page __2__ of __3__]
|
||||
chelp-format=/__1__ __2__ - __3__ __4__
|
||||
chelp-alias=Alias: __1__
|
||||
chelp-out-of-range=__1__ is an invalid page number.
|
||||
roles-higher-role=The role you tried to assign is higher than your highest.
|
||||
roles-list=All active roles are:
|
||||
roles-list=All roles are: [color=__1__]__2__
|
||||
roles-list-player=[color=__1__]__2__ has: [color=__3__]__4__
|
||||
roles-list-element=__1__, [color=__2__]__3__
|
||||
@@ -8,7 +8,7 @@ Commands.new_command('assign-role','Assigns a role to a player')
|
||||
:set_flag('admin-only',true)
|
||||
:add_alias('rpromote','assign','role','add-role')
|
||||
:register(function(player,action_player,role,raw)
|
||||
local player_highest = Roles.get_player_highest(player)
|
||||
local player_highest = Roles.get_player_highest_role(player)
|
||||
if player_highest.index < role.index then
|
||||
Roles.assign_player(action_player,role,player.name)
|
||||
else
|
||||
@@ -22,7 +22,7 @@ Commands.new_command('unassign-role','Unassigns a role from a player')
|
||||
:set_flag('admin-only',true)
|
||||
:add_alias('rdemote','unassign','remove-role')
|
||||
:register(function(player,action_player,role,raw)
|
||||
local player_highest = Roles.get_player_highest(player)
|
||||
local player_highest = Roles.get_player_highest_role(player)
|
||||
if player_highest.index < role.index then
|
||||
Roles.unassign_player(action_player,role,player.name)
|
||||
else
|
||||
@@ -31,15 +31,28 @@ Commands.new_command('unassign-role','Unassigns a role from a player')
|
||||
end)
|
||||
|
||||
Commands.new_command('list-roles','Lists all roles in they correct order')
|
||||
:add_alias('lroles','roles')
|
||||
:register(function(player,raw)
|
||||
:add_param('player',true,'player')
|
||||
:add_alias('lsroles','roles')
|
||||
:register(function(player,action_player,raw)
|
||||
local roles = Roles.config.order
|
||||
local message = {'exp-commands.roles-list'}
|
||||
for _,role_name in pairs(roles) do
|
||||
local role = Roles.get_role_by_name(role_name)
|
||||
if action_player ~= '' then
|
||||
roles = Roles.get_player_roles(action_player)
|
||||
end
|
||||
for index,role in pairs(roles) do
|
||||
role = Roles.get_role_from_any(role)
|
||||
local colour = role.custom_color or Colours.white
|
||||
colour = string.format('%d,%d,%d',colour.r,colour.g,colour.b)
|
||||
message = {'exp-commands.roles-list-element',message,colour,role_name}
|
||||
if index == 1 then
|
||||
message = {'exp-commands.roles-list',colour,role.name}
|
||||
if action_player ~= '' then
|
||||
local player_colour = action_player.color
|
||||
player_colour = string.format('%d,%d,%d',player_colour.r*255,player_colour.g*255,player_colour.b*255)
|
||||
message = {'exp-commands.roles-list-player',player_colour,action_player.name,colour,role.name}
|
||||
end
|
||||
else
|
||||
message = {'exp-commands.roles-list-element',message,colour,role.name}
|
||||
end
|
||||
end
|
||||
return Commands.success(message)
|
||||
end)
|
||||
Reference in New Issue
Block a user