Added Jail and some other stuff

This commit is contained in:
Cooldude2606
2019-04-16 20:46:42 +01:00
parent 0123451267
commit eb4c389673
14 changed files with 194 additions and 66 deletions

View File

@@ -7,20 +7,18 @@ local config = require 'config.compilatron'
local messages = config.messages
local locations = config.locations
local compilatrons = {}
local current_messages = {}
Global.register(
{
compilatrons = compilatrons,
current_messages = current_messages
},
function(tbl)
compilatrons = tbl.compilatrons
current_messages = tbl.current_messages
end
)
local Public = {
compilatrons={},
current_messages={}
}
local Public = {}
Global.register({
Public.compilatrons,
Public.current_messages
},function(tbl)
Public.compilatrons=tbl[1]
Public.current_messages=tbl[2]
end)
--- This will re-create the speech bubble after it de-spawns called with set_timeout
local callback =
@@ -33,17 +31,17 @@ local callback =
ent.surface.create_entity(
{name = 'compi-speech-bubble', text = messages[name][msg_number], position = {0, 0}, source = ent}
)
current_messages[name] = {message = message, msg_number = msg_number}
Public.global.current_messages[name] = {message = message, msg_number = msg_number}
end
)
--- This will move the messages onto the next message in the loop
local function circle_messages()
for name, ent in pairs(compilatrons) do
for name, ent in pairs(Public.global.compilatrons) do
if not ent.valid then
Public.spawn_compilatron(game.players[1].surface,name)
end
local current_message = current_messages[name]
local current_message = Public.global.current_messages[name]
local msg_number
local message
if current_message ~= nil then
@@ -73,12 +71,12 @@ function Public.add_compilatron(entity, name)
if name == nil then
return
end
compilatrons[name] = entity
Public.global.compilatrons[name] = entity
local message =
entity.surface.create_entity(
{name = 'compi-speech-bubble', text = messages[name][1], position = {0, 0}, source = entity}
)
current_messages[name] = {message = message, msg_number = 1}
Public.global.current_messages[name] = {message = message, msg_number = 1}
end
--- This spawns a new compilatron on a surface with the given location tag (not a position)

View File

@@ -94,6 +94,4 @@ if config.auto_collect_bodies then
end
-- this is so other modules can access the logs
return function()
return deaths
end
return deaths

View File

@@ -0,0 +1,41 @@
local Roles = require 'expcore.roles'
local Game = require 'utils.game'
local Global = require 'utils.global'
local Public = {
old_roles = {}
}
Global.register(Public.old_roles,function(tbl)
Public.old_roles=tbl
end)
--- Jails a player, this is only the logic there is no output to players
-- @tparam player LuaPlayer the player that will be jailed, must not be in jail
-- @tparam[opt='<server>'] by_player_name string the name of the player doing the action used in logs
-- @treturn the number of roles that were removed, nil if there was an error
function Public.jail_player(player,by_player_name)
player = Game.get_player_from_any(player)
if not player then return end
if Roles.player_has_role(player,'Jail') then return end
local old_roles = Role.get_player_roles(player)
Public.old_roles[player.name] = old_roles
Roles.unassign_player(player,old_roles,by_player_name,true)
Roles.assign_player(player,'Jail',by_player_name,true)
return #old_roles
end
--- Unjails a player, this is only the logic there is no output to players
-- @tparam player LuaPlayer the player that will be unjailed, must be in jail
-- @tparam[opt='<server>'] by_player_name string string the name of the player who is doing the action
-- @treturn the number of roles that were added, nil if there was an error
function Public.unjail_player(player,by_player_name)
player = Game.get_player_from_any(player)
if not player then return end
if not Roles.player_has_role(player,'Jail') then return end
local old_roles = Public.old_roles[player.name]
Roles.unassign_player(player,'Jail',by_player_name,true)
Roles.assign_player(player,old_roles,by_player_name,true)
return #old_roles
end
return Public

View File

