diff --git a/config/file_loader.lua b/config/file_loader.lua index 3cbd4fac..7a85b3cc 100644 --- a/config/file_loader.lua +++ b/config/file_loader.lua @@ -15,6 +15,7 @@ return { 'modules.commands.interface', 'modules.commands.help', 'modules.commands.roles', + 'modules.commands.rainbow', -- QoL Addons 'modules.addons.chat-popups', 'modules.addons.damage-popups', @@ -23,6 +24,7 @@ return { 'modules.addons.spawn-area', 'modules.addons.compilatron', 'modules.addons.scorched-earth', + 'modules.addons.pollution-grading', -- 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 diff --git a/config/roles.lua b/config/roles.lua index 29c0017b..2e239c19 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -120,7 +120,7 @@ Roles.new_role('Veteran','Vet') :allow{ } :set_auto_promote_condition(function(player) - if player.online_time > 10*hours then + if player.online_time > 10*216000 then return true end end) @@ -141,7 +141,7 @@ Roles.new_role('Regular','Reg') 'command/kill' } :set_auto_promote_condition(function(player) - if player.online_time > 3*hours then + if player.online_time > 3*216000 then return true end end) @@ -155,7 +155,8 @@ Roles.new_role('Guest','') 'command/tag', 'command/tag-clear', 'command/chelp', - 'command/list-roles' + 'command/list-roles', + 'command/rainbow' } --- Jail role diff --git a/expcore/commands.lua b/expcore/commands.lua index b9eb5186..9a8ef7f9 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -162,6 +162,7 @@ return Commands.error(message[opt]) -- this returns an error to the user, and will halt the command execution, ie no success message is returned Commands.success(message[opt]) -- used to return a success message however dont use this method see below return Commands.success(message[opt]) -- will return the success message to the user and your given message, halts execution + return if any value is returned then it will be returned to the player via a Commands.success call Example Code: Commands.new_command('repeat-name','Will repeat you name a number of times in chat.') @@ -728,7 +729,10 @@ function Commands.run_command(command_event) if Commands.internal_error(success,command_data.name,err) then return command_log(player,command_data,'Internal Error: Command Callback Fail',params,command_event.parameter,err) end - if err ~= Commands.defines.error and err ~= Commands.defines.success and err ~= Commands.error and err ~= Commands.success then + if err == Commands.defines.error or err == Commands.error then + return command_log(player,command_data,'Custom Error',raw_params,input_string) + elseif err ~= Commands.defines.success and err ~= Commands.success then + -- in this case the user has not received any output Commands.success(err) end command_log(player,command_data,'Success',raw_params,input_string) diff --git a/expcore/common.lua b/expcore/common.lua index 145e19d8..4c3478fa 100644 --- a/expcore/common.lua +++ b/expcore/common.lua @@ -18,6 +18,8 @@ local Colours = require 'resources.color_presets' local Game = require 'utils.game' local Util = require 'util' +require 'utils.table' +require 'utils.math' local Public = {} @@ -96,7 +98,7 @@ function Public.player_return(value,colour,player) returnAsString = tostring(value) else -- value is a table - returnAsString = serpent.block(value) + returnAsString = table.inspect(value,{depth=5,indent=' ',newline='\n'}) end elseif Public.type_check(value,'function') then -- value is a function @@ -495,4 +497,10 @@ function Public.table_keysort(tbl) return _tbl end +function Public.format_chat_colour(message,color) + color = color or Colours.white + local color_tag = '[color='..math.round(color.r,3)..','..math.round(color.g,3)..','..math.round(color.b,3)..']' + return string.format('%s%s[/color]',color_tag,message) +end + return Public \ No newline at end of file diff --git a/expcore/roles.lua b/expcore/roles.lua index 09fc11e0..6cf5b71b 100644 --- a/expcore/roles.lua +++ b/expcore/roles.lua @@ -180,9 +180,10 @@ local function emit_player_roles_updated(player,type,roles,by_player_name) local by_player = Game.get_player_from_any(by_player_name) local by_player_index = by_player and by_player.index or 0 local role_names = {} - for _,role in pairs(roles) do + for index,role in pairs(roles) do role = Roles.get_role_from_any(role) if role then + roles[index] = role table.insert(role_names,role.name) end end @@ -198,7 +199,7 @@ local function emit_player_roles_updated(player,type,roles,by_player_name) player_name=player.name, by_player_name=by_player_name, type=type, - roles_changed=roles + roles_changed=role_names }..'\n',true,0) end @@ -222,7 +223,7 @@ function Roles.debug() local role = Roles.config.roles[role_name] local color = role.custom_color or Colours.white color = string.format('[color=%d,%d,%d]',color.r,color.g,color.b) - output = output..string.format('\n%s %s) %s',color,index,serpent.line(role)) + output = output..string.format('\n%s %s) %s[/color]',color,index,serpent.line(role)) end return output end diff --git a/locale/en/commands.cfg b/locale/en/commands.cfg index 54e3a84a..393aae20 100644 --- a/locale/en/commands.cfg +++ b/locale/en/commands.cfg @@ -1,6 +1,6 @@ [exp-commands] kill-already-dead=You are already dead. -admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ +admin-chat-format=[Admin Chat] [color=__3__]__1__[/color]: __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__": @@ -9,6 +9,6 @@ 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 roles are: [color=__1__]__2__ -roles-list-player=[color=__1__]__2__ has: [color=__3__]__4__ -roles-list-element=__1__, [color=__2__]__3__ \ No newline at end of file +roles-list=All roles are: [color=__1__]__2__[/color] +roles-list-player=[color=__1__]__2__[/color] has: [color=__3__]__4__[/color] +roles-list-element=__1__, [color=__2__]__3__[/color] \ No newline at end of file diff --git a/modules/commands/rainbow.lua b/modules/commands/rainbow.lua new file mode 100644 index 00000000..f2d03cda --- /dev/null +++ b/modules/commands/rainbow.lua @@ -0,0 +1,54 @@ +local Commands = require 'expcore.commands' +local format_chat_colour = ext_require('expcore.common','format_chat_colour') + +local function step_component(c1,c2) + if c1 < 0 then + return 0,c2+c1 + elseif c1 > 1 then + return 1,c2-c1+1 + else + return c1,c2 + end +end + +local function step_color(color) + color.r,color.g = step_component(color.r,color.g) + color.g,color.b = step_component(color.g,color.b) + color.b,color.r = step_component(color.b,color.r) + color.r = step_component(color.r,0) + return color +end + +local function next_color(color,step) + step = step or 0.1 + local new_color = {r=0,g=0,b=0} + if color.b == 0 and color.r ~= 0 then + new_color.r = color.r-step + new_color.g = color.g+step + elseif color.r == 0 and color.g ~= 0 then + new_color.g = color.g-step + new_color.b = color.b+step + elseif color.g == 0 and color.b ~= 0 then + new_color.b = color.b-step + new_color.r = color.r+step + end + return step_color(new_color) +end + +Commands.new_command('rainbow','Sends an rainbow message in the chat') +:add_param('message',false) -- action that is done by the player, just text its meaningless +:enable_auto_concat() +:register(function(player,message,raw) + local player_name = player and player.name or '' + local player_color = player and player.color or nil + local color_step = 3/message:len() + if color_step > 1 then color_step = 1 end + local current_color = {r=1,g=0,b=0} + local output = format_chat_colour(player_name..': ',player_color) + output = output..message:gsub('%S',function(letter) + local rtn = format_chat_colour(letter,current_color) + current_color = next_color(current_color,color_step) + return rtn + end) + game.print(output) +end) \ No newline at end of file