mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Added Jail and some other stuff
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
41
modules/addons/jail-control.lua
Normal file
41
modules/addons/jail-control.lua
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user