@@ -141,4 +141,7 @@ Event.add(defines.events.on_player_created, function(event)
spawn_belts(s,p)
spawn_turrets()
player.teleport(p,s)
end)
end)
-- Way to access global table
return turrets

View File

@@ -1,4 +1,5 @@
local Commands = require 'expcore.commands'
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name')
require 'config.command_parse_general'
Commands.new_command('admin-chat','Sends a message in chat that only admins can see.')
@@ -7,12 +8,10 @@ Commands.new_command('admin-chat','Sends a message in chat that only admins can
:set_flag('admin_only',true)
:add_alias('ac')
:register(function(player,message,raw)
local pcc = player and player.chat_color or {r=255,g=255,b=255}
local player_name = player and player.name or '<Server>'
local colour = string.format('%s,%s,%s',pcc.r,pcc.g,pcc.b)
local player_name_colour = format_chat_player_name(player)
for _,return_player in pairs(game.connected_players) do
if return_player.admin then
return_player.print{'exp-commands.admin-chat-format',player_name,message,colour}
return_player.print{'exp-commands.admin-chat-format',player_name_colour,message}
end
end
return Commands.success -- prevents command complete message from showing

View File

@@ -72,4 +72,7 @@ Commands.new_command('chelp','Searches for a keyword in all commands you are all
end
-- blocks command complete message
return Commands.success
end)
end)
-- way to access global
return search_cache

View File

@@ -91,4 +91,8 @@ add_interface_callback('position',function(player) return player.position end)
add_interface_callback('entity',function(player) return player.selected end)
add_interface_callback('tile',function(player) return player.surface.get_tile(player.position) end)
return add_interface_callback
return {
add_interface_callback=add_interface_callback,
interface_env=interface_env,
interface_callbacks=interface_callbacks
}

32
modules/commands/jail.lua Normal file
View File

@@ -0,0 +1,32 @@
local Commands = require 'expcore.commands'
local JailControl = require 'modules.addons.jail-control'
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name')
require 'config.command_parse_roles'
Commands.new_command('jail','Puts a player into jail and removes all other roles')
:add_param('player',false,'player-role')
:add_param('reason',true)
:enable_auto_concat()
:register(function(player,action_player,reason,raw)
reason = reason or 'Non Given.'
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
if JailControl.jail_player(action_player,player.name) then
game.print{'exp-commands.jail-give',action_player_name_color,by_player_name_color,reason}
else
return Commands.error{'exp-commands.jail-already-jailed',action_player_name_color}
end
end)
Commands.new_command('unjail','Puts a player into jail and removes all other roles')
:add_param('player',false,'player-role')
:enable_auto_concat()
:register(function(player,action_player,raw)
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
if JailControl.unjail_player(action_player,player.name) then
game.print{'exp-commands.jail-remove',action_player_name_color,by_player_name_color}
else
return Commands.error{'exp-commands.jail-not-jailed',action_player_name_color}
end
end)

View File

@@ -1,6 +1,10 @@
local Commands = require 'expcore.commands'
local Roles = require 'expcore.roles'
local Colours = require 'resources.color_presets'
local format_chat_player_name, format_chat_colour_localized = ext_require('expcore.common',
'format_chat_player_name',
'format_chat_colour_localized'
)
Commands.new_command('assign-role','Assigns a role to a player')
:add_param('player',false,'player-role')
@@ -42,16 +46,15 @@ Commands.new_command('list-roles','Lists all roles in they correct order')
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)
local role_name = format_chat_colour_localized(role.name,colour)
if index == 1 then
message = {'exp-commands.roles-list',colour,role.name}
message = {'exp-commands.roles-list',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}
local player_name_colour = format_chat_player_name(action_player)
message = {'exp-commands.roles-list-player',player_name_colour,role_name}
end
else
message = {'exp-commands.roles-list-element',message,colour,role.name}
message = {'exp-commands.roles-list-element',message,role_name}
end
end
return Commands.success(message)