Spell Check and Lua Check

This commit is contained in:
Cooldude2606
2019-01-11 22:32:30 +00:00
parent 7110b76444
commit 082d9e5439
65 changed files with 760 additions and 724 deletions

31
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"cSpell.enabledLanguageIds": [
"asciidoc",
"c",
"cpp",
"csharp",
"css",
"go",
"handlebars",
"html",
"jade",
"javascript",
"javascriptreact",
"json",
"latex",
"less",
"lua",
"markdown",
"php",
"plaintext",
"pub",
"python",
"restructuredtext",
"rust",
"scss",
"text",
"typescript",
"typescriptreact",
"yml"
]
}

View File

@@ -2,14 +2,14 @@
-- @module ThisModule@X.Y.Z -- @module ThisModule@X.Y.Z
-- @author <get from json> -- @author <get from json>
-- @license <get from json> -- @license <get from json>
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Module = require('Module') local Module = require('Module')
local SubModule = require('Collection.Submodule') local SubModule = require('Collection.Submodule')
local OptModule -- OptModule@^X.Y.Z local OptModule -- OptModule@^X.Y.Z
-- Local Varibles -- Local Variables
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
@@ -34,4 +34,4 @@ local global = global{
-- Event Handlers Define -- Event Handlers Define
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -594,7 +594,7 @@ Manager.event = setmetatable({
__load=script.on_load, __load=script.on_load,
__config=script.on_configuration_changed, __config=script.on_configuration_changed,
events=defines.events, events=defines.events,
error_chache={} error_cache={}
},{ },{
__metatable=false, __metatable=false,
__call=function(tbl,event_name,new_callback,...) __call=function(tbl,event_name,new_callback,...)
@@ -619,14 +619,14 @@ Manager.event = setmetatable({
if type(callback) ~= 'function' then error('Invalid Event Callback: "'..event_name..'/'..moduleName..'"') end if type(callback) ~= 'function' then error('Invalid Event Callback: "'..event_name..'/'..moduleName..'"') end
local success, err = Manager.sandbox(callback,{moduleName=setupModuleName(moduleName),module_path=Manager.loadModules.__load[tostring(moduleName)]},new_callback,...) local success, err = Manager.sandbox(callback,{moduleName=setupModuleName(moduleName),module_path=Manager.loadModules.__load[tostring(moduleName)]},new_callback,...)
if not success then if not success then
local chache = tbl.error_chache local cache = tbl.error_cache
local error_message = 'Event Failed: "'..moduleName..'/'..tbl.names[event_name]..'" ('..err..')' local error_message = 'Event Failed: "'..moduleName..'/'..tbl.names[event_name]..'" ('..err..')'
if not chache[error_message] then Manager.verbose(error_message,'errorCaught') error(error_message) end if not cache[error_message] then Manager.verbose(error_message,'errorCaught') error(error_message) end
if tbl.names[event_name] == 'on_tick' then if tbl.names[event_name] == 'on_tick' then
if not chache[error_message] then chache[error_message] = {game.tick,1} end if not cache[error_message] then cache[error_message] = {game.tick,1} end
if chache[error_message][1] >= game.tick-10 then chache[error_message] = {game.tick,chache[error_message][2]+1} if cache[error_message][1] >= game.tick-10 then cache[error_message] = {game.tick,cache[error_message][2]+1}
else chache[error_message] = nil end else cache[error_message] = nil end
if chache[error_message] and chache[error_message][2] > 100 then if cache[error_message] and cache[error_message][2] > 100 then
Manager.verbose('There was an error happening every tick for 100 ticks, the event handler has been removed!','errorCaught') Manager.verbose('There was an error happening every tick for 100 ticks, the event handler has been removed!','errorCaught')
event_functions[moduleName] = nil event_functions[moduleName] = nil
end end
@@ -694,7 +694,7 @@ Manager.event = setmetatable({
rawset(Manager.event,'names',setmetatable({},{ rawset(Manager.event,'names',setmetatable({},{
__index=function(tbl,key) __index=function(tbl,key)
if type(key) == 'number' or tonumber(key) then if type(key) == 'number' or tonumber(key) then
-- if it is a number then it will first look in the chache -- if it is a number then it will first look in the cache
if rawget(tbl,key) then return rawget(tbl,key) end if rawget(tbl,key) then return rawget(tbl,key) end
-- if it is a core event then it will simply return -- if it is a core event then it will simply return
if key == -1 then rawset(tbl,key,'__init') if key == -1 then rawset(tbl,key,'__init')
@@ -706,7 +706,7 @@ rawset(Manager.event,'names',setmetatable({},{
if id == key then rawset(tbl,key,event) end if id == key then rawset(tbl,key,event) end
end end
end end
-- returns the value from the chache after being loaded in -- returns the value from the cache after being loaded in
return rawget(tbl,key) return rawget(tbl,key)
-- if it is a string then no reverse look up is required -- if it is a string then no reverse look up is required
else else

View File

@@ -206,7 +206,7 @@
<h3>Returns:</h3> <h3>Returns:</h3>
<ol> <ol>
<span class="types"><span class="type">boelon</span></span> <span class="types"><span class="type">boolean</span></span>
based on if it successed or not based on if it successed or not
</ol> </ol>
@@ -244,7 +244,7 @@
<h3>Returns:</h3> <h3>Returns:</h3>
<ol> <ol>
<span class="types"><span class="type">boelon</span></span> <span class="types"><span class="type">boolean</span></span>
based on if it successed or not based on if it successed or not
</ol> </ol>

View File

@@ -87,7 +87,7 @@
<td class="summary">Prints to chat as if it were a player</td> <td class="summary">Prints to chat as if it were a player</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#emit_embeded">emit_embeded (args)</a></td> <td class="name" nowrap><a href="#emit_embedded">emit_embedded (args)</a></td>
<td class="summary">Logs an embed to the json.data we use a js script to add things we cant here</td> <td class="summary">Logs an embed to the json.data we use a js script to add things we cant here</td>
</tr> </tr>
<tr> <tr>
@@ -135,7 +135,7 @@
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#EmitEmbededParamaters">EmitEmbededParamaters</a></td> <td class="name" nowrap><a href="#EmitEmbededParamaters">EmitEmbededParamaters</a></td>
<td class="summary">Outline of the paramaters accepted by Sync.emit_embeded</td> <td class="summary">Outline of the paramaters accepted by Sync.emit_embedded</td>
</tr> </tr>
</table> </table>
<h2><a href="#Fields">Fields</a></h2> <h2><a href="#Fields">Fields</a></h2>
@@ -262,8 +262,8 @@
</dd> </dd>
<dt> <dt>
<a name = "emit_embeded"></a> <a name = "emit_embedded"></a>
<strong>emit_embeded (args)</strong> <strong>emit_embedded (args)</strong>
</dt> </dt>
<dd> <dd>
Logs an embed to the json.data we use a js script to add things we cant here Logs an embed to the json.data we use a js script to add things we cant here
@@ -273,7 +273,7 @@
<ul> <ul>
<li><span class="parameter">args</span> <li><span class="parameter">args</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
a table which contains everything that the embeded will use a table which contains everything that the embedded will use
</li> </li>
</ul> </ul>
@@ -286,7 +286,7 @@
<h3>Usage:</h3> <h3>Usage:</h3>
<ul> <ul>
<pre class="example">Sync.emit_embeded{title=<span class="string">'BAN'</span>,color=<span class="string">'0x0'</span>,description=<span class="string">'A player was banned'</span> ... }</pre> <pre class="example">Sync.emit_embedded{title=<span class="string">'BAN'</span>,color=<span class="string">'0x0'</span>,description=<span class="string">'A player was banned'</span> ... }</pre>
</ul> </ul>
</dd> </dd>
@@ -592,7 +592,7 @@
<strong>EmitEmbededParamaters</strong> <strong>EmitEmbededParamaters</strong>
</dt> </dt>
<dd> <dd>
Outline of the paramaters accepted by Sync.emit_embeded Outline of the paramaters accepted by Sync.emit_embedded
<h3>Fields:</h3> <h3>Fields:</h3>

View File

@@ -2,9 +2,9 @@
-- @module AdvancedStartingItems@4.0.0 -- @module AdvancedStartingItems@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Local Varibles -- Local Variables
local items = { local items = {
['iron-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 8 else return (made*10)/math.pow(tick_to_min(game.tick),2) end end, ['iron-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 8 else return (made*10)/math.pow(tick_to_min(game.tick),2) end end,
['copper-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return (made*8)/math.pow(tick_to_min(game.tick),2) end end, ['copper-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return (made*8)/math.pow(tick_to_min(game.tick),2) end end,
@@ -12,9 +12,9 @@ local items = {
['iron-gear-wheel']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return (made*6)/math.pow(tick_to_min(game.tick),2) end end, ['iron-gear-wheel']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return (made*6)/math.pow(tick_to_min(game.tick),2) end end,
['steel-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return(made*4)/math.pow(tick_to_min(game.tick),2) end end, ['steel-plate']=function(player,made) if tick_to_min(game.tick) < 5 then return 0 else return(made*4)/math.pow(tick_to_min(game.tick),2) end end,
['pistol']=function(player,made) if player.force.item_production_statistics.get_input_count('submachine-gun') > 5 then return 0 else return 1 end end, ['pistol']=function(player,made) if player.force.item_production_statistics.get_input_count('submachine-gun') > 5 then return 0 else return 1 end end,
['submachine-gun']=function(player,made) if made > 5 then return 1 else return 0 end end, ['submachine-gun']=function(player,made) if made > 5 then return 1 else return 0 end end,
['firearm-magazine']=function(player,made) if player.force.item_production_statistics.get_input_count('piercing-rounds-magazine') > 100 then return 0 else return 10 end end, ['firearm-magazine']=function(player,made) if player.force.item_production_statistics.get_input_count('piercing-rounds-magazine') > 100 then return 0 else return 10 end end,
['piercing-rounds-magazine']=function(player,made) if made > 100 then return 10 else return 0 end end, ['piercing-rounds-magazine']=function(player,made) if made > 100 then return 10 else return 0 end end,
['light-armor']=function(player,made) if made > 5 and player.force.item_production_statistics.get_input_count('heavy-armor') <= 5 then return 1 else return 0 end end, ['light-armor']=function(player,made) if made > 5 and player.force.item_production_statistics.get_input_count('heavy-armor') <= 5 then return 1 else return 0 end end,
['heavy-armor']=function(player,made) if made > 5 then return 1 else return 0 end end, ['heavy-armor']=function(player,made) if made > 5 then return 1 else return 0 end end,
['burner-mining-drill']=function(player,made) if tick_to_min(game.tick) < 5 then return 4 else return 0 end end, ['burner-mining-drill']=function(player,made) if tick_to_min(game.tick) < 5 then return 4 else return 0 end end,
@@ -28,7 +28,7 @@ local module_verbose = false
local ThisModule = {} local ThisModule = {}
-- Event Handlers Define -- Event Handlers Define
Event.register(defines.events.on_player_created, function(event) script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
if event.player_index == 1 then if event.player_index == 1 then
player.force.friendly_fire = false player.force.friendly_fire = false
@@ -42,4 +42,4 @@ Event.register(defines.events.on_player_created, function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ChatPopup@4.0.0 -- @module ChatPopup@4.0.0
-- @author badgamernl -- @author badgamernl
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ChatPopup -- @alias ChatPopup
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
@@ -19,7 +19,7 @@ function ChatPopup.sendFlyingText(player, text)
for i=1, #text, chunkSize do for i=1, #text, chunkSize do
chunks[#chunks+1] = text:sub(i,i+chunkSize - 1) chunks[#chunks+1] = text:sub(i,i+chunkSize - 1)
end end
-- Itterate over text chunks and create them as floating text centered above the player -- Iterate over text chunks and create them as floating text centered above the player
-- Disabled false centering because of not being able to disable scaling: (1 / 7.9 * #value) -- Disabled false centering because of not being able to disable scaling: (1 / 7.9 * #value)
for i,value in ipairs(chunks) do for i,value in ipairs(chunks) do
_player.surface.create_entity{ _player.surface.create_entity{
@@ -31,11 +31,11 @@ function ChatPopup.sendFlyingText(player, text)
end end
end end
Event.register(defines.events.on_console_chat, function(event) script.on_event(defines.events.on_console_chat, function(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
if not player then return end if not player then return end
if not event.message then return end if not event.message then return end
-- Send message player send to player itself -- Send message player send to player itself
local message = player.name .. ': ' .. event.message local message = player.name .. ': ' .. event.message
ChatPopup.sendFlyingText(player, message) ChatPopup.sendFlyingText(player, message)
@@ -50,7 +50,7 @@ Event.register(defines.events.on_console_chat, function(event)
end end
end end
end end
end) end)
return ChatPopup return ChatPopup

View File

@@ -1,20 +1,20 @@
--- When a entibty is damaged y a player it will show how much damage you've dealth, When a player gets attacked by a entity it will popup the player's health in color. --- When a entity is damaged y a player it will show how much damage you've death, When a player gets attacked by a entity it will popup the player's health in color.
-- @module DamagePopup@4.0.0 -- @module DamagePopup@4.0.0
-- @author badgamernl -- @author badgamernl
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais DamagePopup -- @alias DamagePopup
-- Module Require -- Module Require
local Color = require('FactorioStdLib.Color') local Color = require('FactorioStdLib.Color')
local DamagePopup = {} local DamagePopup = {}
Event.register(defines.events.on_entity_damaged, function(event) script.on_event(defines.events.on_entity_damaged, function(event)
local entity = event.entity local entity = event.entity
local cause = event.cause local cause = event.cause
local damage = event.original_damage_amount local damage = event.original_damage_amount
local health = entity.health local health = entity.health
-- local pre_attack_health = health + damage -- Didn't use it after all, maybe usefull later -- local pre_attack_health = health + damage -- Didn't use it after all, maybe useful later
local color = defines.textcolor.crit local color = defines.textcolor.crit
@@ -36,7 +36,7 @@ Event.register(defines.events.on_entity_damaged, function(event)
entity.surface.create_entity{ entity.surface.create_entity{
name="flying-text", name="flying-text",
color=defines.textcolor.med, color=defines.textcolor.med,
text='-'..math.floor(damage), -- cooldude2606 added floor for damage ammount text='-'..math.floor(damage), -- cooldude2606 added floor for damage amount
position=entity.position position=entity.position
} }
end end

View File

@@ -2,7 +2,7 @@
-- @module DeathMarkers@4.0.0 -- @module DeathMarkers@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
@@ -14,7 +14,7 @@ local global = global{
} }
-- Event Handlers Define -- Event Handlers Define
Event.register(defines.events.on_player_died, function(event) script.on_event(defines.events.on_player_died, function(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
local tag = player.force.add_chart_tag(player.surface,{ local tag = player.force.add_chart_tag(player.surface,{
position=player.position, position=player.position,
@@ -24,7 +24,7 @@ Event.register(defines.events.on_player_died, function(event)
table.insert(global.corpses,tag) table.insert(global.corpses,tag)
end) end)
Event.register(defines.events.on_tick, function(event) script.on_event(defines.events.on_tick, function(event)
if (game.tick%3600) ~= 0 then return end if (game.tick%3600) ~= 0 then return end
if not global.corpses then global.corpses = {} end if not global.corpses then global.corpses = {} end
local key = 1 local key = 1
@@ -42,4 +42,4 @@ Event.register(defines.events.on_tick, function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module DeconControl@4.0.0 -- @module DeconControl@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
@@ -23,40 +23,40 @@ local ThisModule = {
Event.register(-1,function(event) Event.register(-1,function(event)
Server.new_thread{ Server.new_thread{
name='tree-decon', name='tree-decon',
data={trees={},chache={},clear=0} data={trees={},cache={},clear=0}
}:on_event('tick',function(self) }:on_event('tick',function(self)
local trees = self.data.trees local trees = self.data.trees
if self.data.clear ~= 0 and self.data.clear < game.tick then self.data.chache = {} self.data.clear = 0 end if self.data.clear ~= 0 and self.data.clear < game.tick then self.data.cache = {} self.data.clear = 0 end
if #trees == 0 then return end if #trees == 0 then return end
for i = 0,math.ceil(#trees/10) do for i = 0,math.ceil(#trees/10) do
local tree = table.remove(trees,1) local tree = table.remove(trees,1)
if tree and tree.valid then tree.destroy() end if tree and tree.valid then tree.destroy() end
end end
end):on_event(defines.events.on_marked_for_deconstruction,function(self,event) end):on_event(defines.events.on_marked_for_deconstruction,function(self,event)
local chache = self.data.chache[event.player_index] local cache = self.data.cache[event.player_index]
if not chache then if not cache then
local player = Game.get_player(event) local player = Game.get_player(event)
if not player then return end if not player then return end
if not Role then if not Role then
if player.admin then self.data.chache[event.player_index] = {'tree-decon',false} if player.admin then self.data.cache[event.player_index] = {'tree-decon',false}
else self.data.chache[event.player_index] = {'decon',false} end else self.data.cache[event.player_index] = {'decon',false} end
else else
if Role.allowed(player,'tree-decon') then self.data.chache[event.player_index] = {'tree-decon',false} if Role.allowed(player,'tree-decon') then self.data.cache[event.player_index] = {'tree-decon',false}
elseif not Role.allowed(player,'decon') then self.data.chache[event.player_index] = {'no-decon',false} elseif not Role.allowed(player,'decon') then self.data.cache[event.player_index] = {'no-decon',false}
else self.data.chache[event.player_index] = {'decon',false} end else self.data.cache[event.player_index] = {'decon',false} end
end end
chache = self.data.chache[event.player_index] cache = self.data.cache[event.player_index]
end end
if not event.entity.last_user or event.entity.name == 'entity-ghost' then if not event.entity.last_user or event.entity.name == 'entity-ghost' then
if chache[1] == 'tree-decon' then if cache[1] == 'tree-decon' then
table.insert(self.data.trees,event.entity) table.insert(self.data.trees,event.entity)
self.data.clear = game.tick + 10 self.data.clear = game.tick + 10
end end
else else
if chache[1] == 'no-decon' then if cache[1] == 'no-decon' then
event.entity.cancel_deconstruction('player') event.entity.cancel_deconstruction('player')
if not chache[2] then if not cache[2] then
chache[2] = true cache[2] = true
local player = Game.get_player(event) local player = Game.get_player(event)
player_return({'DeconControl.player-print'},defines.textcolor.crit,player) player_return({'DeconControl.player-print'},defines.textcolor.crit,player)
Role.print(Role.meta.groups.Admin.lowest,{'DeconControl.rank-print',player.name},defines.textcolor.info) Role.print(Role.meta.groups.Admin.lowest,{'DeconControl.rank-print',player.name},defines.textcolor.info)
@@ -69,4 +69,4 @@ Event.register(-1,function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Ban@4.0.0 -- @module ExpGamingAdmin.Ban@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
@@ -27,11 +27,11 @@ AdminGui.add_button('Ban','utility/danger_icon',{'ExpGamingAdmin.tooltip-ban'},f
end) end)
function Admin.ban(player,by_player,reason) function Admin.ban(player,by_player,reason)
local player = Game.get_player(player) player = Game.get_player(player)
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>' local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>'
local reason = Admin.create_reason(reason,by_player_name) reason = Admin.create_reason(reason,by_player_name)
Admin.set_banned(player,true) Admin.set_banned(player,true)
if Sync then Sync.emit_embeded{ if Sync then Sync.emit_embedded{
title='Player Ban', title='Player Ban',
color=Color.to_hex(defines.textcolor.crit), color=Color.to_hex(defines.textcolor.crit),
description='There was a player banned.', description='There was a player banned.',

View File

@@ -1,8 +1,8 @@
--- Adds a function to clear a players inventoy and move the items to spawn. --- Adds a function to clear a players inventory and move the items to spawn.
-- @module ExpGamingAdmin.ClearInventory@4.0.0 -- @module ExpGamingAdmin.ClearInventory@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
@@ -13,7 +13,7 @@ local module_verbose = false
local ThisModule = {} local ThisModule = {}
-- Function Define -- Function Define
local inventorys = { local inventories = {
defines.inventory.player_main, defines.inventory.player_main,
defines.inventory.player_quickbar, defines.inventory.player_quickbar,
defines.inventory.player_trash, defines.inventory.player_trash,
@@ -23,7 +23,7 @@ local inventorys = {
} }
function Admin.move_item_to_spawn(item,surface,chests) function Admin.move_item_to_spawn(item,surface,chests)
local chests = chests or surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {} chests = chests or surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {}
local chest = nil local chest = nil
while not chest or not chest.get_inventory(defines.inventory.chest).can_insert(item) do while not chest or not chest.get_inventory(defines.inventory.chest).can_insert(item) do
chest = table.remove(chests,1) chest = table.remove(chests,1)
@@ -38,14 +38,14 @@ function Admin.move_item_to_spawn(item,surface,chests)
end end
function Admin.move_inventory(player) function Admin.move_inventory(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then return end if not player then return end
local chests = player.surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {} local chests = player.surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {}
for _,_inventory in pairs(inventorys) do for _,_inventory in pairs(inventories) do
local inventory = player.get_inventory(_inventory) local inventory = player.get_inventory(_inventory)
if inventory then if inventory then
for item,count in pairs(inventory.get_contents()) do for item,count in pairs(inventory.get_contents()) do
local item = {name=item,count=count} item = {name=item,count=count}
chests = Admin.move_item_to_spawn(item,player.surface,chests) chests = Admin.move_item_to_spawn(item,player.surface,chests)
end end
inventory.clear() inventory.clear()

View File

@@ -16,7 +16,7 @@ commands.add_command('report', 'Reports a player', {
if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player.name}) return commands.error end if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player.name}) return commands.error end
if Role.has_flag(player,'not_reportable') then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end if Role.has_flag(player,'not_reportable') then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end
for _,report in pairs(global.addons.reports.reports) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end for _,report in pairs(global.addons.reports.reports) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end
for _,report in pairs(global.addons.reports.varified) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end for _,report in pairs(global.addons.reports.verified) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player.name}) return commands.error end end
Admin.report(player,event.player_index,reason) Admin.report(player,event.player_index,reason)
end) end)

View File

@@ -24,5 +24,5 @@ commands.add_command('clear-warnings', 'Clears a player\'s warnings', {
}, function(event,args) }, function(event,args)
local player = args.player local player = args.player
if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player.name}) return commands.error end if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player.name}) return commands.error end
Admin.clear_warings(player,event.player_index) Admin.clear_warnings(player,event.player_index)
end) end)

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Gui@4.0.0 -- @module ExpGamingAdmin.Gui@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais AdminGui -- @alias AdminGui
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
@@ -10,7 +10,6 @@ local Gui = require('ExpGamingCore.Gui')
local Role = require('ExpGamingCore.Role') local Role = require('ExpGamingCore.Role')
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
local playerInfo -- ExpGamingPlayer.playerInfo@^4.0.0 local playerInfo -- ExpGamingPlayer.playerInfo@^4.0.0
local mod_gui = require('mod-gui')
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
@@ -42,7 +41,7 @@ function AdminGui.add_button(name,caption,tooltip,callback)
tooltip=tooltip tooltip=tooltip
}:on_event('click',function(event) }:on_event('click',function(event)
local parent = event.element.parent local parent = event.element.parent
pre_select_player = parent.player and parent.player.caption or nil local pre_select_player = parent.player and parent.player.caption or nil
callback(pre_select_player,event.player_index) callback(pre_select_player,event.player_index)
end) end)
end end
@@ -68,12 +67,12 @@ function AdminGui.draw(frame,filter_buttons)
end end
-- Gui Define -- Gui Define
local function _players(_player,root_frame,state) local function get_players(_player,root_frame,state)
local players = {'Select Player'} local players = {'Select Player'}
local _players = state and game.players or game.connected_players local _players = state and game.players or game.connected_players
for _,player in pairs(_players) do for _,player in pairs(_players) do
if player.name ~= _player.name then if player.name ~= _player.name then
if Admin.is_banned and Admin.is_banned(player) then else if not Admin.is_banned or not Admin.is_banned(player) then
table.insert(players,player.name) table.insert(players,player.name)
end end
end end
@@ -82,14 +81,14 @@ local function _players(_player,root_frame,state)
end end
local online_check = Gui.inputs.add_checkbox('online-check-admin-commands',false,'Show Offline',false,function(player,element) local online_check = Gui.inputs.add_checkbox('online-check-admin-commands',false,'Show Offline',false,function(player,element)
element.parent['player-drop-down-admin-commands'].items = _players(player,element.parent,true) element.parent['player-drop-down-admin-commands'].items = get_players(player,element.parent,true)
element.parent['player-drop-down-admin-commands'].selected_index = 1 element.parent['player-drop-down-admin-commands'].selected_index = 1
end,function(player,element) end,function(player,element)
element.parent['player-drop-down-admin-commands'].items = _players(player,element.parent,false) element.parent['player-drop-down-admin-commands'].items = get_players(player,element.parent,false)
element.parent['player-drop-down-admin-commands'].selected_index = 1 element.parent['player-drop-down-admin-commands'].selected_index = 1
end) end)
local player_drop_down = Gui.inputs.add_drop_down('player-drop-down-admin-commands',_players,1,function(player,selected,items,element) local player_drop_down = Gui.inputs.add_drop_down('player-drop-down-admin-commands',get_players,1,function(player,selected,items,element)
element.parent.parent.player.caption = selected element.parent.parent.player.caption = selected
local player_info_flow = element.parent.parent.info_flow local player_info_flow = element.parent.parent.info_flow
player_info_flow.clear() player_info_flow.clear()
@@ -142,7 +141,7 @@ Admin.center = Gui.center{
tooltip={'ExpGamingAdmin.tooltip'}, tooltip={'ExpGamingAdmin.tooltip'},
draw=function(self,frame,pre_select_player,pre_select_action) draw=function(self,frame,pre_select_player,pre_select_action)
frame.caption={'ExpGamingAdmin.name'} frame.caption={'ExpGamingAdmin.name'}
local frame = frame.add{ frame = frame.add{
type='flow', type='flow',
direction='horizontal' direction='horizontal'
} }
@@ -166,7 +165,7 @@ Admin.center = Gui.center{
online_check:draw(dropdowns) online_check:draw(dropdowns)
local _drop = player_drop_down:draw(dropdowns) local _drop = player_drop_down:draw(dropdowns)
if pre_select_player then Gui.set_dropdown_index(_drop,pre_select_player.name) end if pre_select_player then Gui.set_dropdown_index(_drop,pre_select_player.name) end
local _drop = action_drop_down:draw(dropdowns) _drop = action_drop_down:draw(dropdowns)
Gui.set_dropdown_index(_drop,pre_select_action) Gui.set_dropdown_index(_drop,pre_select_action)
local _text = reason_input:draw(dropdowns) local _text = reason_input:draw(dropdowns)
if pre_select_action == 'Jail' or pre_select_action == 'Kick' or pre_select_action == 'Ban' then if pre_select_action == 'Jail' or pre_select_action == 'Kick' or pre_select_action == 'Ban' then
@@ -174,7 +173,7 @@ Admin.center = Gui.center{
end end
if pre_select_player then playerInfo(pre_select_player,player_info_flow,true) end if pre_select_player then playerInfo(pre_select_player,player_info_flow,true) end
_text.style.width = 200 _text.style.width = 200
local label = dropdowns.add{ label = dropdowns.add{
name='warning', name='warning',
type='label', type='label',
caption='', caption='',
@@ -183,17 +182,17 @@ Admin.center = Gui.center{
label.style.single_line = false label.style.single_line = false
label.style.width = 200 label.style.width = 200
take_action:draw(dropdowns) take_action:draw(dropdowns)
local _caption = pre_select_player and pre_select_player.name or '' local caption = pre_select_player and pre_select_player.name or ''
frame.add{ frame.add{
name='player', name='player',
type='label', type='label',
caption=_caption caption=caption
}.style.visible = false }.style.visible = false
local _caption = pre_select_action or '' caption = pre_select_action or ''
frame.add{ frame.add{
name='action', name='action',
type='label', type='label',
caption=_caption caption=caption
}.style.visible = false }.style.visible = false
end end
} }

View File

@@ -2,14 +2,13 @@
-- @module ExpGamingAdmin.Jail@4.0.0 -- @module ExpGamingAdmin.Jail@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
local AdminGui = require('ExpGamingAdmin.Gui') local AdminGui = require('ExpGamingAdmin.Gui')
local Server = require('ExpGamingCore.Server') local Server = require('ExpGamingCore.Server')
local Role = require('ExpGamingCore.Role') local Role = require('ExpGamingCore.Role')
local Game = require('FactorioStdLib.Game')
local Color -- FactorioStdLib.Color@^0.8.0 local Color -- FactorioStdLib.Color@^0.8.0
local Sync -- ExpGamingCore.Sync@^4.0.0 local Sync -- ExpGamingCore.Sync@^4.0.0
@@ -28,11 +27,11 @@ AdminGui.add_button('jail','utility/clock',{'ExpGamingAdmin.tooltip-jail'},funct
end) end)
function Admin.jail(player,by_player,reason) function Admin.jail(player,by_player,reason)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
local reason = Admin.create_reason(reason,by_player.name) reason = Admin.create_reason(reason,by_player.name)
Admin.set_banned(player,'jail') Admin.set_banned(player,'jail')
if Sync then Sync.emit_embeded{ if Sync then Sync.emit_embedded{
title='Player Jail', title='Player Jail',
color=Color.to_hex(defines.textcolor.med), color=Color.to_hex(defines.textcolor.med),
description='There was a player jailed.', description='There was a player jailed.',

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Kick@4.0.0 -- @module ExpGamingAdmin.Kick@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
@@ -26,10 +26,10 @@ AdminGui.add_button('Kick','utility/warning_icon',{'ExpGamingAdmin.tooltip-kick'
end) end)
function Admin.kick(player,by_player,reason) function Admin.kick(player,by_player,reason)
local player = Game.get_player(player) player = Game.get_player(player)
reason = Admin.create_reason(reason,by_player_name)
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>' local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>'
local reason = Admin.create_reason(reason,by_player_name) if Sync then Sync.emit_embedded{
if Sync then Sync.emit_embeded{
title='Player Kick', title='Player Kick',
color=Color.to_hex(defines.textcolor.high), color=Color.to_hex(defines.textcolor.high),
description='There was a player kicked.', description='There was a player kicked.',

View File

@@ -2,11 +2,10 @@
-- @module ExpGamingAdmin.Reports@4.0.0 -- @module ExpGamingAdmin.Reports@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
local Server = require('ExpGamingCore.Server')
local Role = require('ExpGamingCore.Role') local Role = require('ExpGamingCore.Role')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
@@ -25,22 +24,22 @@ local ThisModule = {
-- Global Define -- Global Define
local global = global{ local global = global{
reports={}, reports={},
varified={} verified={}
} }
-- Local Varibles -- Local Variables
local report_to_warnings = 1 -- used in count_reports local report_to_warnings = 1 -- used in count_reports
local varified_to_warings = 3 -- used in count_reports local verified_to_warnings = 3 -- used in count_reports
local reports_needed_for_jail = 6 local reports_needed_for_jail = 6
-- Function Define -- Function Define
local function report_message(player,by_player,reason) local function report_message(player,by_player,reason)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
if Admin.is_banned(player,true) == 'report' then return end if Admin.is_banned(player,true) == 'report' then return end
Role.print(Role.meta.groups.User.lowest,{'ExpGamingAdmin.low-print',player.name,reason},defines.textcolor.info,true) Role.print(Role.meta.groups.User.lowest,{'ExpGamingAdmin.low-print',player.name,reason},defines.textcolor.info,true)
Role.print(Role.meta.groups.Admin.lowest,{'ExpGamingAdmin.high-print',player.name,by_player.name,reason},defines.textcolor.med) Role.print(Role.meta.groups.Admin.lowest,{'ExpGamingAdmin.high-print',player.name,by_player.name,reason},defines.textcolor.med)
if Sync then Sync.emit_embeded{ if Sync then Sync.emit_embedded{
title='Player Report', title='Player Report',
color=Color.to_hex(defines.textcolor.med), color=Color.to_hex(defines.textcolor.med),
description='A player was reported.', description='A player was reported.',
@@ -51,7 +50,7 @@ local function report_message(player,by_player,reason)
end end
local function cheak_reports(player) local function cheak_reports(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then return end if not player then return end
local reports = Admin.count_reports(player) local reports = Admin.count_reports(player)
if reports >= reports_needed_for_jail and Role.get_highest(player).group.name ~= 'Jail' then if reports >= reports_needed_for_jail and Role.get_highest(player).group.name ~= 'Jail' then
@@ -60,29 +59,29 @@ local function cheak_reports(player)
end end
function Admin.count_reports(player) function Admin.count_reports(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then return 0 end if not player then return 0 end
local _count = 0 local _count = 0
if global.reports[player.name] then if global.reports[player.name] then
for _,report in pairs(global.reports[player.name]) do for _ in pairs(global.reports[player.name]) do
_count=_count+report_to_warnings _count=_count+report_to_warnings
end end
end end
if global.varified[player.name] then if global.verified[player.name] then
for _,report in pairs(global.varified[player.name]) do for _ in pairs(global.verified[player.name]) do
_count=_count+varified_to_warings _count=_count+verified_to_warnings
end end
end end
return _count return _count
end end
function Admin.report(player,by_player,reason) function Admin.report(player,by_player,reason)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player or Role.has_flag(player,'not_reportable') then return end if not player or Role.has_flag(player,'not_reportable') then return end
if Admin.is_banned(by_player) or Role.has_flag(by_player,'is_jail') then return end if Admin.is_banned(by_player) or Role.has_flag(by_player,'is_jail') then return end
if Role.has_flag(by_player,'is_varified') then if Role.has_flag(by_player,'is_verified') then
global.varified[player.name] = global.varified[player.name] or {} global.verified[player.name] = global.verified[player.name] or {}
local reports = global.varified[player.name] local reports = global.verified[player.name]
for _,value in pairs(reports) do for _,value in pairs(reports) do
if value[1] == by_player.name then return end if value[1] == by_player.name then return end
end end
@@ -100,12 +99,12 @@ function Admin.report(player,by_player,reason)
end end
function Admin.clear_reports(player,by_player,no_emit) function Admin.clear_reports(player,by_player,no_emit)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
global.reports[player.name]={} global.reports[player.name]={}
global.varified[player.name]={} global.verified[player.name]={}
if not no_emit and Sync then if not no_emit and Sync then
Sync.emit_embeded{ Sync.emit_embedded{
title='Player Clear', title='Player Clear',
color=Color.to_hex(defines.textcolor.low), color=Color.to_hex(defines.textcolor.low),
description='A player had their reports cleared.', description='A player had their reports cleared.',
@@ -160,4 +159,4 @@ Admin.report_btn = Gui.inputs{
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Teleport@4.0.0 -- @module ExpGamingAdmin.Teleport@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.KicTempBan@4.0.0 -- @module ExpGamingAdmin.KicTempBan@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
@@ -27,7 +27,7 @@ function Admin.temp_ban(player,by_player,reason)
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>' local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>'
if not player or Admin.is_banned(player) then return end if not player or Admin.is_banned(player) then return end
Admin.set_banned(player,'temp') Admin.set_banned(player,'temp')
if Sync then Sync.emit_embeded{ if Sync then Sync.emit_embedded{
title='Player Temp-Ban', title='Player Temp-Ban',
color=Color.to_hex(defines.textcolor.high), color=Color.to_hex(defines.textcolor.high),
description='A player was jailed.', description='A player was jailed.',

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Warnings@4.0.0 -- @module ExpGamingAdmin.Warnings@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
@@ -12,7 +12,7 @@ local Game = require('FactorioStdLib.Game')
local Color -- FactorioStdLib.Color@^0.8.0 local Color -- FactorioStdLib.Color@^0.8.0
local Sync -- ExpGamingCore.Sync@^4.0.0 local Sync -- ExpGamingCore.Sync@^4.0.0
-- Local Varibles -- Local Variables
local take_action = 8 -- the first admin given warning jumps to this number, this case kick-warn is giving local take_action = 8 -- the first admin given warning jumps to this number, this case kick-warn is giving
local remove_warnings_time = {} local remove_warnings_time = {}
local min_time_to_remove_warning = 18000 -- this is in ticks local min_time_to_remove_warning = 18000 -- this is in ticks
@@ -61,10 +61,10 @@ local global = global{}
-- Function Define -- Function Define
local function give_punishment(player,by_player,reason) local function give_punishment(player,by_player,reason)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
reason = reason or 'No Other Reason'
local warnings = Admin.get_warnings(player) local warnings = Admin.get_warnings(player)
local punishment = punishments[warnings] local punishment = punishments[warnings]
local reason = reason or 'No Other Reason'
if not punishment or punishment[1] == 'nothing' then return if not punishment or punishment[1] == 'nothing' then return
elseif punishment[1] == 'message' then elseif punishment[1] == 'message' then
local message = punishment[2] local message = punishment[2]
@@ -85,14 +85,14 @@ local function give_punishment(player,by_player,reason)
end end
function Admin.get_warnings(player) function Admin.get_warnings(player)
local player = Game.get_player(player) player = Game.get_player(player)
return global[player.name] or 0 return global[player.name] or 0
end end
function Admin.give_warning(player,by_player,reason,min) function Admin.give_warning(player,by_player,reason,min)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
local min = Game.get_player(by_player) and Game.get_player(by_player) ~= SERVER and take_action or min or 0 min = Game.get_player(by_player) and Game.get_player(by_player) ~= SERVER and take_action or min or 0
local warnings = Admin.get_warnings(player) local warnings = Admin.get_warnings(player)
if warnings < min then warnings = min-1 end if warnings < min then warnings = min-1 end
warnings = warnings+1 warnings = warnings+1
@@ -104,12 +104,12 @@ function Admin.give_warning(player,by_player,reason,min)
give_punishment(player,by_player,reason) give_punishment(player,by_player,reason)
end end
function Admin.clear_warings(player,by_player,no_emit) function Admin.clear_warnings(player,by_player,no_emit)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
global[player.name]=nil global[player.name]=nil
if not no_emit and Sync then if not no_emit and Sync then
Sync.emit_embeded{ Sync.emit_embedded{
title='Player Clear', title='Player Clear',
color=Color.to_hex(defines.textcolor.low), color=Color.to_hex(defines.textcolor.low),
description='A player had their warnings cleared.', description='A player had their warnings cleared.',
@@ -138,4 +138,4 @@ script.on_event(defines.events.on_tick,function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin@4.0.0 -- @module ExpGamingAdmin@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais Admin -- @alias Admin
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
@@ -34,13 +34,13 @@ local global = global{
-- Function Define -- Function Define
function Admin.valid_players(player,by_player) function Admin.valid_players(player,by_player)
local player = Game.get_player(player) player = Game.get_player(player)
local by_player = Game.get_player(by_player) or SERVER by_player = Game.get_player(by_player) or SERVER
return player, by_player return player, by_player
end end
function Admin.create_reason(reason,name) function Admin.create_reason(reason,name)
local reason = reason or 'No Reason' reason = reason or 'No Reason'
if not string.find(string.lower(reason),string.lower(name)) then reason = reason..' - '..name end if not string.find(string.lower(reason),string.lower(name)) then reason = reason..' - '..name end
if Sync and Sync.info.date ~= '0000/00/00' and not string.find(string.lower(reason),Sync.info.date) then reason = reason..' - '..Sync.info.date end if Sync and Sync.info.date ~= '0000/00/00' and not string.find(string.lower(reason),Sync.info.date) then reason = reason..' - '..Sync.info.date end
if not string.find(string.lower(reason),'appeal') then reason = reason..' - Vist www.explosivegaming.nl to appeal.' end if not string.find(string.lower(reason),'appeal') then reason = reason..' - Vist www.explosivegaming.nl to appeal.' end
@@ -48,20 +48,20 @@ function Admin.create_reason(reason,name)
end end
function Admin.allowed(player) function Admin.allowed(player)
local player = Game.get_player(player) player = Game.get_player(player)
if Role then if Role then
return Role.allowed(player,'admin-commands') return Role.allowed(player,'admin-commands')
else return player.admin end else return player.admin end
end end
function Admin.set_banned(player,set) function Admin.set_banned(player,set)
local player=Game.get_player(player) player = Game.get_player(player)
if not player then return false end if not player then return false end
global.banned[player.name] = set global.banned[player.name] = set
end end
function Admin.is_banned(player,detail) function Admin.is_banned(player,detail)
local player=Game.get_player(player) player = Game.get_player(player)
if not player then return false end if not player then return false end
local banned = global.banned[player.name] local banned = global.banned[player.name]
if banned == true then return true end if banned == true then return true end
@@ -82,13 +82,13 @@ function Admin.take_action(action,player,by_player,reason)
end end
function Admin.clear_player(player,by_player) function Admin.clear_player(player,by_player)
local player, by_player = Admin.valid_players(player,by_player) player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
if Server and Admin.is_banned(player,true) == true then Server.interface(game.unban_player,true,player) end if Server and Admin.is_banned(player,true) == true then Server.interface(game.unban_player,true,player) end
if Admin.clear_warings then Admin.clear_warings(player,by_player,true) end if Admin.clear_warnings then Admin.clear_warnings(player,by_player,true) end
if Admin.clear_reports then Admin.clear_reports(player,by_player,true) end if Admin.clear_reports then Admin.clear_reports(player,by_player,true) end
if Server and Role.has_flag(player,'is_jail') then Server.interface(Role.revert,true,player,by_player,2) end if Server and Role.has_flag(player,'is_jail') then Server.interface(Role.revert,true,player,by_player,2) end
if Sync then Sync.emit_embeded{ if Sync then Sync.emit_embedded{
title='Player Clear', title='Player Clear',
color=Color.to_hex(defines.textcolor.low), color=Color.to_hex(defines.textcolor.low),
description='A player had their reports and warnings cleared.', description='A player had their reports and warnings cleared.',

View File

@@ -1,15 +1,15 @@
--- Sends messages in chat in resposce to other messages --- Sends messages in chat in response to other messages
-- @module ExpGamingBot.autoChat -- @module ExpGamingBot.autoChat
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
local Server = require('ExpGamingCore.Server') local Server = require('ExpGamingCore.Server')
local Role -- ExpGamingCore.Role@^4.0.0 local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles -- Local Variables
-- lots of these are jokes, but some have uses -- lots of these are jokes, but some have uses
-- white spaces removed and made into lower -- white spaces removed and made into lower
@@ -34,12 +34,12 @@ local messages = {
} }
-- white spaces removed and made into lower -- white spaces removed and made into lower
-- these are global chat commands that can be used -- these are global chat commands that can be used
-- comands start with ! (all messages are also commands) -- commands start with ! (all messages are also commands)
local command_syntax = '!' local command_syntax = '!'
local commands = { local commands = {
['online']=function(player) return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end, ['online']=function() return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end,
['playtime']=function(player) return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end, ['playtime']=function() return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end,
['players']=function(player) return {'ExpGamingBot-autoChat.players',#game.players} end, ['players']=function() return {'ExpGamingBot-autoChat.players',#game.players} end,
['dev']={'ExpGamingBot-autoChat.not-real-dev'}, ['dev']={'ExpGamingBot-autoChat.not-real-dev'},
['blame']=function(player) local names = {'Cooldude2606','arty714','badgamernl',player.name} return {'ExpGamingBot-autoChat.blame',names[math.random(#names)]} end, ['blame']=function(player) local names = {'Cooldude2606','arty714','badgamernl',player.name} return {'ExpGamingBot-autoChat.blame',names[math.random(#names)]} end,
['readme']={'ExpGamingBot-autoChat.read-readme'}, ['readme']={'ExpGamingBot-autoChat.read-readme'},
@@ -49,15 +49,17 @@ local commands = {
['lenny']={'ExpGamingBot-autoChat.lenny'}, ['lenny']={'ExpGamingBot-autoChat.lenny'},
['feedback']={'ExpGamingBot-autoChat.feedback'}, ['feedback']={'ExpGamingBot-autoChat.feedback'},
['wiki']={'ExpGamingBot-autoChat.wiki'}, ['wiki']={'ExpGamingBot-autoChat.wiki'},
['hodor']=function(player) local options = {'?','.','!','!!!'} return {'ExpGamingBot-autoChat.hodor',options[math.random(#options)]} end, ['hodor']=function() local options = {'?','.','!','!!!'} return {'ExpGamingBot-autoChat.hodor',options[math.random(#options)]} end,
['evolution']=function(player) return {'ExpGamingBot-autoChat.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end, ['evolution']=function() return {'ExpGamingBot-autoChat.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end,
--Jokes about food and drink --Jokes about food and drink
['whattoeat']={'ExpGamingBot-autoChat.food'}, ['whattoeat']={'ExpGamingBot-autoChat.food'},
['makepopcorn']=function(player) Server.new_thread{ ['makepopcorn']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end
end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end, end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end,
['orderpizza']=function(player) Server.new_thread{ ['orderpizza']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
@@ -66,6 +68,7 @@ local commands = {
end end
self.data[2]=self.data[2]+1 self.data[2]=self.data[2]+1
end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end, end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end,
['passsomesnaps']=function(player) Server.new_thread{ ['passsomesnaps']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
@@ -74,6 +77,7 @@ local commands = {
end end
self.data[2]=self.data[2]+1 self.data[2]=self.data[2]+1
end):open() return {'ExpGamingBot-autoChat.get-snaps-1'} end, end):open() return {'ExpGamingBot-autoChat.get-snaps-1'} end,
['makecocktail']=function(player) Server.new_thread{ ['makecocktail']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
@@ -82,11 +86,13 @@ local commands = {
end end
self.data[2]=self.data[2]+1 self.data[2]=self.data[2]+1
end):open() return {'ExpGamingBot-autoChat.get-cocktail-1'} end, end):open() return {'ExpGamingBot-autoChat.get-cocktail-1'} end,
['makecoffee']=function(player) Server.new_thread{ ['makecoffee']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-coffee-2',self.data}} end if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-coffee-2',self.data}} end
end):open() return {'ExpGamingBot-autoChat.make-coffee-1'} end, end):open() return {'ExpGamingBot-autoChat.make-coffee-1'} end,
['orderpizza']=function(player) Server.new_thread{ ['orderpizza']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
@@ -95,21 +101,25 @@ local commands = {
end end
self.data[2]=self.data[2] + 1 self.data[2]=self.data[2] + 1
end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end, end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end,
['maketea']=function(player) Server.new_thread{ ['maketea']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-tea-2',self.data}} end if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-tea-2',self.data}} end
end):open() return {'ExpGamingBot-autoChat.make-tea-1'} end, end):open() return {'ExpGamingBot-autoChat.make-tea-1'} end,
['popcorn']=function(player) Server.new_thread{ ['popcorn']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end
end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end, end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end,
['meadplease']=function(player) Server.new_thread{ ['meadplease']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-mead-2',self.data}} end if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-mead-2',self.data}} end
end):open() return {'ExpGamingBot-autoChat.get-mead-1'} end, end):open() return {'ExpGamingBot-autoChat.get-mead-1'} end,
['passabeer']=function(player) Server.new_thread{ ['passabeer']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
@@ -153,4 +163,4 @@ script.on_event(defines.events.on_console_chat,function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingBot.autoMessage -- @module ExpGamingBot.autoMessage
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Server = require('ExpGamingCore.Server') local Server = require('ExpGamingCore.Server')
@@ -10,7 +10,7 @@ local Game = require('FactorioStdLib.Game')
local Role -- ExpGamingCore.Role@4.0.0 local Role -- ExpGamingCore.Role@4.0.0
local Sync -- ExpGamingCore.Sync@4.0.0 local Sync -- ExpGamingCore.Sync@4.0.0
-- Local Varibles -- Local Variables
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
@@ -25,7 +25,7 @@ local ThisModule = {
} }
-- Event Handlers Define -- Event Handlers Define
script.on_init(function(event) script.on_init(function()
Server.new_thread{ Server.new_thread{
name='auto-message', name='auto-message',
timeout=54000, -- 3240000 = 15 hours dont make the mistake i did, 54000 is 15 minutes timeout=54000, -- 3240000 = 15 hours dont make the mistake i did, 54000 is 15 minutes
@@ -54,13 +54,12 @@ script.on_init(function(event)
local data = self.data local data = self.data
if not data.high_role or not data.low_role if not data.high_role or not data.low_role
or not data.low then self.reopen = false return end or not data.low then self.reopen = false return end
-- idk but this stoped working for no appent reason so i added more checks for nil values
if Role and Role.get_highest(player).index <= Role.get(data.low_role).index or player.admin then return end if Role and Role.get_highest(player).index <= Role.get(data.low_role).index or player.admin then return end
for _,message in pairs(data.low) do for _,message in pairs(data.low) do
player_return({'ExpGamingBot-autoMessage.message',message},nil,player) player_return({'ExpGamingBot-autoMessage.message',message},nil,player)
end end
end):on_event('error',function(self,err) end):on_event('error',function(self,err)
if Sync then Sync.emit_embeded{ if Sync then Sync.emit_embedded{
title='Auto Message Error', title='Auto Message Error',
color=Color.to_hex(defines.textcolor.bg), color=Color.to_hex(defines.textcolor.bg),
description='Auto Message Error - Closed Thread', description='Auto Message Error - Closed Thread',
@@ -72,4 +71,4 @@ script.on_init(function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingBot.discordAlerts@4.0.0 -- @module ExpGamingBot.discordAlerts@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Sync = require('ExpGamingCore.Sync') local Sync = require('ExpGamingCore.Sync')
@@ -23,7 +23,7 @@ script.on_event(defines.events.on_console_command,function(event)
data.by = event.player_index and game.players[event.player_index].name or '<server>' data.by = event.player_index and game.players[event.player_index].name or '<server>'
if data.by == '<server>' then return end if data.by == '<server>' then return end
if command == 'config' or command == 'banlist' then if command == 'config' or command == 'banlist' then
Sync.emit_embeded{ Sync.emit_embedded{
title='Edit To '..data.title, title='Edit To '..data.title,
color=Color.to_hex(defines.textcolor.bg), color=Color.to_hex(defines.textcolor.bg),
description='A player edited the '..command..'.', description='A player edited the '..command..'.',
@@ -48,7 +48,7 @@ script.on_event(defines.events.on_console_command,function(event)
if not Game.get_player(data.username) then return end if not Game.get_player(data.username) then return end
if string.sub(command,-1) == 'e' then data.command = command..'d' else data.command = command..'ed' end if string.sub(command,-1) == 'e' then data.command = command..'d' else data.command = command..'ed' end
data.reason = data.reason and data.reason ~= '' and data.reason or 'No Reason Required' data.reason = data.reason and data.reason ~= '' and data.reason or 'No Reason Required'
Sync.emit_embeded{ Sync.emit_embedded{
title='Player '..data.title, title='Player '..data.title,
color=data.colour, color=data.colour,
description='There was a player '..data.command..'.', description='There was a player '..data.command..'.',
@@ -60,4 +60,4 @@ script.on_event(defines.events.on_console_command,function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -37,7 +37,7 @@ script.on_event(defines.events.on_player_respawned,function(event)
end end
end) end)
-- overided by ExpGamingCore.Role if present -- overridden by ExpGamingCore.Role if present
script.on_event(defines.events.on_pre_player_died,function(event) script.on_event(defines.events.on_pre_player_died,function(event)
local player = Game.get_player(event) local player = Game.get_player(event)
if player.admin then if player.admin then
@@ -74,10 +74,10 @@ return {
script.on_event(defines.events.role_change,function(event) script.on_event(defines.events.role_change,function(event)
local player = Game.get_player(event) local player = Game.get_player(event)
if Role.allowed(player,'bonus') then if Role.allowed(player,'bonus') then
for _,setting in pairs(settings) do player[key] = setting*0.2 end for key,setting in pairs(settings) do player[key] = setting*0.2 end
global[player.index]=20 global[player.index]=20
else else
for _,setting in pairs(settings) do player[key] = 0 end for key in pairs(settings) do player[key] = 0 end
global[player.index]=nil global[player.index]=nil
end end
end) end)

View File

@@ -3,7 +3,7 @@
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
--- Toogles cheat mode for a player --- Toggles cheat mode for a player
-- @command cheat-mode -- @command cheat-mode
-- @param[opt] player the player to toggle if nil then the player using the command -- @param[opt] player the player to toggle if nil then the player using the command
commands.add_command('cheat-mode', 'Toggles cheat mode for a player', { commands.add_command('cheat-mode', 'Toggles cheat mode for a player', {

View File

@@ -25,7 +25,7 @@ commands.add_command('home', 'Allows you to set, remove and goto your homes', {
player_return{'ExpGamingCommands-home.set',name,pos[1],pos[2]} player_return{'ExpGamingCommands-home.set',name,pos[1],pos[2]}
elseif command == 'remove' then elseif command == 'remove' then
if not homes[name] then player_return{'ExpGamingCommands-home.invalid',name} end if not homes[name] then player_return{'ExpGamingCommands-home.invalid',name} end
homes[name] = nil homes[name] = nil
homes._n=homes._n-1 homes._n=homes._n-1
player_return{'ExpGamingCommands-home.remove',name} player_return{'ExpGamingCommands-home.remove',name}
elseif command == 'goto' then elseif command == 'goto' then
@@ -42,6 +42,6 @@ commands.add_command('home', 'Allows you to set, remove and goto your homes', {
else else
player_return{'ExpGamingCommands-home.homes',homes._n,homes._m} player_return{'ExpGamingCommands-home.homes',homes._n,homes._m}
local index = 1 local index = 1
for name,pos in pairs(homes) do if name ~= '_n' and name ~= '_r' and name ~= '_m' then player_return{'ExpGamingCommands-home.home',index,name,pos[1],pos[2]} index=index+1 end end for home_name,pos in pairs(homes) do if home_name ~= '_n' and home_name ~= '_r' and home_name ~= '_m' then player_return{'ExpGamingCommands-home.home',index,home_name,pos[1],pos[2]} index=index+1 end end
end end
end) end)

View File

@@ -28,7 +28,7 @@ local ThisModule = {
end end
} }
--- Used so that the value can be overriden if tempban is present --- Used so that the value can be overridden if tempban is present
-- @local -- @local
-- @function repairDisallow -- @function repairDisallow
-- @param player the player who called the command -- @param player the player who called the command
@@ -41,7 +41,7 @@ end
--- Used to repair and heal items in an area, different ranks get different size areas --- Used to repair and heal items in an area, different ranks get different size areas
-- @command repair -- @command repair
-- @param range the range that items are repaired in -- @param range the range that items are repaired in
commands.add_command('repair', 'Repairs all destoryed and damaged entites in an area.', { commands.add_command('repair', 'Repairs all destroyed and damaged entities in an area.', {
['range']={true,'number-int'} ['range']={true,'number-int'}
}, function(event,args) }, function(event,args)
local range = args.range local range = args.range

View File

@@ -13,7 +13,7 @@ local Color = require('FactorioStdLib.Color')
-- @usage return commands.error('err message') -- @usage return commands.error('err message')
commands.error = setmetatable({},{__call=function(...) return ... end}) commands.error = setmetatable({},{__call=function(...) return ... end})
commands._add_command = commands.add_command commands._add_command = commands.add_command
local data = {} local commandDataStore = {}
local middleware = {} local middleware = {}
--- Used to add middle ware to the command handler, functions should return true or false --- Used to add middle ware to the command handler, functions should return true or false
@@ -27,10 +27,10 @@ function commands.add_middleware(callback) if not is_type(callback,'function') t
-- @tparam ?string|table|event key the command that will be returned: string is the name, table is the command data, event is event from add_command -- @tparam ?string|table|event key the command that will be returned: string is the name, table is the command data, event is event from add_command
-- @treturn table the command data -- @treturn table the command data
setmetatable(commands,{ setmetatable(commands,{
__index=function(tbl,key) return is_type(key,'table') and (key.command and rawget(data,key.name) or key) or key == 'data' and data or rawget(data,key) end __index=function(tbl,key) return is_type(key,'table') and (key.command and rawget(commandDataStore,key.name) or key) or key == 'data' and commandDataStore or rawget(commandDataStore,key) end
}) })
--- Collection of funcations that can be used to validate inputs --- Collection of functions that can be used to validate inputs
-- @table commands.validate -- @table commands.validate
-- @usage commands.validate[type](value,event,...) -- @usage commands.validate[type](value,event,...)
-- @tparam string type the type that the value should be -- @tparam string type the type that the value should be
@@ -40,11 +40,11 @@ setmetatable(commands,{
-- @return[2] error constant -- @return[2] error constant
-- @return[2] the err message -- @return[2] the err message
-- @field __comment replace _ with - the ldoc did not like me using - in the names -- @field __comment replace _ with - the ldoc did not like me using - in the names
-- @field string basicly does nothing but a type filed is required -- @field string basically does nothing but a type filed is required
-- @field string_inf same as string but is infite in length, must be last arg -- @field string_inf same as string but is infinite in length, must be last arg
-- @field string_len same as string but can define a max lengh -- @field string_len same as string but can define a max length
-- @field number converts the input into a number -- @field number converts the input into a number
-- @field number_int conerts the input to a number and floors it -- @field number_int converts the input to a number and floors it
-- @field number_range allows a number in a range min < X <= max -- @field number_range allows a number in a range min < X <= max
-- @field number_range allows a number in a range after it has been floored min < math.floor(X) <= max -- @field number_range allows a number in a range after it has been floored min < math.floor(X) <= max
-- @field player converts the input into a valid player -- @field player converts the input into a valid player
@@ -54,54 +54,54 @@ setmetatable(commands,{
-- @field player_role-online converts the input to a player if the player is a lower rank than the user and online -- @field player_role-online converts the input to a player if the player is a lower rank than the user and online
-- @field player_role_alive converts the input to a player if the player is a lower rank than the user and online and alive -- @field player_role_alive converts the input to a player if the player is a lower rank than the user and online and alive
commands.validate = { commands.validate = {
['boolean']=function(value,event) local value = value.lower() if value == 'true' or valule == 'yes' or value == 'y' or value == '1' then return true else return false end end, ['boolean']=function(value) value = value.lower() if value == 'true' or value == 'yes' or value == 'y' or value == '1' then return true else return false end end,
['string']=function(value,event) return tostring(value) end, ['string']=function(value) return tostring(value) end,
['string-inf']=function(value,event) return tostring(value) end, ['string-inf']=function(value) return tostring(value) end,
['string-list']=function(value,event,list) ['string-list']=function(value,event,list)
local rtn = tostring(value) and table.includes(list,tostring(value)) and tostring(value) or nil local rtn = tostring(value) and table.includes(list,tostring(value)) and tostring(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-string-list',table.concat(list,', ')} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-string-list',table.concat(list,', ')} end return rtn end,
['string-len']=function(value,event,max) ['string-len']=function(value,event,max)
local rtn = tostring(value) and tostring(value):len() <= max and tostring(value) or nil local rtn = tostring(value) and tostring(value):len() <= max and tostring(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len',max} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len',max} end return rtn end,
['number']=function(value,event) ['number']=function(value)
local rtn = tonumber(value) or nil local rtn = tonumber(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
['number-int']=function(value,event) ['number-int']=function(value)
local rtn = tonumber(value) and math.floor(tonumber(value)) or nil local rtn = tonumber(value) and math.floor(tonumber(value)) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
['number-range']=function(value,event,min,max) ['number-range']=function(value,event,min,max)
local rtn = tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or nil local rtn = tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end,
['number-range-int']=function(value,event,min,max) ['number-range-int']=function(value,event,min,max)
local rtn = tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or nil local rtn = tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end,
['player']=function(value,event) ['player']=function(value)
local rtn = Game.get_player(value) or nil local rtn = Game.get_player(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end,
['player-online']=function(value,event) ['player-online']=function(value)
local player,err = commands.validate['player'](value) local player,err = commands.validate['player'](value)
if err then return commands.error(err) end if err then return commands.error(err) end
local rtn = player.connected and player or nil local rtn = player.connected and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-online'} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-player-online'} end return rtn end,
['player-alive']=function(value,event) ['player-alive']=function(value)
local player,err = commands.validate['player-online'](value) local player,err = commands.validate['player-online'](value)
if err then return commands.error(err) end if err then return commands.error(err) end
local rtn = player.character and player.character.health > 0 and player or nil local rtn = player.character and player.character.health > 0 and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-alive'} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-player-alive'} end return rtn end,
['player-rank']=function(value,event) ['player-rank']=function(value,event)
local player,err = commands.validate['player'](value) local player,err = commands.validate['player'](value)
if err then return commands.error(err) end if err then return commands.error(err) end
local rtn = player.admin and Game.get_player(event).admin and player or nil local rtn = player.admin and Game.get_player(event).admin and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-rank'} end return rtn end, if not rtn then return commands.error{'ExpGamingCore_Command.error-player-rank'} end return rtn end,
['player-rank-online']=function(value,event) ['player-rank-online']=function(value)
local player,err = commands.validate['player-online'](value) local player,err = commands.validate['player-online'](value)
if err then return commands.error(err) end if err then return commands.error(err) end
local player,err = commands.validate['player-rank'](player) local player,err = commands.validate['player-rank'](player)
if err then return commands.error(err) end return player end, if err then return commands.error(err) end return player end,
['player-rank-alive']=function(value,event) ['player-rank-alive']=function(value)
local player,err = commands.validate['player-alive'](value) local player,err = commands.validate['player-alive'](value)
if err then return commands.error(err) end if err then return commands.error(err) end
local player,err = commands.validate['player-rank'](player) local player,err = commands.validate['player-rank'](player)
if err then return commands.error(err) end return player end, if err then return commands.error(err) end return player end,
} }
--- Adds a function to the validation list --- Adds a function to the validation list
@@ -114,7 +114,7 @@ function commands.add_validation(name,callback) if not is_type(callback,'functio
-- @tparam ?string|table|event command the command to get the inputs of -- @tparam ?string|table|event command the command to get the inputs of
-- @treturn string the formated string for the inputs -- @treturn string the formated string for the inputs
function commands.format_inputs(command) function commands.format_inputs(command)
local command = commands[command] command = commands[command]
if not is_type(command,'table') then error('Command is not valid',2) end if not is_type(command,'table') then error('Command is not valid',2) end
local rtn = '' local rtn = ''
for name,data in pairs(command.inputs) do for name,data in pairs(command.inputs) do
@@ -136,13 +136,13 @@ function commands.validate_args(event)
local rtn = {} local rtn = {}
local count = 0 local count = 0
local count_opt = 0 local count_opt = 0
for name,data in pairs(command.inputs) do count = count + 1 if data[1] == false then count_opt = count_opt + 1 end end for _,data in pairs(command.inputs) do count = count + 1 if data[1] == false then count_opt = count_opt + 1 end end
-- checks that there is some args given if there is ment to be -- checks that there is some args given if there is meant to be
if not event.parameter then if not event.parameter then
if count == count_opt then return rtn if count == count_opt then return rtn
else return commands.error('invalid-inputs') end else return commands.error('invalid-inputs') end
end end
-- splits the args into words so that it can be used to asign values -- splits the args into words so that it can be used to assign values
local words = string.split(event.parameter,' ') local words = string.split(event.parameter,' ')
local index = 0 local index = 0
for _,word in pairs(words) do for _,word in pairs(words) do
@@ -158,7 +158,7 @@ function commands.validate_args(event)
end end
end end
-- assigns the values from the words to the args -- assigns the values from the words to the args
local index = 0 index = 0
for name,data in pairs(command.inputs) do for name,data in pairs(command.inputs) do
index = index+1 index = index+1
local arg = words[index] local arg = words[index]
@@ -178,10 +178,10 @@ end
-- @tparam ?index|name|player| player the player to test as -- @tparam ?index|name|player| player the player to test as
-- @treturn table a table containg all the commands the player can use -- @treturn table a table containg all the commands the player can use
function commands.get_commands(player) function commands.get_commands(player)
player = Game.get_player(player)
local commands = {} local commands = {}
local player = Game.get_player(player)
if not player then return error('Invalid player',2) end if not player then return error('Invalid player',2) end
for name,data in pairs(data) do for name,data in pairs(commandDataStore) do
if #middleware > 0 then for _,callback in pairs(middleware) do if #middleware > 0 then for _,callback in pairs(middleware) do
local success, err = pcall(callback,player,name,data) local success, err = pcall(callback,player,name,data)
if not success then error(err) if not success then error(err)
@@ -207,7 +207,7 @@ end
local function run_custom_command(command) local function run_custom_command(command)
local data = commands.data[command.name] local data = commands.data[command.name]
local player = Game.get_player(command) or SERVER local player = Game.get_player(command) or SERVER
-- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only -- runs all middle ware if any, if there is no middle where then it relies on .default_admin_only
if #middleware > 0 then for _,callback in pairs(middleware) do if #middleware > 0 then for _,callback in pairs(middleware) do
local success, err = pcall(callback,player,command.name,command) local success, err = pcall(callback,player,command.name,command)
if not success then error(err) if not success then error(err)
@@ -243,7 +243,7 @@ end
-- @usage --see examples in file -- @usage --see examples in file
-- @tparam string name the name of the command -- @tparam string name the name of the command
-- @tparam[opt='No Description'] string description the description of the command -- @tparam[opt='No Description'] string description the description of the command
-- @tparam[opt=an infite string] table inputs a table of the inputs to be used, last index being true makes the last parameter open ended (longer than one word) -- @tparam[opt=an infinite string] table inputs a table of the inputs to be used, last index being true makes the last parameter open ended (longer than one word)
-- @tparam function callback the function to call on the event -- @tparam function callback the function to call on the event
commands.add_command = function(name, description, inputs, callback) commands.add_command = function(name, description, inputs, callback)
if commands[name] then error('That command is already registered',2) end if commands[name] then error('That command is already registered',2) end
@@ -254,11 +254,11 @@ commands.add_command = function(name, description, inputs, callback)
end end
verbose('Created Command: '..name) verbose('Created Command: '..name)
-- test for string and then test for locale string -- test for string and then test for locale string
local description = is_type(description,'string') and description description = is_type(description,'string') and description
or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,''} or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,''}
or 'No Description' or 'No Description'
local inputs = is_type(inputs,'table') and inputs or {['param']={false,'string-inf'}} inputs = is_type(inputs,'table') and inputs or {['param']={false,'string-inf'}}
data[name] = { commandDataStore[name] = {
name=name, name=name,
description=description, description=description,
inputs=inputs, inputs=inputs,
@@ -268,12 +268,12 @@ commands.add_command = function(name, description, inputs, callback)
local help = is_type(description,'string') and commands.format_inputs(name)..'- '..description local help = is_type(description,'string') and commands.format_inputs(name)..'- '..description
or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,commands.format_inputs(name)..'- '} or is_type(description,'table') and is_type(description[1],'string') and string.find(description[1],'.+[.].+') and {description,commands.format_inputs(name)..'- '}
or commands.format_inputs(name) or commands.format_inputs(name)
data[name].help = help commandDataStore[name].help = help
commands._add_command(name,help,function(...) commands._add_command(name,help,function(...)
local success, err = Manager.sandbox(run_custom_command,{},...) local success, err = Manager.sandbox(run_custom_command,{},...)
if not success then error(err) end if not success then error(err) end
end) end)
return data[name] return commandDataStore[name]
end end
return commands return commands
@@ -289,8 +289,8 @@ return commands
commands.add_command('foo',{'foo.description'},{ commands.add_command('foo',{'foo.description'},{
['player']={true,'player'}, -- a required arg that must be a valid player ['player']={true,'player'}, -- a required arg that must be a valid player
['number']={true,'number-range',0,10}, -- a required arg that must be a number 0<X<=10 ['number']={true,'number-range',0,10}, -- a required arg that must be a number 0<X<=10
['pwd']={true,function(value,event) if value == 'password123' then return true else return commands.error('Invalid Password') end} -- a requireed arg pwd that has custom validation ['pwd']={true,function(value,event) if value == 'password123' then return true else return commands.error('Invalid Password') end} -- a required arg pwd that has custom validation
['reason']={false,'string-inf'} -- an optinal arg that is and infite lengh (useful for reasons) ['reason']={false,'string-inf'} -- an optional arg that is and infinite length (useful for reasons)
},function(event,args) },function(event,args)
args.player.print(args.number) args.player.print(args.number)
if args.reasons then args.player.print(args.reason) end if args.reasons then args.player.print(args.reason) end

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingCore@Group -- @module ExpGamingCore@Group
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais Group -- @alias Group
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
@@ -14,24 +14,26 @@ local module_verbose = false
-- @type Group -- @type Group
-- @field _prototype the prototype of this class -- @field _prototype the prototype of this class
-- @field groups a table of all groups, includes auto complete on the indexing -- @field groups a table of all groups, includes auto complete on the indexing
local _GroupSelfRef
local Group = { local Group = {
_prototype = {}, _prototype = {},
groups = setmetatable({},{ groups = setmetatable({},{
__index=table.autokey, __index=table.autokey,
__newindex=function(tbl,key,value) __newindex=function(tbl,key,value)
rawset(tbl,key,Group.define(value)) rawset(tbl,key,_GroupSelfRef.define(value))
end end
}), }),
on_init = function() on_init = function()
if loaded_modules['ExpGamingCore.Server'] then require('ExpGamingCore.Server') end if loaded_modules['ExpGamingCore.Server'] then require('ExpGamingCore.Server') end
end, end,
on_post = function(self) on_post = function(self)
-- creats a root role that the server can use -- creates a root role that the server can use
self{name='Root',disallow={}} self{name='Root',disallow={}}
-- loads the groups in config -- loads the groups in config
require(module_path..'/config',{Group=self}) require(module_path..'/config',{Group=self})
end end
} }
_GroupSelfRef=Group
-- Function Define -- Function Define
@@ -75,9 +77,9 @@ end
-- @tparam ?string|LuaPermissionGroup the group to add the player to -- @tparam ?string|LuaPermissionGroup the group to add the player to
-- @treturn boolean was the player assigned -- @treturn boolean was the player assigned
function Group.assign(player,group) function Group.assign(player,group)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to Group.assign.',2) return end if not player then error('Invalid player #1 given to Group.assign.',2) return end
local group = Group.get(group) group = Group.get(group)
if not group then error('Invalid group #2 given to Group.assign.',2) return end if not group then error('Invalid group #2 given to Group.assign.',2) return end
return group:add_player(player) return group:add_player(player)
end end
@@ -98,7 +100,7 @@ end
-- @treturn boolean if the player was added -- @treturn boolean if the player was added
function Group._prototype:add_player(player) function Group._prototype:add_player(player)
if not self_test(self,'group','add_player') then return end if not self_test(self,'group','add_player') then return end
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to group.add_player.',2) return end if not player then error('Invalid player #1 given to group.add_player.',2) return end
local raw_group = self:get_raw() local raw_group = self:get_raw()
return raw_group.add_player(player) return raw_group.add_player(player)
@@ -110,7 +112,7 @@ end
-- @treturn boolean if the player was removed -- @treturn boolean if the player was removed
function Group._prototype:remove_player(player) function Group._prototype:remove_player(player)
if not self_test(self,'group','remove_player') then return end if not self_test(self,'group','remove_player') then return end
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to group.remove_player.',2) return end if not player then error('Invalid player #1 given to group.remove_player.',2) return end
local raw_group = self:get_raw() local raw_group = self:get_raw()
return raw_group.remove_player(player) return raw_group.remove_player(player)
@@ -134,18 +136,18 @@ end
-- this is used to create a connected_players table -- this is used to create a connected_players table
Group._prototype.connected_players_mt = { Group._prototype.connected_players_mt = {
__call=function(tbl) return tbl.self:get_players(true) end, __call=function(tbl) return tbl.self:get_players(true) end,
__pairs=function(tbl) __pairs=function(self)
local players = tbl.self:get_players(true) local players = self.self:get_players(true)
local function next_pair(tbl,k) local function next_pair(tbl,key)
k, v = next(players, k) local k, v = next(players, key)
if v then return k,v end if v then return k,v end
end end
return next_pair, players, nil return next_pair, players, nil
end, end,
__ipairs=function(tbl) __ipairs=function(self)
local players = tbl.self:get_players(true) local players = self.self:get_players(true)
local function next_pair(tbl,k) local function next_pair(tbl,key)
k, v = next(players, k) local k, v = next(players, key)
if v then return k,v end if v then return k,v end
end end
return next_pair, players, nil return next_pair, players, nil
@@ -156,7 +158,7 @@ Group._prototype.connected_players_mt = {
-- @usage group.print('Hello, World!') -- @usage group.print('Hello, World!')
-- @param rtn any value you wish to print, string not required -- @param rtn any value you wish to print, string not required
-- @param colour the colour to print the message in -- @param colour the colour to print the message in
-- @treturn number the number of players who recived the message -- @treturn number the number of players who received the message
function Group._prototype:print(rtn,colour) function Group._prototype:print(rtn,colour)
if not self_test(self,'group','print') then return end if not self_test(self,'group','print') then return end
if colour and not type_error(colour,'table','Invalid argument #2 to group:print, colour is not a table.') then return end if colour and not type_error(colour,'table','Invalid argument #2 to group:print, colour is not a table.') then return end
@@ -169,7 +171,7 @@ end
-- Event Handlers Define -- Event Handlers Define
-- creates all permission groups and links them -- creates all permission groups and links them
script.on_event('on_init',function(event) script.on_event('on_init',function()
for name,group in pairs(Group.groups) do for name,group in pairs(Group.groups) do
local _group = game.permissions.create_group(name) local _group = game.permissions.create_group(name)
verbose('Created Permission Group: '..name) verbose('Created Permission Group: '..name)

View File

@@ -15,11 +15,11 @@ center._prototype = {}
--- Adds a new obj to the center gui --- Adds a new obj to the center gui
-- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function} -- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function}
-- @usage return_value(player) -- opens the center gui for that player -- @usage return_value(player) -- opens the center gui for that player
-- @param obj contains the new object, needs name, fraw is opt and is function(root_frame) -- @param obj contains the new object, needs name, frame is opt and is function(root_frame)
-- @return the object made, used to add tabs, calling the returned value will open the center for the given player -- @return the object made, used to add tabs, calling the returned value will open the center for the given player
function center.add(obj) function center.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end if not is_type(obj.name,'string') then return end
verbose('Created Center Gui: '..obj.name) verbose('Created Center Gui: '..obj.name)
setmetatable(obj,{__index=center._prototype,__call=function(self,player,...) return center.open(player,self.name,...) end}) setmetatable(obj,{__index=center._prototype,__call=function(self,player,...) return center.open(player,self.name,...) end})
obj.tabs = {} obj.tabs = {}
@@ -30,32 +30,32 @@ function center.add(obj)
end end
--- Used to get the center frame of the player, used mainly in script --- Used to get the center frame of the player, used mainly in script
-- @usage Gui.center.get_flow(player) -- returns gui emelemt -- @usage Gui.center.get_flow(player) -- returns gui element
-- @param player a player indifier to get the flow for -- @param player a player identifier to get the flow for
-- @treturn table the gui element flow -- @treturn table the gui element flow
function center.get_flow(player) function center.get_flow(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player',2) end if not player then error('Invalid player',2) end
return player.gui.center.exp_center or player.gui.center.add{name='exp_center',type='flow'} return player.gui.center.exp_center or player.gui.center.add{name='exp_center',type='flow'}
end end
--- Used to open a center frame for a player, extra params are sent to open event --- Used to open a center frame for a player, extra params are sent to open event
-- @usage Gui.center.open(player,'server-info') -- return true -- @usage Gui.center.open(player,'server-info') -- return true
-- @param player a player indifier to get the flow for -- @param player a player identifier to get the flow for
-- @tparam string center the name of the center frame to open -- @tparam string center_name the name of the center frame to open
-- @treturn boelon based on if it successed or not -- @treturn boolean based on if it succeeded or not
function center.open(player,center,...) function center.open(player,center_name,...)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player',2) return false end if not player then error('Invalid player',2) return false end
Gui.center.clear(player) Gui.center.clear(player)
if not Gui.data.center[center] then return false end if not Gui.data.center[center_name] then return false end
local self = Gui.data.center[center] local self = Gui.data.center[center_name]
-- this function is the draw function passed to the open event -- this function is the draw function passed to the open event
self:open(player,function(...) Gui.center._draw(self,...) end,...) self:open(player,function(...) Gui.center._draw(self,...) end,...)
return true return true
end end
-- used as a pice of middle ware for the open event -- used as a piece of middle ware for the open event
function center._draw(self,frame,...) function center._draw(self,frame,...)
game.players[frame.player_index].opened=frame game.players[frame.player_index].opened=frame
if is_type(self.draw,'function') then if is_type(self.draw,'function') then
@@ -66,37 +66,37 @@ end
--- Used to open a center frame for a player --- Used to open a center frame for a player
-- @usage Gui.center.open_tab(player,'readme','rules') -- return true -- @usage Gui.center.open_tab(player,'readme','rules') -- return true
-- @param player a player indifier to get the flow for -- @param player a player identifier to get the flow for
-- @tparam string center the name of the center frame to open -- @tparam string center the name of the center frame to open
-- @tparam string tab the name of the tab to open -- @tparam string tab the name of the tab to open
-- @treturn boelon based on if it successed or not -- @treturn boolean based on if it succeeded or not
function center.open_tab(player,center,tab) function center.open_tab(player,center_name,tab)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player',2) end if not player then error('Invalid player',2) end
if not Gui.center.open(player,center) then return false end if not Gui.center.open(player,center_name) then return false end
local name = center..'_'..tab local name = center_name..'_'..tab
if not Gui.data.inputs_button[name] then return false end if not Gui.data.inputs_button[name] then return false end
Gui.data.inputs_button[name].events[defines.events.on_gui_click]{ Gui.data.inputs_button[name].events[defines.events.on_gui_click]{
element=Gui.center.get_flow(player)[center].tab_bar.tab_bar_scroll.tab_bar_scroll_flow[name], element=Gui.center.get_flow(player)[center_name].tab_bar.tab_bar_scroll.tab_bar_scroll_flow[name],
} }
return true return true
end end
--- Used to clear the center frame of the player, used mainly in script --- Used to clear the center frame of the player, used mainly in script
-- @usage Gui.center.clear(player) -- @usage Gui.center.clear(player)
-- @param player a player indifier to get the flow for -- @param player a player identifier to get the flow for
function center.clear(player) function center.clear(player)
local player = Game.get_player(player) player = Game.get_player(player)
center.get_flow(player).clear() center.get_flow(player).clear()
end end
-- opens this gui for this player, draw is the draw function when event is called from center.open -- opens this gui for this player, draw is the draw function when event is called from center.open
-- this is the default function it can be overriden when the gui is defined, simply call draw on the frame you create -- this is the default function it can be overridden when the gui is defined, simply call draw on the frame you create
-- extra values passed to draw will also be passed to the draw event -- extra values passed to draw will also be passed to the draw event
-- extra values from center.draw and passed to the open event -- extra values from center.draw and passed to the open event
function center._prototype:open(player,draw,...) function center._prototype:open(player,draw,...)
local player = Game.get_player(player) player = Game.get_player(player)
local draw = draw or function(...) center._draw(self,...) end draw = draw or function(...) center._draw(self,...) end
local center_flow = center.get_flow(player) local center_flow = center.get_flow(player)
if center_flow[self.name] then Gui.center.clear(player) return end if center_flow[self.name] then Gui.center.clear(player) return end
local center_frame = center_flow.add{ local center_frame = center_flow.add{
@@ -110,8 +110,8 @@ function center._prototype:open(player,draw,...)
draw(center_frame,...) draw(center_frame,...)
end end
-- this is the default draw function if one is not provided, can be overriden -- this is the default draw function if one is not provided, can be overridden
-- not recomented for direct use see Gui.center.open -- not recommended for direct use see Gui.center.open
function center._prototype:draw(frame) function center._prototype:draw(frame)
Gui.bar(frame,510) Gui.bar(frame,510)
local tab_bar = frame.add{ local tab_bar = frame.add{
@@ -123,8 +123,8 @@ function center._prototype:draw(frame)
tab_bar.style.width = 510 tab_bar.style.width = 510
tab_bar.style.height = 65 tab_bar.style.height = 65
local tab_bar_scroll = tab_bar.add{ local tab_bar_scroll = tab_bar.add{
type='scroll-pane', type='scroll-pane',
name='tab_bar_scroll', name='tab_bar_scroll',
horizontal_scroll_policy='auto-and-reserve-space', horizontal_scroll_policy='auto-and-reserve-space',
vertical_scroll_policy='never' vertical_scroll_policy='never'
} }
@@ -147,7 +147,7 @@ function center._prototype:draw(frame)
tab.style.height = 305 tab.style.height = 305
local tab_scroll = tab.add{ local tab_scroll = tab.add{
type ='scroll-pane', type ='scroll-pane',
name='tab_scroll', name='tab_scroll',
horizontal_scroll_policy='never', horizontal_scroll_policy='never',
vertical_scroll_policy='auto' vertical_scroll_policy='auto'
} }
@@ -155,8 +155,8 @@ function center._prototype:draw(frame)
tab_scroll.style.vertically_stretchable = true tab_scroll.style.vertically_stretchable = true
tab_scroll.style.width = 500 tab_scroll.style.width = 500
local tab_scroll_flow = tab_scroll.add{ local tab_scroll_flow = tab_scroll.add{
type='flow', type='flow',
name='tab_scroll_flow', name='tab_scroll_flow',
direction='vertical' direction='vertical'
} }
tab_scroll_flow.style.width = 480 tab_scroll_flow.style.width = 480
@@ -171,7 +171,7 @@ function center._prototype:draw(frame)
frame.parent.add{type='frame',name='temp'}.destroy()--recenter the GUI frame.parent.add{type='frame',name='temp'}.destroy()--recenter the GUI
end end
--- If deafult draw is used then you can add tabs to the gui with this function --- If default draw is used then you can add tabs to the gui with this function
-- @usage _center:add_tab('foo','Foo','Just a tab',function) -- @usage _center:add_tab('foo','Foo','Just a tab',function)
-- @tparam string name this is the name of the tab -- @tparam string name this is the name of the tab
-- @tparam string caption this is the words that appear on the tab button -- @tparam string caption this is the words that appear on the tab button
@@ -214,7 +214,7 @@ end)
script.on_event(defines.events.on_player_respawned,center.clear) script.on_event(defines.events.on_player_respawned,center.clear)
function center:on_init() function center.on_init()
if loaded_modules['ExpGamingCore.Role'] then script.on_event(defines.events.on_role_change,center.clear) end if loaded_modules['ExpGamingCore.Role'] then script.on_event(defines.events.on_role_change,center.clear) end
end end
-- calling will attempt to add a new gui -- calling will attempt to add a new gui

View File

@@ -16,7 +16,7 @@ local global = global()
-- @tparam string location the location to get/set the data, center left etc... -- @tparam string location the location to get/set the data, center left etc...
-- @tparam[opt] string key the name of the gui to set the value of -- @tparam[opt] string key the name of the gui to set the value of
-- @param[opt] value the data that will be set can be any value but table advised -- @param[opt] value the data that will be set can be any value but table advised
-- @treturn[1] table all the gui data that is locationed in that location -- @treturn[1] table all the gui data that is located in that location
Gui.data = setmetatable({},{ Gui.data = setmetatable({},{
__call=function(tbl,location,key,value) __call=function(tbl,location,key,value)
if not location then return tbl end if not location then return tbl end
@@ -31,7 +31,7 @@ Gui.data = setmetatable({},{
-- @usage Gui.bar(frame,100) -- @usage Gui.bar(frame,100)
-- @param frame the frame to draw the line to -- @param frame the frame to draw the line to
-- @param[opt=10] width the width of the bar -- @param[opt=10] width the width of the bar
-- @return the line that was made type is progressbar -- @return the line that was made type is progress bar
function Gui.bar(frame,width) function Gui.bar(frame,width)
local line = frame.add{ local line = frame.add{
type='progressbar', type='progressbar',
@@ -44,11 +44,11 @@ function Gui.bar(frame,width)
return line return line
end end
--- Adds a lable that is centered --- Adds a label that is centered
-- @usage Gui.centered_label(frane, 'Hello, world!') -- @usage Gui.centered_label(frame, 'Hello, world!')
-- @tparam LuaGuiElement frame the parent frame to add the label to -- @tparam LuaGuiElement frame the parent frame to add the label to
-- @tparam string string the string that the lable will have -- @tparam string string the string that the label will have
function Gui.centered_label(frane, string) function Gui.centered_label(frame, string)
local flow = frame.add {frame = 'flow'} local flow = frame.add {frame = 'flow'}
local flow_style = flow.style local flow_style = flow.style
flow_style.align = 'center' flow_style.align = 'center'
@@ -62,13 +62,13 @@ function Gui.centered_label(frane, string)
return label return label
end end
--- Used to set the index of a drop down to a certian item --- Used to set the index of a drop down to a certain item
-- @usage Gui.set_dropdown_index(dropdown,player.name) -- will select the index with the players name as the value -- @usage Gui.set_dropdown_index(dropdown,player.name) -- will select the index with the players name as the value
-- @param dropdown the dropdown that is to be effected -- @param dropdown the dropdown that is to be effected
-- @param _item this is the item to look for -- @param _item this is the item to look for
-- @return returns the dropdown if it was successful -- @return returns the dropdown if it was successful
function Gui.set_dropdown_index(dropdown,_item) function Gui.set_dropdown_index(dropdown,_item)
if dropdown and dropdown.valid and dropdown.items and _item then else return end if not dropdown or not dropdown.valid or not dropdown.items or not _item then return end
local _index = 1 local _index = 1
for index, item in pairs(dropdown.items) do for index, item in pairs(dropdown.items) do
if item == _item then _index = index break end if item == _item then _index = index break end
@@ -88,7 +88,7 @@ end
-- @field surface this will over ride the surface that the camera follows on, allowing for a 'ghost surface' while keeping same position -- @field surface this will over ride the surface that the camera follows on, allowing for a 'ghost surface' while keeping same position
-- @field respawn_open if set to true then the camera will auto re link to the player after a respawn -- @field respawn_open if set to true then the camera will auto re link to the player after a respawn
--- Adds a camera that updates every tick (or less depeading on how many are opening) it will move to follow an entity --- Adds a camera that updates every tick (or less depending on how many are opening) it will move to follow an entity
-- @usage Gui.cam_link{entity=game.player.character,frame=frame,width=50,hight=50,zoom=1} -- @usage Gui.cam_link{entity=game.player.character,frame=frame,width=50,hight=50,zoom=1}
-- @usage Gui.cam_link{entity=game.player.character,cam=frame.camera,surface=game.surfaces['testing']} -- @usage Gui.cam_link{entity=game.player.character,cam=frame.camera,surface=game.surfaces['testing']}
-- @tparam table data contains all other params given below -- @tparam table data contains all other params given below
@@ -103,7 +103,7 @@ function Gui.cam_link(data)
data.cam.name='camera' data.cam.name='camera'
data.cam.position= data.entity.position data.cam.position= data.entity.position
data.cam.surface_index= data.surface and data.surface.index or data.entity.surface.index data.cam.surface_index= data.surface and data.surface.index or data.entity.surface.index
data.cam.zomm = data.zoom data.cam.zoom = data.zoom
data.cam = data.frame.add(data.cam) data.cam = data.frame.add(data.cam)
data.cam.style.width = data.width or 100 data.cam.style.width = data.width or 100
data.cam.style.height = data.height or 100 data.cam.style.height = data.height or 100
@@ -147,7 +147,7 @@ script.on_event('on_tick', function(event)
if global.cam_index >= #global.cams then global.cam_index = 1 end if global.cam_index >= #global.cams then global.cam_index = 1 end
if update > #global.cams then update = #global.cams end if update > #global.cams then update = #global.cams end
for cam_offset = 0,update do for cam_offset = 0,update do
local _cam = global.cams[global.cam_index] local _cam = global.cams[global.cam_index+cam_offset]
if not _cam then break end if not _cam then break end
if not _cam.cam.valid then table.remove(global.cams,global.cam_index) if not _cam.cam.valid then table.remove(global.cams,global.cam_index)
elseif not _cam.entity.valid then table.remove(global.cams,global.cam_index) elseif not _cam.entity.valid then table.remove(global.cams,global.cam_index)
@@ -162,6 +162,7 @@ script.on_event('on_player_respawned',function(event)
if loaded_modules['ExpGamingCore.Server'] then return end if loaded_modules['ExpGamingCore.Server'] then return end
if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then
local remove = {} local remove = {}
local player = Game.get_player(event)
for index,cam in pairs(global.players[event.player_index]) do for index,cam in pairs(global.players[event.player_index]) do
if cam.valid then table.insert(global.cams,{cam=cam,entity=player.character,surface=player.surface}) if cam.valid then table.insert(global.cams,{cam=cam,entity=player.character,surface=player.surface})
else table.insert(remove,index) end else table.insert(remove,index) end
@@ -173,14 +174,14 @@ script.on_event('on_player_respawned',function(event)
end) end)
function Gui:on_init() function Gui:on_init()
if loaded_modules['ExpGamingCore.Server'] then if loaded_modules['ExpGamingCore.Server'] then
Server = require('ExpGamingCore.Server') Server = require('ExpGamingCore.Server')
verbose('ExpGamingCore.Server is installed; Loading server src') verbose('ExpGamingCore.Server is installed; Loading server src')
script.on_init(require(module_path..'/src/server',{Gui=self})) script.on_init(require(module_path..'/src/server',{Gui=self}))
end end
end end
function Gui:on_post() function Gui.on_post()
Gui.test = require(module_path..'/src/test',{Gui=Gui}) Gui.test = require(module_path..'/src/test',{Gui=Gui})
end end

View File

@@ -78,8 +78,8 @@ function inputs._prototype:draw(root)
local success, err = pcall(self.data._items,player,root) local success, err = pcall(self.data._items,player,root)
if success then data.items = err else error(err) end if success then data.items = err else error(err) end
if is_type(self.data._index,'function') then if is_type(self.data._index,'function') then
local success, err = pcall(self.data._index,player,root) local _success, _err = pcall(self.data._index,player,root)
if success then data.selected_index = err else error(err) end if _success then data.selected_index = _err else error(_err) end
end end
return root.add(data) return root.add(data)
else else
@@ -87,25 +87,25 @@ function inputs._prototype:draw(root)
end end
end end
--- Add a new input, this is the same as doing frame.add{} but returns a diffrent object --- Add a new input, this is the same as doing frame.add{} but returns a different object
-- @usage Gui.inputs.add{type='button',name='test',caption='Test'} -- @usage Gui.inputs.add{type='button',name='test',caption='Test'}
-- @usage return_value(frame) -- draws the button onto that frame -- @usage return_value(frame) -- draws the button onto that frame
-- @tparam table obj the new element to add if caption is a sprite path then sprite is used -- @tparam table obj the new element to add if caption is a sprite path then sprite is used
-- @treturn table the custom input object, calling the returned calue will draw the button -- @treturn table the custom input object, calling the returned value will draw the button
function inputs.add(obj) function inputs.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.type,'string') then return end if not is_type(obj.type,'string') then return end
local type = obj.type local type = obj.type
if type == 'button' or if type ~= 'button'
type == 'sprite-button' or and type ~= 'sprite-button'
type == 'choose-elem-button' or and type ~= 'choose-elem-button'
type == 'checkbox' or and type ~= 'checkbox'
type == 'radiobutton' or and type ~= 'radiobutton'
type == 'textfield' or and type ~= 'textfield'
type == 'text-box' or and type ~= 'text-box'
type == 'slider' or and type ~= 'slider'
type == 'drop-down' and type ~= 'drop-down'
then else return end then return end
verbose('Created Input: '..obj.name..' ('..obj.type..')') verbose('Created Input: '..obj.name..' ('..obj.type..')')
if obj.type == 'button' or obj.type == 'sprite-button' then obj.style = mod_gui.button_style end if obj.type == 'button' or obj.type == 'sprite-button' then obj.style = mod_gui.button_style end
obj.draw_data = table.deepcopy(obj) obj.draw_data = table.deepcopy(obj)
@@ -139,23 +139,23 @@ end
script.on_event(inputs.events,inputs._event_handler) script.on_event(inputs.events,inputs._event_handler)
inputs.events.error = {} inputs.events.error = {}
-- the folwing functions are just to make inputs easier but if what you want is not include use inputs.add(obj) -- the following functions are just to make inputs easier but if what you want is not include use inputs.add(obj)
--- Used to define a button, can have many function --- Used to define a button, can have many function
-- @usage Gui.inputs.add_button('test','Test','Just for testing',{{condition,callback},...}) -- @usage Gui.inputs.add_button('test','Test','Just for testing',{{condition,callback},...})
-- @tparam string name the name of this button -- @tparam string name the name of this button
-- @tparam string the display for this button, either text or sprite path -- @tparam string the display for this button, either text or sprite path
-- @tparam string tooltip the tooltip to show on the button -- @tparam string tooltip the tooltip to show on the button
-- @param callbacks can either be a single function or a list of function pairs see exaplmes at bottom -- @param callbacks can either be a single function or a list of function pairs see examples at bottom
-- @treturn table the button object that was made, to allow a custom error event if wanted -- @treturn table the button object that was made, to allow a custom error event if wanted
function inputs.add_button(name,display,tooltip,callbacks) function inputs.add_button(name,display,tooltip,callbacks)
local button = inputs.add{ local rtn_button = inputs.add{
type='button', type='button',
name=name, name=name,
caption=display, caption=display,
tooltip=tooltip tooltip=tooltip
} }
button.data._callbacks = callbacks rtn_button.data._callbacks = callbacks
button:on_event('click',function(event) rtn_button:on_event('click',function(event)
local elements = Gui.data['inputs_'..event.element.type] or {} local elements = Gui.data['inputs_'..event.element.type] or {}
local button = elements[event.element.name] local button = elements[event.element.name]
if not button and event.element.type == 'sprite-button' then if not button and event.element.type == 'sprite-button' then
@@ -166,19 +166,19 @@ function inputs.add_button(name,display,tooltip,callbacks)
local mouse = event.button local mouse = event.button
local keys = {alt=event.alt,ctrl=event.control,shift=event.shift} local keys = {alt=event.alt,ctrl=event.control,shift=event.shift}
local element = event.element local element = event.element
local callbacks = button.data._callbacks local btn_callbacks = button.data._callbacks
if is_type(callbacks,'function') then callbacks = {{function(...) return true end,callbacks}} end if is_type(btn_callbacks,'function') then btn_callbacks = {{function() return true end,btn_callbacks}} end
for _,data in pairs(callbacks) do for _,data in pairs(btn_callbacks) do
if is_type(data[1],'function') and is_type(data[2],'function') then if is_type(data[1],'function') and is_type(data[2],'function') then
local success, err = pcall(data[1],player,mouse,keys,event) local success, err = pcall(data[1],player,mouse,keys,event)
if success and err == true then if success and err == true then
local success, err = pcall(data[2],player,element,event) local _success, _err = pcall(data[2],player,element,event)
if not success then error(err) end if not _success then error(_err) end
elseif not success then error(err) end elseif not success then error(err) end
else error('Invalid Callback Condition Format') end else error('Invalid Callback Condition Format') end
end end
end) end)
return button return rtn_button
end end
--- Used to define a choose-elem-button callback only on elem_changed --- Used to define a choose-elem-button callback only on elem_changed
@@ -221,20 +221,19 @@ end
function inputs.add_checkbox(name,radio,display,default,callback_true,callback_false) function inputs.add_checkbox(name,radio,display,default,callback_true,callback_false)
local type = 'checkbox'; if radio then type='radiobutton' end local type = 'checkbox'; if radio then type='radiobutton' end
local state = false; if is_type(default,'boolean') then state = default end local state = false; if is_type(default,'boolean') then state = default end
local checkbox = inputs.add{ local rtn_checkbox = inputs.add{
type=type, type=type,
name=name, name=name,
caption=display, caption=display,
state=state state=state
} }
if is_type(default,'function') then checkbox.data._state = default end if is_type(default,'function') then rtn_checkbox.data._state = default end
checkbox.data._true = callback_true rtn_checkbox.data._true = callback_true
checkbox.data._false = callback_false rtn_checkbox.data._false = callback_false
checkbox:on_event('state',function(event) rtn_checkbox:on_event('state',function(event)
local checkbox = Gui.data['inputs_'..event.element.type][event.element.name] local checkbox = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event) local player = Game.get_player(event)
local state = event.element.state if event.element.state then
if state then
if is_type(checkbox.data._true,'function') then if is_type(checkbox.data._true,'function') then
local success, err = pcall(checkbox.data._true,player,event.element) local success, err = pcall(checkbox.data._true,player,event.element)
if not success then error(err) end if not success then error(err) end
@@ -246,10 +245,10 @@ function inputs.add_checkbox(name,radio,display,default,callback_true,callback_f
else error('Invalid Callback') end else error('Invalid Callback') end
end end
end) end)
return checkbox return rtn_checkbox
end end
--- Used to reset the state of radio buttons, recomened to be called on_state_change to reset any radio buttons it is ment to work with. --- Used to reset the state of radio buttons, recommended to be called on_state_change to reset any radio buttons it is meant to work with.
-- @usage Gui.inputs.reset_radio{radio1,radio2,...} -- @usage Gui.inputs.reset_radio{radio1,radio2,...}
-- @param elements can be a list of elements or a single element -- @param elements can be a list of elements or a single element
function inputs.reset_radio(elements) function inputs.reset_radio(elements)
@@ -287,23 +286,23 @@ end
-- @treturn table the text object that was made, to allow a custom error event if wanted -- @treturn table the text object that was made, to allow a custom error event if wanted
function inputs.add_text(name,box,text,callback) function inputs.add_text(name,box,text,callback)
local type = 'textfield'; if box then type='text-box' end local type = 'textfield'; if box then type='text-box' end
local textbox = inputs.add{ local rtn_textbox = inputs.add{
type=type, type=type,
name=name, name=name,
text=text text=text
} }
textbox.data._callback = callback rtn_textbox.data._callback = callback
textbox:on_event('text',function(event) rtn_textbox:on_event('text',function(event)
local textbox = Gui.data['inputs_'..event.element.type][event.element.name] local textbox = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event) local player = Game.get_player(event)
local element = event.element local element = event.element
local callback = textbox.data._callback local event_callback = textbox.data._callback
if is_type(callback,'function') then if is_type(event_callback,'function') then
local success, err = pcall(callback,player,element.text,element) local success, err = pcall(event_callback,player,element.text,element)
if not success then error(err) end if not success then error(err) end
else error('Invalid Callback Condition Format') end else error('Invalid Callback Condition Format') end
end) end)
return textbox return rtn_textbox
end end
--- Used to define a slider callback only on value_changed --- Used to define a slider callback only on value_changed
@@ -348,28 +347,28 @@ end
-- @tparam function callback the callback which is called when a new index is selected function(player,selected,items,element) -- @tparam function callback the callback which is called when a new index is selected function(player,selected,items,element)
-- @treturn table the drop-down object that was made, to allow a custom error event if wanted -- @treturn table the drop-down object that was made, to allow a custom error event if wanted
function inputs.add_drop_down(name,items,index,callback) function inputs.add_drop_down(name,items,index,callback)
local drop_down = inputs.add{ local rtn_dropdown = inputs.add{
type='drop-down', type='drop-down',
name=name, name=name,
items=items, items=items,
selected_index=index selected_index=index
} }
drop_down.data._items = items rtn_dropdown.data._items = items
drop_down.data._index = index rtn_dropdown.data._index = index
drop_down.data._callback = callback rtn_dropdown.data._callback = callback
drop_down:on_event('selection',function(event) rtn_dropdown:on_event('selection',function(event)
local drop_down = Gui.data['inputs_'..event.element.type][event.element.name] local dropdown = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event) local player = Game.get_player(event)
local element = event.element local element = event.element
local items = element.items local drop_items = element.items
local selected = items[element.selected_index] local selected = drop_items[element.selected_index]
local callback = drop_down.data._callback local drop_callback = dropdown.data._callback
if is_type(callback,'function') then if is_type(drop_callback,'function') then
local success, err = pcall(callback,player,selected,items,element) local success, err = pcall(drop_callback,player,selected,drop_items,element)
if not success then error(err) end if not success then error(err) end
else error('Invalid Callback Condition Format') end else error('Invalid Callback Condition Format') end
end) end)
return drop_down return rtn_dropdown
end end
-- calling will attempt to add a new input -- calling will attempt to add a new input

View File

@@ -1,4 +1,4 @@
--- Adds a organiser for left gui ellements which will automaticaly update there information and have open requirements --- Adds a organiser for left gui elements which will automatically update there information and have open requirements
-- @module ExpGamingCore.Gui.Left -- @module ExpGamingCore.Gui.Left
-- @alias left -- @alias left
-- @author Cooldude2606 -- @author Cooldude2606
@@ -12,7 +12,7 @@ local Color = require('FactorioStdLib.Color')
local mod_gui = require('mod-gui') local mod_gui = require('mod-gui')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local order_config = require(module_path..'/order_config') local order_config = require(module_path..'/order_config')
local Role -- this is optional and is hanndled by it being present, it is loaded on init local Role -- this is optional and is handled by it being present, it is loaded on init
local left = {} local left = {}
left._prototype = {} left._prototype = {}
@@ -35,11 +35,11 @@ function left.override_open(state)
end end
--- Used to add a left gui frame --- Used to add a left gui frame
-- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function} -- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function}
-- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players -- @usage return_value(player) -- toggles visibility for that player, if no player then updates for all players
-- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed -- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the default state true/false, can_open is a test to block it from opening but is not needed
-- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player -- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visibility for that player
function left.add(obj) function left.add(obj)
if not is_type(obj,'table') then return end if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end if not is_type(obj.name,'string') then return end
verbose('Created Left Gui: '..obj.name) verbose('Created Left Gui: '..obj.name)
setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then return self:toggle(player) else return left.update(self.name) end end}) setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then return self:toggle(player) else return left.update(self.name) end end})
@@ -54,18 +54,18 @@ end
-- @param[opt] players the player to update for, if not given all players are updated, can be one player -- @param[opt] players the player to update for, if not given all players are updated, can be one player
function left.update(frame,players) function left.update(frame,players)
if not Server or not Server._thread then if not Server or not Server._thread then
local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players
for _,player in pairs(players) do for _,player in pairs(players) do
local frames = Gui.data.left or {} local frames = Gui.data.left or {}
if frame then frames = {[frame]=frames[frame]} or {} end if frame then frames = {[frame]=frames[frame]} or {} end
for name,left in pairs(frames) do for _,left_frame in pairs(frames) do
if _left then left:first_open(player) end if left_frame then left_frame:first_open(player) end
end end
end end
else else
local frames = Gui.data.left or {} local frames = Gui.data.left or {}
if frame then frames = {[frame]=frames[frame]} or {} end if frame then frames = {[frame]=frames[frame]} or {} end
local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players
Server.new_thread{ Server.new_thread{
data={players=players,frames=frames} data={players=players,frames=frames}
}:on_event('tick',function(thread) }:on_event('tick',function(thread)
@@ -74,8 +74,8 @@ function left.update(frame,players)
Server.new_thread{ Server.new_thread{
data={player=player,frames=thread.data.frames} data={player=player,frames=thread.data.frames}
}:on_event('resolve',function(thread) }:on_event('resolve',function(thread)
for name,left in pairs(thread.data.frames) do for _,left_frame in pairs(thread.data.frames) do
if left then left:first_open(thread.data.player) end if left_frame then left_frame:first_open(thread.data.player) end
end end
end):queue() end):queue()
end):open() end):open()
@@ -91,14 +91,14 @@ function left.open(left_name,player)
local _left = Gui.data.left[left_name] local _left = Gui.data.left[left_name]
if not _left then return end if not _left then return end
if not Server or not Server._thread then if not Server or not Server._thread then
for _,player in pairs(players) do _left:open(player) end for _,next_player in pairs(players) do _left:open(next_player) end
else else
Server.new_thread{ Server.new_thread{
data={players=players} data={players=players}
}:on_event('tick',function(thread) }:on_event('tick',function(thread)
if #thread.data.players == 0 then thread:close() return end if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1) local next_player = table.remove(thread.data.players,1)
_left:open(player) _left:open(next_player)
end):open() end):open()
end end
end end
@@ -112,14 +112,14 @@ function left.close(left_name,player)
local _left = Gui.data.left[left_name] local _left = Gui.data.left[left_name]
if not _left then return end if not _left then return end
if not Server or not Server._thread or player then if not Server or not Server._thread or player then
for _,player in pairs(players) do _left:close(player) end for _,next_player in pairs(players) do _left:close(next_player) end
else else
Server.new_thread{ Server.new_thread{
data={players=players} data={players=players}
}:on_event('tick',function(thread) }:on_event('tick',function(thread)
if #thread.data.players == 0 then thread:close() return end if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1) local next_player = table.remove(thread.data.players,1)
_left:close(player) _left:close(next_player)
end):open() end):open()
end end
end end
@@ -129,7 +129,7 @@ end
-- @usage left:open(player) -- @usage left:open(player)
-- @tparam luaPlayer player the player to open the gui for -- @tparam luaPlayer player the player to open the gui for
function left._prototype:open(player) function left._prototype:open(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid Player') end if not player then error('Invalid Player') end
local left_flow = mod_gui.get_frame_flow(player) local left_flow = mod_gui.get_frame_flow(player)
if not left_flow[self.name] then self:first_open(player) end if not left_flow[self.name] then self:first_open(player) end
@@ -141,7 +141,7 @@ end
-- @usage left:open(player) -- @usage left:open(player)
-- @tparam luaPlayer player the player to close the gui for -- @tparam luaPlayer player the player to close the gui for
function left._prototype:close(player) function left._prototype:close(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid Player') end if not player then error('Invalid Player') end
local left_flow = mod_gui.get_frame_flow(player) local left_flow = mod_gui.get_frame_flow(player)
if not left_flow[self.name] then self:first_open(player) end if not left_flow[self.name] then self:first_open(player) end
@@ -156,11 +156,11 @@ end
-- @tparam LuaPlayer player the player to draw the gui for -- @tparam LuaPlayer player the player to draw the gui for
-- @treturn LuaFrame the frame made/updated -- @treturn LuaFrame the frame made/updated
function left._prototype:first_open(player) function left._prototype:first_open(player)
local player = Game.get_player(player) player = Game.get_player(player)
local left_flow = mod_gui.get_frame_flow(player) local left_flow = mod_gui.get_frame_flow(player)
local frame = nil local frame
if left_flow[self.name] then if left_flow[self.name] then
frame = left_flow[self.name] frame = left_flow[self.name]
frame.clear() frame.clear()
else else
if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end
@@ -172,15 +172,15 @@ function left._prototype:first_open(player)
return frame return frame
end end
--- Toggles the visiblity of the gui based on some conditions --- Toggles the visibility of the gui based on some conditions
-- @usage left:toggle(player) -- returns new state -- @usage left:toggle(player) -- returns new state
-- @tparam LuaPlayer player the player to toggle the gui for, remember there are condition which need to be met -- @tparam LuaPlayer player the player to toggle the gui for, remember there are condition which need to be met
-- @treturn boolean the new state that the gui is in -- @treturn boolean the new state that the gui is in
function left._prototype:toggle(player) function left._prototype:toggle(player)
local player = Game.get_player(player) player = Game.get_player(player)
local left_flow = mod_gui.get_frame_flow(player) local left_flow = mod_gui.get_frame_flow(player)
if not left_flow[self.name] then self:first_open(player) end if not left_flow[self.name] then self:first_open(player) end
local left = left_flow[self.name] local left_frame = left_flow[self.name]
local open = false local open = false
if is_type(self.can_open,'function') then if is_type(self.can_open,'function') then
local success, err = pcall(self.can_open,player) local success, err = pcall(self.can_open,player)
@@ -198,18 +198,18 @@ function left._prototype:toggle(player)
else open = {'ExpGamingCore_Gui.unauthorized'} end else open = {'ExpGamingCore_Gui.unauthorized'} end
else open = true end else open = true end
end end
if open == true and left.style.visible ~= true then if open == true and left_frame.style.visible ~= true then
left.style.visible = true left_frame.style.visible = true
left_flow['gui-left-hide'].style.visible = true left_flow['gui-left-hide'].style.visible = true
else else
left.style.visible = false left_frame.style.visible = false
local count = 0 local count = 0
for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end
if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end
end end
if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'}
elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
return left.style.visible return left_frame.style.visible
end end
script.on_event(defines.events.on_player_joined_game,function(event) script.on_event(defines.events.on_player_joined_game,function(event)
@@ -220,14 +220,14 @@ script.on_event(defines.events.on_player_joined_game,function(event)
if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end
local done = {} local done = {}
for _,name in pairs(order_config) do for _,name in pairs(order_config) do
local left = Gui.data.left[name] local left_frame = Gui.data.left[name]
if left then if left_frame then
done[name] = true done[name] = true
left:first_open(player) left_frame:first_open(player)
end end
end end
for name,left in pairs(frames) do for name,left_frame in pairs(frames) do
if not done[name] then left:first_open(player) end if not done[name] then left_frame:first_open(player) end
end end
end) end)
@@ -237,7 +237,7 @@ script.on_event(defines.events.on_tick,function(event)
end end
end) end)
function left:on_init() function left.on_init()
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
end end

View File

@@ -33,7 +33,7 @@ end
-- this is used by the script to find the popup flow -- this is used by the script to find the popup flow
function popup.flow(player) function popup.flow(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid Player',2) end if not player then error('Invalid Player',2) end
local flow = mod_gui.get_frame_flow(player).popups local flow = mod_gui.get_frame_flow(player).popups
if not flow then flow = mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} flow.style.visible=false end if not flow then flow = mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} flow.style.visible=false end
@@ -47,8 +47,8 @@ end
-- @tparam[opt=game.connected_players] table players the players to open the popup for -- @tparam[opt=game.connected_players] table players the players to open the popup for
function popup.open(style,data,players) function popup.open(style,data,players)
local _popup = Gui.data.popup[style] local _popup = Gui.data.popup[style]
local players = players or game.connected_players players = players or game.connected_players
local data = data or {} data = data or {}
if not _popup then return end if not _popup then return end
if not Server or not Server._thread then if not Server or not Server._thread then
for _,player in pairs(players) do for _,player in pairs(players) do
@@ -107,11 +107,11 @@ function popup._prototype:add_left(obj)
self.left = Gui.left(obj) self.left = Gui.left(obj)
end end
function popup:on_init() function popup.on_init()
if loaded_modules['ExpGamingCore.Server'] then Server = require('ExpGamingCore.Server') end if loaded_modules['ExpGamingCore.Server'] then Server = require('ExpGamingCore.Server') end
end end
function popup:on_post() function popup.on_post()
popup._prototype.close = Gui.inputs.add{ popup._prototype.close = Gui.inputs.add{
type='button', type='button',
name='popup-close', name='popup-close',

View File

@@ -7,7 +7,7 @@ local Server = require('ExpGamingCore.Server')
Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui') Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui')
--- Adds a server thread that allows the camera follows to be toggled off and on --- Adds a server thread that allows the camera follows to be toggled off and on
return function(event) return function()
Server.new_thread{ Server.new_thread{
name='camera-follow', name='camera-follow',
data={cams={},cam_index=1,players={}} data={cams={},cam_index=1,players={}}

View File

@@ -53,30 +53,30 @@ local input_test = Gui.inputs.add_button('test-inputs','Try RMB','alt,ctrl,shift
function(player,mouse,keys) return mouse == defines.mouse_button_type.right and keys.shift end, function(player,mouse,keys) return mouse == defines.mouse_button_type.right and keys.shift end,
function(player,element) player_return('Right: Shift',nil,player) end function(player,element) player_return('Right: Shift',nil,player) end
} }
}):on_event('error',function(err) game.print('this is error handliling') end) }):on_event('error',function(err) game.print('this is error handling') end)
local elem_test = Gui.inputs.add_elem_button('test-elem','item','Testing Elems',function(player,element,elem) local elem_test = Gui.inputs.add_elem_button('test-elem','item','Testing Elems',function(player,element,elem)
player_return(elem.type..' '..elem.value,nil,player) player_return(elem.type..' '..elem.value,nil,player)
end) end)
local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent) local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent)
return game.players[parent.player_index].cheat_mode return game.players[parent.player_index].cheat_mode
end,function(player,element) end,function(player,element)
player.cheat_mode = true player.cheat_mode = true
end,function(player,element) end,function(player,element)
player.cheat_mode = false player.cheat_mode = false
end) end)
local radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(player,parent) local radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(player,parent)
return false return false
end,function(player,element) end,function(player,element)
if player.character then player.character.die() end if player.character then player.character.die() end
Gui.inputs.reset_radio(element.parent['test-radio-reset']) Gui.inputs.reset_radio(element.parent['test-radio-reset'])
end) end)
local radio_test_reset = Gui.inputs.add_checkbox('test-radio-reset',true,'Reset Kill Self',function(player,parent) local radio_test_reset = Gui.inputs.add_checkbox('test-radio-reset',true,'Reset Kill Self',function(player,parent)
return not parent['test-radio'].state return not parent['test-radio'].state
end,function(player,element) end,function(player,element)
Gui.inputs.reset_radio(element.parent['test-radio']) Gui.inputs.reset_radio(element.parent['test-radio'])
end) end)

View File

@@ -11,7 +11,7 @@ local Game = require('FactorioStdLib.Game')
local mod_gui = require('mod-gui') local mod_gui = require('mod-gui')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local order_config = require(module_path..'/order_config') local order_config = require(module_path..'/order_config')
local Role -- this is optional and is hanndled by it being present, it is loaded on init local Role -- this is optional and is handled by it being present, it is loaded on init
local toolbar = {} local toolbar = {}
@@ -52,7 +52,7 @@ end
-- @usage toolbar.draw(1) -- @usage toolbar.draw(1)
-- @param player the player to draw the tool bar of -- @param player the player to draw the tool bar of
function toolbar.draw(player) function toolbar.draw(player)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then return end if not player then return end
local toolbar_frame = mod_gui.get_button_flow(player) local toolbar_frame = mod_gui.get_button_flow(player)
toolbar_frame.clear() toolbar_frame.clear()
@@ -81,7 +81,7 @@ function toolbar.draw(player)
end end
end end
function toolbar:on_init() function toolbar.on_init()
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
end end

View File

@@ -1,17 +1,17 @@
Role.add_flag('is_default') -- this must be included in atleast one role Role.add_flag('is_default') -- this must be included in at least one role
Role.add_flag('is_root',function(player,state) Role.add_flag('is_root',function(player,state)
if state then game.print('--- !!!ALERT!!! --- '..player.name..' has been given a role with ROOT ACCESS --- !!!ALERT!!! ---') end if state then game.print('--- !!!ALERT!!! --- '..player.name..' has been given a role with ROOT ACCESS --- !!!ALERT!!! ---') end
if player.character then player.character.destructible = not state end if player.character then player.character.destructible = not state end
end) -- the SERVER role will have root but you may assign this to other roles end) -- the SERVER role will have root but you may assign this to other roles
-- the two above and used internaly and should NOT have their names changed and should NOT be removed but the state function MAY be changed -- the two above and used internally and should NOT have their names changed and should NOT be removed but the state function MAY be changed
Role.add_flag('is_antiroot',function(player,state) if player.character then player.character.destructible = not state end end) -- not required but setting true will disallow everything for that role Role.add_flag('is_antiroot',function(player,state) if player.character then player.character.destructible = not state end end) -- not required but setting true will disallow everything for that role
Role.add_flag('is_admin',function(player,state) player.admin = state end) -- highly recomented but not required Role.add_flag('is_admin',function(player,state) player.admin = state end) -- highly recommenced but not required
Role.add_flag('is_spectator',function(player,state) player.spectator = state end) Role.add_flag('is_spectator',function(player,state) player.spectator = state end)
Role.add_flag('is_jail',function(player,state) if player.character then player.character.active = not state end end) Role.add_flag('is_jail',function(player,state) if player.character then player.character.active = not state end end)
Role.add_flag('allow_afk_kick') Role.add_flag('allow_afk_kick')
Role.add_flag('is_donator') Role.add_flag('is_donator')
Role.add_flag('is_timed') Role.add_flag('is_timed')
Role.add_flag('is_varified') Role.add_flag('is_verified')
Role.add_flag('not_reportable') Role.add_flag('not_reportable')
-- Root -- Root
@@ -64,7 +64,7 @@ Role{
colour={r=233,g=63,b=233}, colour={r=233,g=63,b=233},
is_admin=true, is_admin=true,
is_spectator=true, is_spectator=true,
is_varified=true, is_verified=true,
not_reportable=true, not_reportable=true,
allow={ allow={
['game-settings']=true, ['game-settings']=true,
@@ -80,7 +80,7 @@ Role{
colour={r=0,g=170,b=0}, colour={r=0,g=170,b=0},
is_admin=true, is_admin=true,
is_spectator=true, is_spectator=true,
is_varified=true, is_verified=true,
not_reportable=true, not_reportable=true,
allow={ allow={
['set-home']=true, ['set-home']=true,
@@ -97,7 +97,7 @@ Role{
group='Admin', group='Admin',
colour={r=0,g=196,b=137}, colour={r=0,g=196,b=137},
is_spectator=true, is_spectator=true,
is_varified=true, is_verified=true,
not_reportable=true, not_reportable=true,
allow={ allow={
['go-to']=true, ['go-to']=true,
@@ -173,7 +173,7 @@ Role{
group='HiMember', group='HiMember',
colour={r=140,g=120,b=200}, colour={r=140,g=120,b=200},
is_timed=true, is_timed=true,
is_varified=true, is_verified=true,
allow_afk_kick=true, allow_afk_kick=true,
time=600, -- 10 hours time=600, -- 10 hours
allow={ allow={
@@ -190,13 +190,13 @@ Role{
tag='[Member]', tag='[Member]',
group='Member', group='Member',
colour={r=24,g=172,b=188}, colour={r=24,g=172,b=188},
is_varified=true, is_verified=true,
allow_afk_kick=true, allow_afk_kick=true,
allow={ allow={
['edit-tasklist']=true, ['edit-tasklist']=true,
['make-warp']=true, ['make-warp']=true,
['nuke']=true, ['nuke']=true,
['varified']=true ['verified']=true
} }
} }
Role{ Role{

View File

@@ -2,17 +2,18 @@
-- @module ExpGamingCore.Role@4.0.0 -- @module ExpGamingCore.Role@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais Role -- @alias Role
-- Module Require -- Module Require
local Group = require('ExpGamingCore.Group') local Group = require('ExpGamingCore.Group')
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
-- Local Varibles -- Local Variables
local role_change_event_id = script.generate_event_name('on_role_change') local role_change_event_id = script.generate_event_name('on_role_change')
local RoleGlobal local RoleGlobal
-- Module Define -- Module Define
local _RoleSelfReference
local module_verbose = false local module_verbose = false
local Role = { local Role = {
_prototype={}, _prototype={},
@@ -24,7 +25,7 @@ local Role = {
roles=setmetatable({},{ roles=setmetatable({},{
__index=table.autokey, __index=table.autokey,
__newindex=function(tbl,key,value) __newindex=function(tbl,key,value)
rawset(tbl,key,Role.define(value)) rawset(tbl,key,_RoleSelfReference.define(value))
end end
}), }),
on_init=function(self) on_init=function(self)
@@ -57,10 +58,11 @@ local Role = {
else error('Invalid roles, no roles to load.') end else error('Invalid roles, no roles to load.') end
end end
} }
_RoleSelfReference=Role
-- Global Define -- Global Define
local global = global{ local global = global{
change_chache_length=15, change_cache_length=15,
changes={}, changes={},
latest_change={}, latest_change={},
preassign={}, preassign={},
@@ -79,7 +81,7 @@ function Role.set_preassign(tbl) if game then global.preassign = tbl else Role.p
-- @usage Role{name='Root',short_hand='Root',tag='[Root]',group='Root',colour={r=255,b=255,g=255},is_root=true,allow={}} -- returns new role -- @usage Role{name='Root',short_hand='Root',tag='[Root]',group='Root',colour={r=255,b=255,g=255},is_root=true,allow={}} -- returns new role
-- @tparam table obj contains the strings: name,short_hand,tag a table called allow a table called colour and a pointer to a permission group -- @tparam table obj contains the strings: name,short_hand,tag a table called allow a table called colour and a pointer to a permission group
-- @treturn Role the role which has been made -- @treturn Role the role which has been made
function Role.define(obj) function Role.define(obj)
if not type_error(game,nil,'Cant define Role during runtime.') then return end if not type_error(game,nil,'Cant define Role during runtime.') then return end
if not type_error(obj.name,'string','Role creation is invalid: role.name is not a string') then return end if not type_error(obj.name,'string','Role creation is invalid: role.name is not a string') then return end
if not is_type(obj.short_hand,'string') then obj.short_hand = obj.name:sub(1,3) end if not is_type(obj.short_hand,'string') then obj.short_hand = obj.name:sub(1,3) end
@@ -101,19 +103,19 @@ end
--- Used to get the role of a player or the role by name --- Used to get the role of a player or the role by name
-- @usage Role.get('foo') -- returns group foo -- @usage Role.get('foo') -- returns group foo
-- @usage Role.get(player) -- returns group of player -- @usage Role.get(player) -- returns group of player
-- @tparam ?LuaPlayer|pointerToPlayer|string mixed can either be the name of the role or a player indenifier -- @tparam ?LuaPlayer|pointerToPlayer|string mixed can either be the name of the role or a player identifier
-- @treturn table the group which was found or nil -- @treturn table the group which was found or nil
function Role.get(mixed,forceIsRole) function Role.get(mixed,forceIsRole)
local player = game and Game.get_player(mixed) local player = game and Game.get_player(mixed)
if player == SERVER then return {Role.meta.server} end if player == SERVER then return {Role.meta.server} end
if not forceIsRole and player then if not forceIsRole and player then
local rtn = {} local rtn = {}
if not global.players[player.index] then return Role.meta.default and {Role.meta.default} or {} end if not global.players[player.index] then return Role.meta.default and {Role.meta.default} or {} end
for _,role in pairs(global.players[player.index]) do table.insert(rtn,Role.get(role)) end for _,role in pairs(global.players[player.index]) do table.insert(rtn,Role.get(role)) end
return rtn return rtn
elseif is_type(mixed,'table') and mixed.group then return mixed elseif is_type(mixed,'table') and mixed.group then return mixed
elseif is_type(mixed,'string') then return Role.roles[mixed] elseif is_type(mixed,'string') then return Role.roles[mixed]
elseif is_type(mixed,'number') then elseif is_type(mixed,'number') then
for _,role in pairs(Role.roles) do for _,role in pairs(Role.roles) do
if role.index == mixed then return role end if role.index == mixed then return role end
end end
@@ -124,25 +126,25 @@ end
-- @usage Role.assign(player,'Root') -- @usage Role.assign(player,'Root')
-- @usage Role.assign(player,{'Root','Foo'}) -- @usage Role.assign(player,{'Root','Foo'})
-- @tparam ?LuaPlayer|pointerToPlayer player the player to assign the role to -- @tparam ?LuaPlayer|pointerToPlayer player the player to assign the role to
-- @tparam ?string|role|table the role to add the player to, if its a table then it will act recursly though the table -- @tparam ?string|role|table the role to add the player to, if its a table then it will act recursively though the table
-- @tparam[opt='<server>'] ?LuaPlayer|pointerToPlayer by_player the player who assigned the roles to the player -- @tparam[opt='<server>'] ?LuaPlayer|pointerToPlayer by_player the player who assigned the roles to the player
-- @tparam[opt] table batch this is used internally to provent multiple event calls, conatins {role_index_in_batch,batch} -- @tparam[opt] table batch this is used internally to prevent multiple event calls, contains {role_index_in_batch,batch}
-- @treturn boolean was the player assigned the roles -- @treturn boolean was the player assigned the roles
function Role.assign(player,role,by_player,batch) function Role.assign(player,role,by_player,batch)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to Role.assign.',2) return end if not player then error('Invalid player #1 given to Role.assign.',2) return end
verbose('Assigning Roles: '..serpent.line(role)..' to: '..player.name) verbose('Assigning Roles: '..serpent.line(role)..' to: '..player.name)
-- this loops over a table of role if given; will return if ipairs returns, else will asume it was ment to be a role and error -- this loops over a table of role if given; will return if ipairs returns, else will assume it was meant to be a role and error
if is_type(role,'table') and not role.name then if is_type(role,'table') and not role.name then
local ctn = 0 local ctn = 0
for n,_role in ipairs(role) do ctn=ctn+1 Role.assign(player,_role,by_player,{n,role}) end for n,_role in ipairs(role) do ctn=ctn+1 Role.assign(player,_role,by_player,{n,role}) end
if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'assign',role}) global.latest_change = {player.index,'assign',role} end return end if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'assign',role}) global.latest_change = {player.index,'assign',role} end return end
end end
local role = Role.get(role) role = Role.get(role)
if not role then error('Invalid role #2 given to Role.assign.',2) return end if not role then error('Invalid role #2 given to Role.assign.',2) return end
-- this acts as a way to provent the global table getting too full -- this acts as a way to prevent the global table getting too full
if not global.changes[player.index] then global.changes[player.index]={} end if not global.changes[player.index] then global.changes[player.index]={} end
if #global.changes[player.index] > global.change_chache_length then table.remove(global.changes[player.index],1) end if #global.changes[player.index] > global.change_cache_length then table.remove(global.changes[player.index],1) end
if not batch then table.insert(global.changes[player.index],{'assign',role.name}) global.latest_change = {player.index,'assign',role.name} end if not batch then table.insert(global.changes[player.index],{'assign',role.name}) global.latest_change = {player.index,'assign',role.name} end
return role:add_player(player,by_player,batch) return role:add_player(player,by_player,batch)
end end
@@ -150,31 +152,31 @@ end
--- Used to remove a player from a role(s) --- Used to remove a player from a role(s)
-- @usage Role.unassign(player,'Root') -- @usage Role.unassign(player,'Root')
-- @tparam ?LuaPlayer|pointerToPlayer player the player to unassign the role to -- @tparam ?LuaPlayer|pointerToPlayer player the player to unassign the role to
-- @tparam ?string|role|table role the role to remove the player from, if its a table then it will act recursly though the table -- @tparam ?string|role|table role the role to remove the player from, if its a table then it will act recursively though the table
-- @tparam[opt='<server>'] ?LuaPlayer|pointerToPlayer by_player the player who unassigned the roles from the player -- @tparam[opt='<server>'] ?LuaPlayer|pointerToPlayer by_player the player who unassigned the roles from the player
-- @tparam[opt] table batch this is used internally to provent multiple event calls -- @tparam[opt] table batch this is used internally to prevent multiple event calls
-- @treturn boolean was the player unassigned the roles -- @treturn boolean was the player unassigned the roles
function Role.unassign(player,role,by_player,batch) function Role.unassign(player,role,by_player,batch)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to Role.unassign.',2) return end if not player then error('Invalid player #1 given to Role.unassign.',2) return end
verbose('Assigning Roles: '..serpent.line(role)..' to: '..player.name) verbose('Assigning Roles: '..serpent.line(role)..' to: '..player.name)
-- this loops over a table of role if given; will return if ipairs returns, else will asume it was ment to be a role and error -- this loops over a table of role if given; will return if ipairs returns, else will assume it was meant to be a role and error
if is_type(role,'table') and not role.name then if is_type(role,'table') and not role.name then
local ctn = 0 local ctn = 0
for n,_role in ipairs(role) do ctn=ctn+1 Role.unassign(player,_role,by_player,{n,role}) end for n,_role in ipairs(role) do ctn=ctn+1 Role.unassign(player,_role,by_player,{n,role}) end
if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'unassign',role}) global.latest_change = {player.index,'unassign',role} end return end if ctn > 0 then if not batch then table.insert(global.changes[player.index],{'unassign',role}) global.latest_change = {player.index,'unassign',role} end return end
end end
local role = Role.get(role) role = Role.get(role)
if not role then error('Invalid role #2 given to Role.unassign.',2) return end if not role then error('Invalid role #2 given to Role.unassign.',2) return end
if not global.changes[player.index] then global.changes[player.index]={} end if not global.changes[player.index] then global.changes[player.index]={} end
-- this acts as a way to provent the global table getting too full -- this acts as a way to prevent the global table getting too full
if #global.changes[player.index] > global.change_chache_length then table.remove(global.changes[player.index],1) end if #global.changes[player.index] > global.change_cache_length then table.remove(global.changes[player.index],1) end
if not batch then table.insert(global.changes[player.index],{'unassign',role.name}) global.latest_change = {player.index,'unassign',role.name} end if not batch then table.insert(global.changes[player.index],{'unassign',role.name}) global.latest_change = {player.index,'unassign',role.name} end
return role:remove_player(player,by_player,batch) return role:remove_player(player,by_player,batch)
end end
--- Returns the highest role given in a list, if a player is passed then it returns the highest role of the player --- Returns the highest role given in a list, if a player is passed then it returns the highest role of the player
-- @usage Role.get_highest{'Root','Admin','Mod'} -- retuns Root (given that root is highest) -- @usage Role.get_highest{'Root','Admin','Mod'} -- returns Root (given that root is highest)
-- @usage Role.get_highest(player) -- returns the players highest role -- @usage Role.get_highest(player) -- returns the players highest role
-- @tparam ?table|LuaPlayer|pointerToPlayer options table of options or a player -- @tparam ?table|LuaPlayer|pointerToPlayer options table of options or a player
-- @treturn role the highest role given in the options -- @treturn role the highest role given in the options
@@ -192,19 +194,19 @@ function Role.get_highest(options)
return highest return highest
end end
--- Uses the change chache to revert changes to players roles --- Uses the change cache to revert changes to players roles
-- @usage Role.revert(player) -- reverts the last change to the players roles -- @usage Role.revert(player) -- reverts the last change to the players roles
-- @tparam ?LuaPlayer|pointerToPlayer player the player to revert the changes of -- @tparam ?LuaPlayer|pointerToPlayer player the player to revert the changes of
-- @tparam[opt] ?LuaPlayer|pointerToPlayer the player who proformed the role revert -- @tparam[opt] ?LuaPlayer|pointerToPlayer the player who preformed the role revert
-- @tparam[opt=1] count the number of reverts to do, if 0 all changes chached are reverted -- @tparam[opt=1] count the number of reverts to do, if 0 all changes cached are reverted
-- @treturn number the number of changes that occured -- @treturn number the number of changes that occurred
function Role.revert(player,by_player,count) function Role.revert(player,by_player,count)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to Role.revert.',2) return end if not player then error('Invalid player #1 given to Role.revert.',2) return end
if count and not type_error(count,'number','Invalid argument #2 to Role.revert, count is not a number.') then return end if count and not type_error(count,'number','Invalid argument #2 to Role.revert, count is not a number.') then return end
local changes = global.changes[player.index] or {} local changes = global.changes[player.index] or {}
if #changes == 0 then error('Player has no role changes logged, can not revert.') end if #changes == 0 then error('Player has no role changes logged, can not revert.') end
local count = count or 1 count = count or 1
local ctn = 0 local ctn = 0
if count > #changes or count == 0 then count = #changes end if count > #changes or count == 0 then count = #changes end
for i = 1,count do for i = 1,count do
@@ -220,7 +222,7 @@ end
--- Adds a flag which can be set on roles; these flags act as a quick way to access general role changes --- Adds a flag which can be set on roles; these flags act as a quick way to access general role changes
-- @usage Role.add_flag('is_admin',function(player,state) player.admin = state end) -- the function is passed player and if the flag is true or false -- @usage Role.add_flag('is_admin',function(player,state) player.admin = state end) -- the function is passed player and if the flag is true or false
-- @tparam string flag the name of the falg that is being added -- @tparam string flag the name of the flag that is being added
-- @tparam[opt] function callback the function(player,state) which is called when a player loses or gains a flag, if nil no function is called -- @tparam[opt] function callback the function(player,state) which is called when a player loses or gains a flag, if nil no function is called
function Role.add_flag(flag,callback) function Role.add_flag(flag,callback)
if not type_error(flag,'string','Invalid argument #1 to Role.add_flag, flag is not a string.') then return end if not type_error(flag,'string','Invalid argument #1 to Role.add_flag, flag is not a string.') then return end
@@ -229,7 +231,7 @@ function Role.add_flag(flag,callback)
Role.flags[flag] = callback or true Role.flags[flag] = callback or true
end end
--- Checks if a player or role has the requested flag, if player all roles of player are checked (true has pirortiy) --- Checks if a player or role has the requested flag, if player all roles of player are checked (true has priority)
-- @usage Role.has_flag(role,'is_admin') -- returns true if this role has is_admin set -- @usage Role.has_flag(role,'is_admin') -- returns true if this role has is_admin set
-- @tparam role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested -- @tparam role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested
-- @tparam string flag the flag to test for -- @tparam string flag the flag to test for
@@ -253,7 +255,7 @@ function Role.add_action(action)
table.insert(Role.actions,action) table.insert(Role.actions,action)
end end
--- Checks if a player or role is allowed the requested action, if player all roles of player are checked (true has pirortiy) --- Checks if a player or role is allowed the requested action, if player all roles of player are checked (true has priority)
-- @usage Role.allowed(role,'foo') -- returns true if this role is allowed 'foo' -- @usage Role.allowed(role,'foo') -- returns true if this role is allowed 'foo'
-- @tparam ?role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested -- @tparam ?role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested
-- @tparam string action the action to test for -- @tparam string action the action to test for
@@ -269,14 +271,14 @@ function Role.allowed(mixed,action)
end end
--- Prints to all roles and players of those roles which are greater than the given role (or if inv then all below) --- Prints to all roles and players of those roles which are greater than the given role (or if inv then all below)
-- @usage Role.print('Admin','Hello, World!') -- returns the number of players who recived the message -- @usage Role.print('Admin','Hello, World!') -- returns the number of players who received the message
-- @tparam ?role|string role the role which acts as the turning point of the print (always included regardless of inv value) -- @tparam ?role|string role the role which acts as the turning point of the print (always included regardless of inv value)
-- @param rtn the value that will be returned to the players -- @param rtn the value that will be returned to the players
-- @tparam[opt] table colour the colour that you want the message printed in -- @tparam[opt] table colour the colour that you want the message printed in
-- @tparam[opt=false] boolean inv true to print to roles below, false to print to roles above -- @tparam[opt=false] boolean inv true to print to roles below, false to print to roles above
-- @treturn number the number of players who recived the message -- @treturn number the number of players who received the message
function Role.print(role,rtn,colour,inv) function Role.print(role,rtn,colour,inv)
local role = Role.get(role,true) role = Role.get(role,true)
if not type_error(role,'table','Invalid argument #1 to Role.print, role is invalid.') then return end if not type_error(role,'table','Invalid argument #1 to Role.print, role is invalid.') then return end
if colour and not type_error(colour,'table','Invalid argument #3 to Role.print, colour is not a table.') then return end if colour and not type_error(colour,'table','Invalid argument #3 to Role.print, colour is not a table.') then return end
if inv and not type_error(inv,'boolean','Invalid argument #4 to Role.print, inv is not a boolean.') then return end if inv and not type_error(inv,'boolean','Invalid argument #4 to Role.print, inv is not a boolean.') then return end
@@ -293,11 +295,11 @@ function Role.print(role,rtn,colour,inv)
return ctn return ctn
end end
--- Prints all registed roles and there important infomation (debug) --- Prints all registered roles and there important information (debug)
-- @tparam[opt] ?role|string the role to print the info of, if nil then all roles are printed in order of power -- @tparam[opt] ?role|string the role to print the info of, if nil then all roles are printed in order of power
-- @tparam[opt=game.player] ?LuaPlayer|pointerToPlayer the player to print the info to, default the player who ran command -- @tparam[opt=game.player] ?LuaPlayer|pointerToPlayer the player to print the info to, default the player who ran command
function Role.debug_output(role,player) function Role.debug_output(role,player)
local player = Game.get_player(player) or game.player player = Game.get_player(player) or game.player
if not player then error('Invalid player #2 given to Role.debug_output.',2) return end if not player then error('Invalid player #2 given to Role.debug_output.',2) return end
local function _output(_role) local function _output(_role)
local flags = {};for flag in pairs(Role.flags) do if _role:has_flag(flag) then table.insert(flags,flag) end end local flags = {};for flag in pairs(Role.flags) do if _role:has_flag(flag) then table.insert(flags,flag) end end
@@ -306,7 +308,7 @@ function Role.debug_output(role,player)
player_return(rtn,_role.colour,player) player_return(rtn,_role.colour,player)
end end
if role then if role then
local role = Role.get(mixed) role = Role.get(role)
if not type_error(role,'table','Invalid argument #1 to Role.print, role is invalid.') then return end if not type_error(role,'table','Invalid argument #1 to Role.print, role is invalid.') then return end
_output(role) _output(role)
else for index,_role in pairs(Role.roles) do _output(_role) end end else for index,_role in pairs(Role.roles) do _output(_role) end end
@@ -354,18 +356,18 @@ end
-- this is used to create a connected_players table -- this is used to create a connected_players table
Role._prototype.players_mt = { Role._prototype.players_mt = {
__call=function(tbl) return tbl.self:get_players(tbl.connected) end, __call=function(tbl) return tbl.self:get_players(tbl.connected) end,
__pairs=function(tbl) __pairs=function(tbl)
local players = tbl.self:get_players(tbl.connected) local players = tbl.self:get_players(tbl.connected)
local function next_pair(tbl,k) local function next_pair(tbl,key)
k, v = next(players, k) local k, v = next(players, key)
if v then return k,v end if v then return k,v end
end end
return next_pair, players, nil return next_pair, players, nil
end, end,
__ipairs=function(tbl) __ipairs=function(tbl)
local players = tbl.self:get_players(tbl.connected) local players = tbl.self:get_players(tbl.connected)
local function next_pair(tbl,k) local function next_pair(tbl,key)
k, v = next(players, k) local k, v = next(players, key)
if v then return k,v end if v then return k,v end
end end
return next_pair, players, nil return next_pair, players, nil
@@ -374,10 +376,10 @@ Role._prototype.players_mt = {
--- Prints a message to all players who have this role --- Prints a message to all players who have this role
-- @usage role:print('Hello, World!') -- retuns number of players who recived the message -- @usage role:print('Hello, World!') -- returns number of players who received the message
-- @param rtn the message to print to the players -- @param rtn the message to print to the players
-- @tparam[opt] table colour the colour to print the message in -- @tparam[opt] table colour the colour to print the message in
-- @treturn number the number of players who recived the message -- @treturn number the number of players who received the message
function Role._prototype:print(rtn,colour) function Role._prototype:print(rtn,colour)
if not self_test(self,'role','print') then return end if not self_test(self,'role','print') then return end
if colour and not type_error(colour,'table','Invalid argument #2 to Role.print, colour is not a table.') then return end if colour and not type_error(colour,'table','Invalid argument #2 to Role.print, colour is not a table.') then return end
@@ -387,8 +389,8 @@ function Role._prototype:print(rtn,colour)
end end
--- Returns a table that describes all the permissions and which this role is allowed --- Returns a table that describes all the permissions and which this role is allowed
-- @usage role:get_permissions() -- retuns table of permissions -- @usage role:get_permissions() -- returns table of permissions
-- @treturn table a table of permisions, only includes ones which were defined with Role.add_action -- @treturn table a table of permissions, only includes ones which were defined with Role.add_action
function Role._prototype:get_permissions() function Role._prototype:get_permissions()
if not self_test(self,'role','get_permissions') then return end if not self_test(self,'role','get_permissions') then return end
local rtn = {} local rtn = {}
@@ -400,12 +402,12 @@ end
-- @usage role:add_player(player) -- @usage role:add_player(player)
-- @tparam ?LuaPlayer|PointerToPlayer player the player to add -- @tparam ?LuaPlayer|PointerToPlayer player the player to add
-- @tparam[opt] ?LuaPlayer|PointerToPlayer by_player the player who ran the command -- @tparam[opt] ?LuaPlayer|PointerToPlayer by_player the player who ran the command
-- @tparam[opt] table batch this is used internally to provent multiple event calls -- @tparam[opt] table batch this is used internally to prevent multiple event calls
function Role._prototype:add_player(player,by_player,batch) function Role._prototype:add_player(player,by_player,batch)
if not self_test(self,'role','add_player') then return end if not self_test(self,'role','add_player') then return end
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to role:add_player.',2) return end if not player then error('Invalid player #1 given to role:add_player.',2) return end
local by_player = Game.get_player(by_player) or SERVER by_player = Game.get_player(by_player) or SERVER
if not global.roles[self.name] then global.roles[self.name] = {} end if not global.roles[self.name] then global.roles[self.name] = {} end
if not global.players[player.index] then global.players[player.index] = {} end if not global.players[player.index] then global.players[player.index] = {} end
local highest = Role.get_highest(player) or Role.meta.default local highest = Role.get_highest(player) or Role.meta.default
@@ -429,12 +431,12 @@ end
-- @usage role:remove_player(player) -- @usage role:remove_player(player)
-- @tparam ?LuaPlayer|PointerToPlayer player the player to remove -- @tparam ?LuaPlayer|PointerToPlayer player the player to remove
-- @tparam[opt] ?LuaPlayer|PointerToPlayer by_player the player who ran the command -- @tparam[opt] ?LuaPlayer|PointerToPlayer by_player the player who ran the command
-- @tparam[opt] table batch this is used internally to provent multiple event calls -- @tparam[opt] table batch this is used internally to prevent multiple event calls
function Role._prototype:remove_player(player,by_player,batch) function Role._prototype:remove_player(player,by_player,batch)
if not self_test(self,'role','add_player') then return end if not self_test(self,'role','add_player') then return end
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid player #1 given to role:remove_player.',2) return end if not player then error('Invalid player #1 given to role:remove_player.',2) return end
local by_player = Game.get_player(by_player) or SERVER by_player = Game.get_player(by_player) or SERVER
if not global.roles[self.name] then global.roles[self.name] = {} end if not global.roles[self.name] then global.roles[self.name] = {} end
if not global.players[player.index] then global.players[player.index] = {} end if not global.players[player.index] then global.players[player.index] = {} end
local highest = Role.get_highest(player) or Role.meta.default local highest = Role.get_highest(player) or Role.meta.default
@@ -458,13 +460,13 @@ end
-- Event Handlers Define -- Event Handlers Define
script.on_event(role_change_event_id,function(event) script.on_event(role_change_event_id,function(event)
-- varible init -- variable init
local player = Game.get_player(event) local player = Game.get_player(event)
local by_player = Game.get_player(event.by_player_index) or SERVER local by_player = Game.get_player(event.by_player_index) or SERVER
local role = Role.get(event.role_name) local role = Role.get(event.role_name)
local highest = Role.get_highest(player) local highest = Role.get_highest(player)
if not highest then Role.meta.default:add_player(player) highest = Role.meta.default end if not highest then Role.meta.default:add_player(player) highest = Role.meta.default end
-- gets the falgs the player currently has -- gets the flags the player currently has
for flag,callback in pairs(Role.flags) do if is_type(callback,'function') then callback(player,Role.has_flag(player,flag)) end end for flag,callback in pairs(Role.flags) do if is_type(callback,'function') then callback(player,Role.has_flag(player,flag)) end end
-- assign new tag and group of highest role -- assign new tag and group of highest role
Group.assign(player,highest.group) Group.assign(player,highest.group)
@@ -476,7 +478,7 @@ script.on_event(role_change_event_id,function(event)
-- send a message to other players -- send a message to other players
if event.batch_index == 1 then if event.batch_index == 1 then
local names = {} local names = {}
for _,name in pairs(event.batch) do local role = Role.get(name) if role then table.insert(names,role.name) end end for _,name in pairs(event.batch) do local next_role = Role.get(name) if next_role then table.insert(names,next_role.name) end end
if event.effect == 'assign' then if event.effect == 'assign' then
if not role.is_jail then player.play_sound{path='utility/achievement_unlocked'} end if not role.is_jail then player.play_sound{path='utility/achievement_unlocked'} end
game.print{'ExpGamingCore-Role.default-print',{'ExpGamingCore-Role.assign',player.name,table.concat(names,', '),by_player.name}} game.print{'ExpGamingCore-Role.default-print',{'ExpGamingCore-Role.assign',player.name,table.concat(names,', '),by_player.name}}
@@ -524,4 +526,4 @@ end)
-- Module Return -- Module Return
-- calling will attempt to define a new role -- calling will attempt to define a new role
return setmetatable(Role,{__call=function(tbl,...) return tbl.define(...) end}) return setmetatable(Role,{__call=function(tbl,...) return tbl.define(...) end})

View File

@@ -43,7 +43,7 @@ end
Sync.add_update('roles',function() Sync.add_update('roles',function()
if not game then return {'Offline'} end if not game then return {'Offline'} end
local _rtn = {} local _rtn = {}
for name,role in pairs(Role.roles) do for _,role in pairs(Role.roles) do
local players = role:get_players() local players = role:get_players()
local _players = {} local _players = {}
for k,player in pairs(players) do _players[k] = player.name end for k,player in pairs(players) do _players[k] = player.name end
@@ -57,20 +57,20 @@ end)
-- Adds a caption to the info gui that shows the rank given to the player -- Adds a caption to the info gui that shows the rank given to the player
if Sync.add_to_gui then if Sync.add_to_gui then
Sync.add_to_gui(function(player,frame) Sync.add_to_gui(function(player)
local names = {} local names = {}
for _,role in pairs(Role.get(player)) do table.insert(names,role.name) end for _,role in pairs(Role.get(player)) do table.insert(names,role.name) end
return 'You have been assigned the roles: '..table.concat(names,', ') return 'You have been assigned the roles: '..table.concat(names,', ')
end) end)
end end
-- adds a discord emit for rank chaning -- adds a discord emit for rank changing
script.on_event('on_role_change',function(event) script.on_event('on_role_change',function(event)
local role = Role.get(event.role_name) local role = Role.get(event.role_name)
local player = Game.get_player(event) local player = Game.get_player(event)
local by_player = Game.get_player(event.by_player_index) or SERVER local by_player = Game.get_player(event.by_player_index) or SERVER
if role.is_jail and RoleGlobal.last_change[1] ~= player.index then if role.is_jail and RoleGlobal.last_change[1] ~= player.index then
Sync.emit_embeded{ Sync.emit_embedded{
title='Player Jail', title='Player Jail',
color=Color.to_hex(defines.textcolor.med), color=Color.to_hex(defines.textcolor.med),
description='There was a player jailed.', description='There was a player jailed.',

View File

@@ -17,7 +17,7 @@ local module_verbose = false --true|false
-- @field tick an index for threads which will run every tick (contains uuids) -- @field tick an index for threads which will run every tick (contains uuids)
-- @field timeout an index for threads which will timeout (contains uuids) -- @field timeout an index for threads which will timeout (contains uuids)
-- @field events an index of threads based on event ids (contains uuids) -- @field events an index of threads based on event ids (contains uuids)
-- @field paused an index of pasued threads (contains uuids) -- @field paused an index of paused threads (contains uuids)
-- @field named a name index for thread uuids -- @field named a name index for thread uuids
-- @field print_to contains players that event details will be printed to -- @field print_to contains players that event details will be printed to
-- @field uuid contains the random number generator for the uuid system -- @field uuid contains the random number generator for the uuid system
@@ -39,7 +39,7 @@ local global = global{
-- @treturn string the new uuid -- @treturn string the new uuid
Server.uuid = add_metatable({},function() Server.uuid = add_metatable({},function()
-- when it is called as a function -- when it is called as a function
local uuid = 0 local uuid
if game then if game then
global.uuid=global.uuid+1 global.uuid=global.uuid+1
uuid=global.uuid+pre_load_uuid uuid=global.uuid+pre_load_uuid
@@ -68,8 +68,8 @@ Server.threads = setmetatable({},{
__newindex=function(tbl,key,value) rawset(global.all,key,value) end, __newindex=function(tbl,key,value) rawset(global.all,key,value) end,
__pairs=function(tbl) __pairs=function(tbl)
local tbl = global.all local tbl = global.all
local function next_pair(tbl,k) local function next_pair(tbl,key)
k, v = next(tbl, k) local k, v = next(tbl, key)
if type(v) ~= nil and k ~= '_n' then return k,v if type(v) ~= nil and k ~= '_n' then return k,v
else return next(tbl, k) end else return next(tbl, k) end
end end
@@ -79,15 +79,15 @@ Server.threads = setmetatable({},{
--- Generates a new thread object --- Generates a new thread object
-- @usage Server.new_thread{name='foo',data={}} -- @usage Server.new_thread{name='foo',data={}}
-- @tparam table obj the atributes to give to the thread -- @tparam table obj the attributes to give to the thread
-- @treturn Server._thread the new thread created -- @treturn Server._thread the new thread created
function Server.new_thread(obj) return Server._thread:create(obj) end function Server.new_thread(obj) return Server._thread:create(obj) end
--- Used to get a thread via uuid or name (if one is assied) --- Used to get a thread via uuid or name (if one is assigned)
-- @usage Server.get_thread('decon') -- return thread -- @usage Server.get_thread('decon') -- return thread
-- @param mixed either a uuid or the name given to a thread -- @param mixed either a uuid or the name given to a thread
-- @treturn[1] Server._thread the thread by that name or uuid -- @treturn[1] Server._thread the thread by that name or uuid
-- @treturn[2] boolean if false is returned then no thread existes -- @treturn[2] boolean if false is returned then no thread exists
function Server.get_thread(mixed) function Server.get_thread(mixed)
local threads = global local threads = global
if threads.named[mixed] then return threads.all[threads.named[mixed]] if threads.named[mixed] then return threads.all[threads.named[mixed]]
@@ -99,7 +99,7 @@ end
--- Adds a thread into the resolve queue, can be used to lower lag --- Adds a thread into the resolve queue, can be used to lower lag
-- @usage Server.queue_thread(thread) -- return true/false -- @usage Server.queue_thread(thread) -- return true/false
-- @tparam Server._thread thread_to_queue the thread to be added to the queue, must be open and have a on_resolve function -- @tparam Server._thread thread_to_queue the thread to be added to the queue, must be open and have a on_resolve function
-- @treturn boolean was it added successfuly -- @treturn boolean was it added successfully
function Server.queue_thread(thread_to_queue) function Server.queue_thread(thread_to_queue)
if not thread_to_queue and not thread_to_queue.valid and not thread_to_queue:valid() then return false end if not thread_to_queue and not thread_to_queue.valid and not thread_to_queue:valid() then return false end
if not thread_to_queue._resolve then return false end if not thread_to_queue._resolve then return false end
@@ -109,15 +109,15 @@ end
--- Closes all active threads, can use force if it causes errors --- Closes all active threads, can use force if it causes errors
-- @usage Server.close_all_threads() -- asks all threads to close -- @usage Server.close_all_threads() -- asks all threads to close
-- @usage Server.close_all_threads(true) -- forcefuly close all threads -- @usage Server.close_all_threads(true) -- forcefully close all threads
-- @tparam bolean with_force use force when closing -- @tparam boolean with_force use force when closing
function Server.close_all_threads(with_force) function Server.close_all_threads(with_force)
if not with_force then if not with_force then
for uuid,thread in pairs(Server.threads) do thread:close() end for uuid,thread in pairs(Server.threads) do thread:close() end
else global.Server(true) end -- idk why you cant just use global even when global is defined at the top to be over ridren else global.Server(true) end -- idk why you cant just use global even when global is defined at the top to be overridden
end end
--- Runs all the theads which have opened with an on_tick event --- Runs all the threads which have opened with an on_tick event
-- @usage Server.run_tick_threads() -- @usage Server.run_tick_threads()
function Server.run_tick_threads() function Server.run_tick_threads()
table.each(global.tick,function(uuid) table.each(global.tick,function(uuid)
@@ -146,8 +146,8 @@ end
-- @tparam ?name|index event the event that info will be returned fo -- @tparam ?name|index event the event that info will be returned fo
-- @tparam[opt=toggle] boolean state will info be returned, nil to toggle current state -- @tparam[opt=toggle] boolean state will info be returned, nil to toggle current state
function Server._thread_debuger(player,event,state) function Server._thread_debuger(player,event,state)
local player = Game.get_player(player) player = Game.get_player(player)
local event = tonumber(event) or Manager.event.names[event] event = tonumber(event) or Manager.event.names[event]
local print_to = global.print_to local print_to = global.print_to
print_to[player.index] = print_to[player.index] or {} print_to[player.index] = print_to[player.index] or {}
if state then print_to[player.index][event] = state if state then print_to[player.index][event] = state
@@ -155,12 +155,12 @@ function Server._thread_debuger(player,event,state)
else print_to[player.index][event] = true end else print_to[player.index][event] = true end
end end
--- Calles all threads on a certain game event (used with script.on_event) --- Calls all threads on a certain game event (used with script.on_event)
-- @local Server._thread_handler -- @local Server._thread_handler
-- @usage script.on_event(defines.events,Server._thread_handler) -- adds this handler -- @usage script.on_event(defines.events,Server._thread_handler) -- adds this handler
-- @tparam table event the event that is called -- @tparam table event the event that is called
function Server._thread_handler(event) function Server._thread_handler(event)
-- returns to players who have set _thread_debuger to trye -- returns to players who have set _thread_debuger to true
table.each(global.print_to,function(print_to,player_index,event) table.each(global.print_to,function(print_to,player_index,event)
if event.name == defines.events.on_tick then return true end if event.name == defines.events.on_tick then return true end
if print_to[event.name] then if print_to[event.name] then
@@ -189,7 +189,7 @@ end
--- Adds a event handler to tell threads about events --- Adds a event handler to tell threads about events
-- @usage Server.add_thread_handler(defines.event) -- @usage Server.add_thread_handler(defines.event)
-- @tparam number event the event to run the thread handler on` -- @tparam number event the event to run the thread handler on`
-- @treturn bolean if the handler was added -- @treturn boolean if the handler was added
function Server.add_thread_handler(event) function Server.add_thread_handler(event)
if not is_type(event,'number') then return false end if not is_type(event,'number') then return false end
local threads = global local threads = global
@@ -204,9 +204,9 @@ end
--- Acts as a bypass for running functions, can accept a string --- Acts as a bypass for running functions, can accept a string
-- @usage Server.interface('local x = 1+1 print(x) return x') -- return 2 -- @usage Server.interface('local x = 1+1 print(x) return x') -- return 2
-- @usage Server.interface('local x = 1+1 print(x)',true) -- will creat a thread to run as root (this is the bypass) -- @usage Server.interface('local x = 1+1 print(x)',true) -- will create a thread to run as root (this is the bypass)
-- @tparam ?string|function callback function to be ran -- @tparam ?string|function callback function to be ran
-- @tparam[opt] ?Server._thread|true use_thread run the command on a premade thread or let it make its own -- @tparam[opt] ?Server._thread|true use_thread run the command on a pre-made thread or let it make its own
-- @tparam[opt] table env run the env to run the command in must have _env key as true to be -- @tparam[opt] table env run the env to run the command in must have _env key as true to be
-- @param[opt] ... any args you want to pass to the function -- @param[opt] ... any args you want to pass to the function
-- @treturn[1] boolean if no thread then it will return a true for the success -- @treturn[1] boolean if no thread then it will return a true for the success
@@ -219,15 +219,15 @@ function Server.interface(callback,use_thread,env,...)
if use_thread == true then use_thread = Server.new_thread{data={callback,env,...}} end if use_thread == true then use_thread = Server.new_thread{data={callback,env,...}} end
-- creates the resolve function for the thread -- creates the resolve function for the thread
use_thread:on_event('resolve',function(thread) use_thread:on_event('resolve',function(thread)
local callback = table.remove(thread.data,1) local thread_callback = table.remove(thread.data,1)
callback = is_type(callback,'function') and callback or loadstring(callback) thread_callback = is_type(thread_callback,'function') and thread_callback or loadstring(thread_callback)
local env = table.remove(thread.data,1) local thread_env = table.remove(thread.data,1)
if is_type(env,'table') and not is_type(env.__self,'userdata') and env._env == true then if is_type(thread_env,'table') and not is_type(thread_env.__self,'userdata') and thread_env._env == true then
local success, err = Manager.sandbox(callback,env,unpack(thread.data)) local success, err = Manager.sandbox(thread_callback,thread_env,unpack(thread.data))
if not success then error(err) end if not success then error(err) end
return err return err
else else
local success, err = Manager.sandbox(callback,{},env,unpack(thread.data)) local success, err = Manager.sandbox(thread_callback,{},env,unpack(thread.data))
if not success then error(err) end if not success then error(err) end
return err return err
end end
@@ -254,13 +254,13 @@ function Server.interface(callback,use_thread,env,...)
end end
end end
--- The class for the server threads, allows abbilty to run async function --- The class for the server threads, allows ability to run async function
-- @type Thread -- @type Thread
-- @alias Server._thread -- @alias Server._thread
-- @field name the name that is given to the thread, use for easy later indexing -- @field name the name that is given to the thread, use for easy later indexing
-- @field timeout the time in ticks that the thread will have before it times out -- @field timeout the time in ticks that the thread will have before it times out
-- @field reopen when true the thread will reopen itself untill set to false, combine with timeout to create a long on_nth_tick wait -- @field reopen when true the thread will reopen itself until set to false, combine with timeout to create a long on_nth_tick wait
-- @field data any data that the thread will beable to access -- @field data any data that the thread will be able to access
Server._thread = {} Server._thread = {}
local _env_metatable = { local _env_metatable = {
@@ -271,15 +271,15 @@ local _env_metatable = {
-- @usage new_thread = thread:create() -- @usage new_thread = thread:create()
-- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any} -- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any}
-- @treturn Server._thread the new thread object -- @treturn Server._thread the new thread object
function Server._thread:create(obj) function Server._thread.create(obj)
local obj = obj or {} obj = obj or {}
setmetatable(obj,{__index=Server._thread}) setmetatable(obj,{__index=Server._thread})
obj.uuid = tostring(Server.uuid) obj.uuid = tostring(Server.uuid)
-- creates a varible containg all upvalus for the thread (stops desyncs) -- creates a variable containing all upvalus for the thread (stops desyncs)
obj._env = get_upvalues(2) obj._env = get_upvalues(2)
obj._env._env = true obj._env._env = true
obj._env._ENV = nil -- provents infinte recusion obj._env._ENV = nil -- prevents infinite recursion
-- removes any modules from the _env to save space in global (less time to serizle) -- removes any modules from the _env to save space in global (less time to serialize)
obj._env._modules = {} obj._env._modules = {}
for name,value in pairs(obj._env) do if is_type(value,'table') and value._moduleName and loaded_modules[value._moduleName] == value then obj._env._modules[name] = value._moduleName obj._env[name] = nil end end for name,value in pairs(obj._env) do if is_type(value,'table') and value._moduleName and loaded_modules[value._moduleName] == value then obj._env._modules[name] = value._moduleName obj._env[name] = nil end end
setmetatable(obj._env,_env_metatable) setmetatable(obj._env,_env_metatable)
@@ -288,21 +288,21 @@ function Server._thread:create(obj)
return obj return obj
end end
--- Opens and queses a thread --- Opens and queues a thread
-- @usage Server._thread:queue() -- returns true/false -- @usage Server._thread:queue() -- returns true/false
-- @treturn boolean was the thread queued successfuly -- @treturn boolean was the thread queued successfully
-- @see Server.queue_thread -- @see Server.queue_thread
function Server._thread:queue() function Server._thread:queue()
self:open() self:open()
return Server.queue_thread(self) return Server.queue_thread(self)
end end
--- Test if the thread has all requied parts --- Test if the thread has all required parts
-- @usage if thread:valid() then end -- basic test for valid -- @usage if thread:valid() then end -- basic test for valid
-- @tparam[opt=false] bolean skip_location_check true to skip the location checking -- @tparam[opt=false] boolean skip_location_check true to skip the location checking
-- @treturn boolean is the thread valid -- @treturn boolean is the thread valid
function Server._thread:valid(skip_location_check) function Server._thread:valid(skip_location_check)
local skip_location_check = skip_location_check or false skip_location_check = skip_location_check or false
if is_type(self.uuid,'string') and if is_type(self.uuid,'string') and
skip_location_check or is_type(self.opened,'number') and skip_location_check or is_type(self.opened,'number') and
skip_location_check or is_type(global.all[self.uuid],'table') and skip_location_check or is_type(global.all[self.uuid],'table') and
@@ -314,34 +314,34 @@ function Server._thread:valid(skip_location_check)
is_type(self._resolve) or is_type(self._resolve,'function') and is_type(self._resolve) or is_type(self._resolve,'function') and
is_type(self._success) or is_type(self._success,'function') and is_type(self._success) or is_type(self._success,'function') and
is_type(self._error) or is_type(self._error,'function') then is_type(self._error) or is_type(self._error,'function') then
-- all above must be true to be vaild, must accept nil and function -- all above must be true to be valid, must accept nil and function
return true return true
end end
return false return false
end end
--- Opens the thread; indexs this thread in the global index --- Opens the thread; indexes this thread in the global index
-- @usage thread:open() -- return true -- @usage thread:open() -- return true
-- @treturn bolean if the thread was opened successfuly -- @treturn boolean if the thread was opened successfully
function Server._thread:open() function Server._thread:open()
-- if the thread is valid and not already opended -- if the thread is valid and not already opened
if not self:valid(true) or self.opened then return false end if not self:valid(true) or self.opened then return false end
local uuid = self.uuid local uuid = self.uuid
-- sets the thread to open, this is the tick it was opened -- sets the thread to open, this is the tick it was opened
self.opened = game.tick self.opened = game.tick
-- creats the global index -- creates the global index
global.all[uuid] = global.all[uuid] or self global.all[uuid] = global.all[uuid] or self
global.all._n = global.all._n+1 global.all._n = global.all._n+1
-- indexs the thread in other places if it has more function -- indexes the thread in other places if it has more function
-- if it was paused before (ie did not run any events) then the index is removed from the paused index -- if it was paused before (ie did not run any events) then the index is removed from the paused index
if global.paused[self.name] then global.paused[self.name] = nil end if global.paused[self.name] then global.paused[self.name] = nil end
-- if it has a timeout or on_tick handler then it is indexed in those indexs -- if it has a timeout or on_tick handler then it is indexed in those indexes
if is_type(self.timeout,'number') then table.insert(global.timeout,uuid) end if is_type(self.timeout,'number') then table.insert(global.timeout,uuid) end
if is_type(self._tick,'function') then table.insert(global.tick,uuid) end if is_type(self._tick,'function') then table.insert(global.tick,uuid) end
-- if the thread is given a name then a index from the name to uuid is made -- if the thread is given a name then a index from the name to uuid is made
if is_type(self.name,'string') then global.named[self.name] = global.named[self.name] or self.uuid end if is_type(self.name,'string') then global.named[self.name] = global.named[self.name] or self.uuid end
-- if there are event handlers then it will loop over them and add them to the event index -- if there are event handlers then it will loop over them and add them to the event index
if is_type(self._events,'table') then if is_type(self._events,'table') then
table.each(self._events,function(callback,event,global,uuid) table.each(self._events,function(callback,event,global,uuid)
-- cant be used V -- cant be used V
--Server.add_thread_handler(event) --Server.add_thread_handler(event)
@@ -354,7 +354,7 @@ function Server._thread:open()
return true return true
end end
--- Inverse of thread:open() - Removes all indexs to this thread, most cases this will cause it to become inassible --- Inverse of thread:open() - Removes all indexes to this thread, most cases this will cause it to become inaccessible
-- @usage thread:close() -- return true -- @usage thread:close() -- return true
-- @treturn boolean if the thread had a on_close function -- @treturn boolean if the thread had a on_close function
function Server._thread:close() function Server._thread:close()
@@ -363,17 +363,17 @@ function Server._thread:close()
-- if there is a call to the threads on close event, will later return true -- if there is a call to the threads on close event, will later return true
if is_type(self._close,'function') then Manager.sandbox(self._close,self._env,self) _return = true end if is_type(self._close,'function') then Manager.sandbox(self._close,self._env,self) _return = true end
-- will search every possible location for this thread and remove it -- will search every possible location for this thread and remove it
local value,key = table.find(global.queue,function(v,k,uuid) return v == uuid end,uuid) local _,key = table.find(global.queue,function(v,k,uuid) return v == uuid end,uuid)
if key then table.remove(global.queue,key) end -- queue if key then table.remove(global.queue,key) end -- queue
local value,key = table.find(global.timeout,function(v,k,uuid) return v == uuid end,uuid) _,key = table.find(global.timeout,function(v,k,uuid) return v == uuid end,uuid)
if key then table.remove(global.timeout,key) end -- timeouts if key then table.remove(global.timeout,key) end -- timeouts
local value,key = table.find(global.tick,function(v,k,uuid) return v == uuid end,uuid) _,key = table.find(global.tick,function(v,k,uuid) return v == uuid end,uuid)
if key then table.remove(global.tick,key) end -- on_tick if key then table.remove(global.tick,key) end -- on_tick
-- then will look for it in the event handlers and remove it if found -- then will look for it in the event handlers and remove it if found
if is_type(self._events,'table') then if is_type(self._events,'table') then
table.each(self._events,function(callback,event) table.each(self._events,function(callback,event)
if global.events[event] then if global.events[event] then
local value,key = table.find(global.events[event],function(v,k,uuid) return v == uuid end,uuid) local _,key = table.find(global.events[event],function(v,k,uuid) return v == uuid end,uuid)
if key then table.remove(global.events[event],key) end if key then table.remove(global.events[event],key) end
-- cant be used V -- cant be used V
--if #global.events[event] == 0 then Event.remove(event,Server.game_event) global.events[event] = nil end --if #global.events[event] == 0 then Event.remove(event,Server.game_event) global.events[event] = nil end
@@ -382,9 +382,9 @@ function Server._thread:close()
end end
-- sets the thread to closed -- sets the thread to closed
self.opened=nil self.opened=nil
-- unless the thread has a name or is assied to be reopened -- unless the thread has a name or is assigned to be reopened
if self.reopen == true then self:open() else if self.reopen == true then self:open() else
-- if it has a name but not assied to reopen then it will become 'pasued' -- if it has a name but not assigned to reopen then it will become 'paused'
if is_type(self.name,'string') then global.paused[self.name]=self.uuid if is_type(self.name,'string') then global.paused[self.name]=self.uuid
-- else it will just be wiped from the global index -- else it will just be wiped from the global index
else global.all[uuid] = nil global.all._n = global.all._n-1 end else global.all[uuid] = nil global.all._n = global.all._n-1 end
@@ -397,19 +397,19 @@ end
--- Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async) --- Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async)
-- @usage thread:resolve(x,y,z) -- return true -- @usage thread:resolve(x,y,z) -- return true
-- @param[opt] ... any arguments you want to pass to the resolve function -- @param[opt] ... any arguments you want to pass to the resolve function
-- @treturn bolean true if the thread called on_success or on_error -- @treturn boolean true if the thread called on_success or on_error
function Server._thread:resolve(...) function Server._thread:resolve(...)
local _return = false local _return = false
-- checks if the resolve haddler is still present -- checks if the resolve handler is still present
if is_type(self._resolve,'function') then if is_type(self._resolve,'function') then
local success, err = Manager.sandbox(self._resolve,self._env,self,...) local success, err = Manager.sandbox(self._resolve,self._env,self,...)
if success then if success then
-- if it was successful then it will attemp to call the success handler -- if it was successful then it will attempt to call the success handler
if is_type(self._success,'function') then if is_type(self._success,'function') then
-- interface is used as a way to delay the success call till the next tick -- interface is used as a way to delay the success call till the next tick
Server.interface(function(thread,err) Server.interface(function(thread,err)
local success, err = Manager.sandbox(thread._success,thread._env,thread,err) local _success, _err = Manager.sandbox(thread._success,thread._env,thread,err)
if not success then thread:error(err) end if not _success then thread:error(_err) end
end,true,self,err) end,true,self,err)
-- later returns true if there was a call to the success handler -- later returns true if there was a call to the success handler
_return = true _return = true
@@ -422,9 +422,9 @@ function Server._thread:resolve(...)
return _return return _return
end end
--- Checks the timeout on a thread - if timed out then it calles on_timeout and closes --- Checks the timeout on a thread - if timed out then it calls on_timeout and closes
-- @usage thread:check_timeout() -- return true -- @usage thread:check_timeout() -- return true
-- @treturn bolean if the thread timed out -- @treturn boolean if the thread timed out
function Server._thread:check_timeout() function Server._thread:check_timeout()
local _return = false local _return = false
-- makes sure the thread is still valid -- makes sure the thread is still valid
@@ -436,7 +436,7 @@ function Server._thread:check_timeout()
Manager.sandbox(self._timeout,self._env,self) Manager.sandbox(self._timeout,self._env,self)
end end
_return = true _return = true
-- closes the thread to provent any further event calls -- closes the thread to prevent any further event calls
self:close() self:close()
end end
return _return return _return
@@ -444,7 +444,7 @@ end
--- Used to check and raise the error handler of the thread, if not present it raises an error --- Used to check and raise the error handler of the thread, if not present it raises an error
-- @usage thread:error(err) -- return true -- @usage thread:error(err) -- return true
-- @tparam string err the err to be rasied -- @tparam string err the err to be raised
-- @treturn boolean did the thread have an error handler -- @treturn boolean did the thread have an error handler
function Server._thread:error(err) function Server._thread:error(err)
local _return = false local _return = false
@@ -453,12 +453,12 @@ function Server._thread:error(err)
_return = true _return = true
else else
self:close() -- no matter what happens next this thread will be closed self:close() -- no matter what happens next this thread will be closed
error('Thread Error (no handler): '..err) error('Thread Error (no handler): '..err)
end end
return _return return _return
end end
--- Set function to run then an event is triggered, none of them are 'needed' but you are advised to have atleast one --- Set function to run then an event is triggered, none of them are 'needed' but you are advised to have at least one
-- @usage thread:on_event('close',function) -- if event is not one below then a game event is used -- @usage thread:on_event('close',function) -- if event is not one below then a game event is used
-- @usage thread_only_events = ['close','timeout','tick','resolve','success','error'] -- @usage thread_only_events = ['close','timeout','tick','resolve','success','error']
-- @tparam ?string|index event the name of the event that the function should be called on -- @tparam ?string|index event the name of the event that the function should be called on
@@ -466,7 +466,7 @@ end
-- @treturn table returns self so that they can be chained together -- @treturn table returns self so that they can be chained together
function Server._thread:on_event(event,callback) function Server._thread:on_event(event,callback)
local events = {'close','timeout','tick','resolve','success','error'} local events = {'close','timeout','tick','resolve','success','error'}
-- seaches the above list for the event -- searches the above list for the event
local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event) local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event)
if value and is_type(callback,'function') then if value and is_type(callback,'function') then
-- if it is a thread_only_event then it will add it to its core values -- if it is a thread_only_event then it will add it to its core values
@@ -492,7 +492,7 @@ script.on_event(defines.events.on_tick,function(event)
end) end)
script.on_load(function(event) script.on_load(function(event)
-- sets up metatable again so that threads contiune to work -- sets up metatable again so that threads continue to work
for uuid,thread in pairs(Server.threads) do for uuid,thread in pairs(Server.threads) do
setmetatable(thread,{__index=Server._thread}) setmetatable(thread,{__index=Server._thread})
setmetatable(thread._env,_env_metatable) setmetatable(thread._env,_env_metatable)
@@ -535,7 +535,7 @@ return Server
end) end)
thread:open() thread:open()
all on_event functions can be chained from the thread creation rather than use varibles eg: all on_event functions can be chained from the thread creation rather than use variables eg:
Server.new_thread{ Server.new_thread{
name='tree-decon', name='tree-decon',
data={} data={}

View File

@@ -7,7 +7,6 @@
--- This file will be loaded when ExpGamingCore.Command is present --- This file will be loaded when ExpGamingCore.Command is present
-- @function _comment -- @function _comment
local Game = require('FactorioStdLib.Game')
local Server = Server local Server = Server
Server.interfaceCallbacks = {} Server.interfaceCallbacks = {}
@@ -40,7 +39,7 @@ commands.add_command('interface','Runs the given input from the script', {
env.tile = game.player.surface.get_tile(game.player.position) env.tile = game.player.surface.get_tile(game.player.position)
end end
-- adds custom callbacks to the interface -- adds custom callbacks to the interface
for name,callback in pairs(Server.interfaceCallbacks) do env[name] = callback() end for name,custom_callback in pairs(Server.interfaceCallbacks) do env[name] = custom_callback() end
-- runs the function -- runs the function
local success, err = Server.interface(callback,false,env) local success, err = Server.interface(callback,false,env)
-- if there is an error then it will remove the stacktrace and return the error -- if there is an error then it will remove the stacktrace and return the error

View File

@@ -1,4 +1,4 @@
--- Allows syncing with an outside server and info panle. --- Allows syncing with an outside server and info panel.
-- @module ExpGamingCore.Sync -- @module ExpGamingCore.Sync
-- @alias Sync -- @alias Sync
-- @author Cooldude2606 -- @author Cooldude2606
@@ -16,10 +16,10 @@ local module_verbose = false --true|false
-- @field server_name the server name -- @field server_name the server name
-- @field server_description a short description of the server -- @field server_description a short description of the server
-- @field reset_time the reset time of the server -- @field reset_time the reset time of the server
-- @field time the last knowen irl time -- @field time the last known irl time
-- @field time_set the last in game time that the time was set -- @field time_set the last in game time that the time was set
-- @field last_update the last time that this info was updated -- @field last_update the last time that this info was updated
-- @field time_period how often this infomation is updated -- @field time_period how often this information is updated
-- @field players a list of different player related states -- @field players a list of different player related states
-- @field ranks a list of player ranks -- @field ranks a list of player ranks
-- @field rockets the number of rockets launched -- @field rockets the number of rockets launched
@@ -58,9 +58,9 @@ local global = global{
-- @field afk_players the number of afk players -- @field afk_players the number of afk players
-- @field times the play times of every player -- @field times the play times of every player
--- Used to standidise the tick format for any sync info --- Used to standardise the tick format for any sync info
-- @usage Sync.tick_format(60) -- return {60,'1.00M'} -- @usage Sync.tick_format(60) -- return {60,'1.00M'}
-- @treturn {number,string} table containg both the raw number and clean version of a time -- @treturn {number,string} table containing both the raw number and clean version of a time
function Sync.tick_format(tick) function Sync.tick_format(tick)
if not is_type(tick,'number') then error('Tick was not given to Sync.tick_format',2) end if not is_type(tick,'number') then error('Tick was not given to Sync.tick_format',2) end
return {tick,tick_to_display_format(tick)} return {tick,tick_to_display_format(tick)}
@@ -70,7 +70,7 @@ end
-- @usage Sync.print('Test','Cooldude2606') -- @usage Sync.print('Test','Cooldude2606')
-- @tparam string player_message the message to be printed in chat -- @tparam string player_message the message to be printed in chat
-- @tparam string player_name the name of the player sending the message -- @tparam string player_name the name of the player sending the message
-- @tparam[opt] string player_tag the tag apllied to the player's name -- @tparam[opt] string player_tag the tag applied to the player's name
-- @tparam[opt] string player_colour the colour of the message, either hex or named colour -- @tparam[opt] string player_colour the colour of the message, either hex or named colour
-- @tparam[opt] string prefix add a prefix before the chat eg [IRC] -- @tparam[opt] string prefix add a prefix before the chat eg [IRC]
function Sync.print(player_message,player_name,player_tag,player_colour,prefix) function Sync.print(player_message,player_name,player_tag,player_colour,prefix)
@@ -78,8 +78,8 @@ function Sync.print(player_message,player_name,player_tag,player_colour,prefix)
local player = game.player or game.players[player_name] local player = game.player or game.players[player_name]
local tag = player_tag and player_tag ~= '' and ' '..player_tag or '' local tag = player_tag and player_tag ~= '' and ' '..player_tag or ''
local colour = type(player_colour) == 'string' and player_colour or '#FFFFFF' local colour = type(player_colour) == 'string' and player_colour or '#FFFFFF'
local prefix = prefix and prefix..' ' or '' prefix = prefix and prefix..' ' or ''
-- if it is an ingame player it will over ride the given params -- if it is an in game player it will over ride the given params
if player then if player then
tag = ' '..player.tag tag = ' '..player.tag
colour = player.chat_color colour = player.chat_color
@@ -92,7 +92,7 @@ function Sync.print(player_message,player_name,player_tag,player_colour,prefix)
game.print(prefix..player_name..tag..': '..player_message,colour) game.print(prefix..player_name..tag..': '..player_message,colour)
end end
--- Outline of the paramaters accepted by Sync.emit_embeded --- Outline of the parameters accepted by Sync.emit_embedded
-- @table EmitEmbededParamaters -- @table EmitEmbededParamaters
-- @field title the tile of the embed -- @field title the tile of the embed
-- @field color the color given in hex you can use Color.to_hex{r=0,g=0,b=0} -- @field color the color given in hex you can use Color.to_hex{r=0,g=0,b=0}
@@ -102,11 +102,11 @@ end
-- @field fieldtwo the filed to add to the embed (key is name) (value is text) (start value with &lt;&lt;inline&gt;&gt; to make inline) -- @field fieldtwo the filed to add to the embed (key is name) (value is text) (start value with &lt;&lt;inline&gt;&gt; to make inline)
--- Logs an embed to the json.data we use a js script to add things we cant here --- Logs an embed to the json.data we use a js script to add things we cant here
-- @usage Sync.emit_embeded{title='BAN',color='0x0',description='A player was banned' ... } -- @usage Sync.emit_embedded{title='BAN',color='0x0',description='A player was banned' ... }
-- @tparam table args a table which contains everything that the embeded will use -- @tparam table args a table which contains everything that the embedded will use
-- @see EmitEmbededParamaters -- @see EmitEmbededParamaters
function Sync.emit_embeded(args) function Sync.emit_embedded(args)
if not is_type(args,'table') then error('Args table not given to Sync.emit_embeded',2) end if not is_type(args,'table') then error('Args table not given to Sync.emit_embedded',2) end
if not game then error('Game has not loaded',2) end if not game then error('Game has not loaded',2) end
local title = is_type(args.title,'string') and args.title or '' local title = is_type(args.title,'string') and args.title or ''
local color = is_type(args.color,'string') and args.color:find("0x") and args.color or '0x0' local color = is_type(args.color,'string') and args.color:find("0x") and args.color or '0x0'
@@ -130,14 +130,14 @@ function Sync.emit_embeded(args)
table.insert(fields,f) table.insert(fields,f)
end end
end end
-- forms the data that will be emited to the file -- forms the data that will be emitted to the file
local log_data = { local log_data = {
title=title, title=title,
description=description, description=description,
color=color, color=color,
fields=fields fields=fields
} }
game.write_file('embeded.json',table.json(log_data)..'\n',true,0) game.write_file('embedded.json',table.json(log_data)..'\n',true,0)
end end
--- The error handle setup by sync to emit a discord embed for any errors --- The error handle setup by sync to emit a discord embed for any errors
@@ -147,7 +147,7 @@ end
error.addHandler('Discord Emit',function(err) error.addHandler('Discord Emit',function(err)
if not game then return error(error()) end if not game then return error(error()) end
local color = Color and Color.to_hex(defines.textcolor.bg) or '0x0' local color = Color and Color.to_hex(defines.textcolor.bg) or '0x0'
Sync.emit_embeded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err} Sync.emit_embedded{title='SCRIPT ERROR',color=color,description='There was an error in the script @Developers ',Error=err}
end) end)
--- Used to get the number of admins currently online --- Used to get the number of admins currently online
@@ -169,7 +169,7 @@ end
-- @treturn number the number of afk players -- @treturn number the number of afk players
function Sync.count_afk_times(time) function Sync.count_afk_times(time)
if not game then return 0 end if not game then return 0 end
local time = time or 7200 time = time or 7200
local rtn = {} local rtn = {}
for _,player in pairs(game.connected_players) do for _,player in pairs(game.connected_players) do
if player.afk_time > time then rtn[player.name] = Sync.tick_format(player.afk_time) end if player.afk_time > time then rtn[player.name] = Sync.tick_format(player.afk_time) end
@@ -236,15 +236,15 @@ Sync.info = setmetatable({},{
return true return true
end, end,
__pairs=function(tbl) __pairs=function(tbl)
local tbl = global tbl = global
local function next_pair(tbl,k) local function next_pair(tbl,key)
k, v = next(tbl, k) local k, v = next(tbl, key)
if type(v) ~= nil then return k,v end if type(v) ~= nil then return k,v end
end end
return next_pair, tbl, nil return next_pair, tbl, nil
end, end,
__ipairs=function(tbl) __ipairs=function(tbl)
local tbl = global tbl = global
local function next_pair(tbl, i) local function next_pair(tbl, i)
i = i + 1 i = i + 1
local v = tbl[i] local v = tbl[i]
@@ -305,7 +305,7 @@ end
-- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018') -- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018')
-- @usage Sync.time -- string -- @usage Sync.time -- string
-- @tparam[opt=nil] string set the date time to be set -- @tparam[opt=nil] string set the date time to be set
-- @treturn boolean if the datetime set was successful -- @treturn boolean if the date time set was successful
Sync.time=add_metatable({},function(full,date) Sync.time=add_metatable({},function(full,date)
local info = Sync.info local info = Sync.info
if not is_type(full,'string') then return false end if not is_type(full,'string') then return false end

View File

@@ -1,4 +1,4 @@
--- Allows syncing with an outside server and info panle. --- Allows syncing with an outside server and info panel.
-- @submodule ExpGamingCore.Sync -- @submodule ExpGamingCore.Sync
-- @alias Sync -- @alias Sync
-- @author Cooldude2606 -- @author Cooldude2606
@@ -7,17 +7,16 @@
--- This file will be loaded when ExpGamingCore.Gui is present --- This file will be loaded when ExpGamingCore.Gui is present
-- @function _comment -- @function _comment
local Game = require('FactorioStdLib.Game')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local Sync = Sync -- this is to force sync to remain in the ENV local Sync = Sync -- this is to force sync to remain in the ENV
local Sync_gui_functions = {} local Sync_gui_functions = {}
local logo_sprite_path = 'file'..string.sub(module_path,2)..'/src/logo.png' local logo_sprite_path = 'file'..string.sub(module_path,2)..'/src/logo.png'
--- Adds a emeltent to the sever info gui --- Adds a element to the sever info gui
-- @usage Sync.add_to_gui('string') -- return true -- @usage Sync.add_to_gui('string') -- return true
-- @param element see examples before for what can be used, it can also be a return from Gui.inputs.add -- @param element see examples before for what can be used, it can also be a return from Gui.inputs.add
-- @treturn bolean based on weather it was successful or not -- @treturn boolean based on weather it was successful or not
function Sync.add_to_gui(element,...) function Sync.add_to_gui(element,...)
if game then return false end if game then return false end
if is_type(element,'function') then if is_type(element,'function') then
@@ -29,10 +28,10 @@ function Sync.add_to_gui(element,...)
return true return true
end end
Sync.add_to_gui('Welcome to the Explosive Gaming comunity! This is one of many servers which we host.') Sync.add_to_gui('Welcome to the Explosive Gaming community! This is one of many servers which we host.')
Sync.add_to_gui(function(player,frame) return 'This server\'s next reset: '..Sync.info.reset_time end) Sync.add_to_gui(function(player,frame) return 'This server\'s next reset: '..Sync.info.reset_time end)
--- Formats a lable to be a certain format --- Formats a label to be a certain format
-- @local label_format -- @local label_format
local function label_format(label,width) local function label_format(label,width)
label.style.width = width label.style.width = width
@@ -49,7 +48,7 @@ Sync.info_gui = Gui.center{
draw=function(self,frame) draw=function(self,frame)
frame.caption = '' frame.caption = ''
local info = Sync.info local info = Sync.info
local frame = frame.add{type='flow',direction='vertical'} frame = frame.add{type='flow',direction='vertical'}
local h_flow = frame.add{type='flow'} local h_flow = frame.add{type='flow'}
h_flow.add{type='sprite',sprite=logo_sprite_path} h_flow.add{type='sprite',sprite=logo_sprite_path}
local v_flow = h_flow.add{type='flow',direction='vertical'} local v_flow = h_flow.add{type='flow',direction='vertical'}
@@ -68,7 +67,7 @@ Sync.info_gui = Gui.center{
Gui.bar(_flow,110) Gui.bar(_flow,110)
Gui.bar(frame,600) Gui.bar(frame,600)
local _frame = frame local _frame = frame
local frame = frame.add{ frame = frame.add{
type='frame', type='frame',
direction='vertical', direction='vertical',
style='image_frame' style='image_frame'

View File

@@ -2,11 +2,10 @@
-- @module ExpGamingInfo.Readme -- @module ExpGamingInfo.Readme
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game')
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
@@ -65,12 +64,12 @@ end):add_tab('commands',{'ExpGamingInfo-Readme.commands-name'},{'ExpGamingInfo-R
type='label', type='label',
caption='/'..command.name caption='/'..command.name
} }
local discription = table.add{ local description = table.add{
type='label', type='label',
caption=command.description, caption=command.description,
} }
discription.style.maximal_width = 400 description.style.maximal_width = 400
discription.style.single_line = false description.style.single_line = false
end end
end):add_tab('links',{'ExpGamingInfo-Readme.links-name'},{'ExpGamingInfo-Readme.links-tooltip'},function(frame) end):add_tab('links',{'ExpGamingInfo-Readme.links-name'},{'ExpGamingInfo-Readme.links-tooltip'},function(frame)
local links={ local links={
@@ -87,7 +86,7 @@ end):add_tab('links',{'ExpGamingInfo-Readme.links-name'},{'ExpGamingInfo-Readme.
text_box.selectable = true text_box.selectable = true
end end
for i,link in pairs(links) do for i,link in pairs(links) do
frame.add{ frame.add{
type="label", type="label",
caption={'ExpGamingInfo-Readme.links-cap'..tostring(i)}, caption={'ExpGamingInfo-Readme.links-cap'..tostring(i)},
style='caption_label' style='caption_label'

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingInfo.Rockets -- @module ExpGamingInfo.Rockets
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
@@ -74,20 +74,20 @@ ThisModule.Gui = Gui.left{
type='flow', type='flow',
direction='vertical' direction='vertical'
} }
for milestone,time in pairs(global.milestones) do for milestone,next_time in pairs(global.milestones) do
local milestone = tonumber(milestone:match('%d+')) milestone = tonumber(milestone:match('%d+'))
if time == 0 and satellites == milestone then if next_time == 0 and satellites == milestone then
global.milestones['m'..milestone] = global.last global.milestones['m'..milestone] = global.last
time = global.last next_time = global.last
Gui.left.open('rockets') Gui.left.open('rockets')
end end
local _time = {'ExpGamingInfo-Rockets.nan'} local _time = {'ExpGamingInfo-Rockets.nan'}
if time > 0 then _time = tick_to_display_format(time) end if next_time > 0 then _time = tick_to_display_format(next_time) end
milestones.add{ milestones.add{
type='label', type='label',
caption={'ExpGamingInfo-Rockets.format',tostring(milestone),_time} caption={'ExpGamingInfo-Rockets.format',tostring(milestone),_time}
} }
if time == 0 then break end if next_time == 0 then break end
end end
end, end,
can_open=function(player) can_open=function(player)

View File

@@ -13,8 +13,8 @@ Sync.add_update('rockets',function()
_return.time = Sync.tick_format(time) _return.time = Sync.tick_format(time)
_return.fastest = Sync.tick_format(global.fastest) _return.fastest = Sync.tick_format(global.fastest)
_return.milestones = {} _return.milestones = {}
for milestone,time in pairs(global.milestones) do for milestone,next_time in pairs(global.milestones) do
_return.milestones[milestone] = Sync.tick_format(time) _return.milestones[milestone] = Sync.tick_format(next_time)
end end
return _return return _return
end) end)

View File

@@ -1,14 +1,14 @@
--- Adds a science count gui to the game that shows toatal made and per minute --- Adds a science count gui to the game that shows total made and per minute
-- @module ExpGamingInfo.Science -- @module ExpGamingInfo.Science
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
-- Local Varibles -- Local Variables
local science_packs = { local science_packs = {
'science-pack-1', 'science-pack-1',
'science-pack-2', 'science-pack-2',
@@ -23,7 +23,7 @@ local science_packs = {
local module_verbose = false local module_verbose = false
local ThisModule = { local ThisModule = {
on_init=function() on_init=function()
if loaded_modules['ExpGamingCore.Sync^4.0.0'] then require(module_path..'/src/sync') end if loaded_modules['ExpGamingCore.Sync^4.0.0'] then require(module_path..'/src/sync',{science_packs=science_packs}) end
end end
} }
@@ -48,7 +48,7 @@ ThisModule.Gui = Gui.left{
verbose('Added Science Global for: '..player.force.name) verbose('Added Science Global for: '..player.force.name)
global[player.force.name] = table.deepcopy(global._base) global[player.force.name] = table.deepcopy(global._base)
end end
force_data = global[player.force.name] local force_data = global[player.force.name]
frame.caption = {'ExpGamingInfo-Science.name'} frame.caption = {'ExpGamingInfo-Science.name'}
frame.add{ frame.add{
type='label', type='label',
@@ -101,5 +101,5 @@ ThisModule.Gui = Gui.left{
script.on_event(defines.events.on_research_finished,function(event) Gui.left.update('science') end) script.on_event(defines.events.on_research_finished,function(event) Gui.left.update('science') end)
-- Module Return -- Module Return
-- when called will toogle the gui for that player, if no player it will update the gui -- when called will toggle the gui for that player, if no player it will update the gui
return setmetatable(ThisModule,{_call=function(self,...) self.Gui(...) end}) return setmetatable(ThisModule,{_call=function(self,...) self.Gui(...) end})

View File

@@ -1,5 +1,6 @@
local Sync = require('ExpGamingCore.Sync') local Sync = require('ExpGamingCore.Sync')
local data = global['ExpGamingInfo.Science'] local data = global['ExpGamingInfo.Science']
local science_packs = science_packs
Sync.add_update('science',function() Sync.add_update('science',function()
local _return = {} local _return = {}

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingInfo.Tasklist -- @module ExpGamingInfo.Tasklist
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
@@ -102,26 +102,26 @@ local add = Gui.inputs{
end) end)
local function _tasks(player) local function _tasks(player)
local player = Game.get_player(player) player = Game.get_player(player)
local data = global._edit[player.index] local data = global._edit[player.index]
if not data then return global.tasks end if not data then return global.tasks end
local _edit = false local editing = false
for _,v in pairs(data._editing) do for _,v in pairs(data._editing) do
if v == true then if v == true then
_edit = true editing = true
break break
end end
end end
if data._edit and not _edit then if data._edit and not editing then
global.tasks = table.deepcopy(data._tasks) global.tasks = table.deepcopy(data._tasks)
global._edit[player.index] = table.deepcopy(global._base) global._edit[player.index] = table.deepcopy(global._base)
Gui.left.update('tasklist') Gui.left.update('tasklist')
return global.tasks return global.tasks
elseif not data._edit and _edit then elseif not data._edit and editing then
data._edit = true data._edit = true
for key,_ in pairs(data._tasks) do if not data._editing[key] then data._editing[key] = false end end for key,_ in pairs(data._tasks) do if not data._editing[key] then data._editing[key] = false end end
return data._tasks return data._tasks
elseif _edit then return data._tasks elseif editing then return data._tasks
else return global.tasks else return global.tasks
end end
end end

View File

@@ -10,7 +10,7 @@ local Color = require('FactorioStdLib.Color')
local module_verbose = false -- there is no verbose in this file so true will do nothing local module_verbose = false -- there is no verbose in this file so true will do nothing
local ExpLib = {} local ExpLib = {}
--- Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs --- Loads a table into _G even when sandboxes; will not overwrite values or append to tables; will not work during runtime to avoid desyncs
-- @usage unpack_to_G{key1='foo',key2='bar'} -- @usage unpack_to_G{key1='foo',key2='bar'}
-- @tparam table tbl table to be unpacked -- @tparam table tbl table to be unpacked
function ExpLib.unpack_to_G(tbl) function ExpLib.unpack_to_G(tbl)
@@ -25,7 +25,7 @@ end
-- @treturn table the env table with _G keys removed -- @treturn table the env table with _G keys removed
-- @warning does not work from console -- @warning does not work from console
function ExpLib.get_env(level) function ExpLib.get_env(level)
local level = level and level+1 or 2 level = level and level+1 or 2
local env = setmetatable({},{__index=_G}) local env = setmetatable({},{__index=_G})
while true do while true do
if not debug.getinfo(level) then break end if not debug.getinfo(level) then break end
@@ -46,7 +46,7 @@ end
-- @warning does not work from console -- @warning does not work from console
function ExpLib.get_upvalues(level) function ExpLib.get_upvalues(level)
local func = level and ExpLib.is_type(level,'function') and level or nil local func = level and ExpLib.is_type(level,'function') and level or nil
local level = level and ExpLib.is_type(level,'number') and level+1 or 2 level = level and ExpLib.is_type(level,'number') and level+1 or 2
func = func or debug.getinfo(level).func func = func or debug.getinfo(level).func
local upvalues = setmetatable({},{__index=_G}) local upvalues = setmetatable({},{__index=_G})
local i = 1 local i = 1
@@ -58,7 +58,7 @@ function ExpLib.get_upvalues(level)
return upvalues return upvalues
end end
--- Creats a table that will act like a string and a function --- Creates a table that will act like a string and a function
-- @usage add_metatable({},function) -- returns table -- @usage add_metatable({},function) -- returns table
-- @tparam table tbl the table that will have its metatable set -- @tparam table tbl the table that will have its metatable set
-- @tparam[opt=tostring] function callback the function that will be used for the call -- @tparam[opt=tostring] function callback the function that will be used for the call
@@ -66,8 +66,8 @@ end
-- @treturn table the new table with its metatable set -- @treturn table the new table with its metatable set
function ExpLib.add_metatable(tbl,callback,string) function ExpLib.add_metatable(tbl,callback,string)
if not ExpLib.is_type(tbl,'table') then error('No table given to add_metatable',2) end if not ExpLib.is_type(tbl,'table') then error('No table given to add_metatable',2) end
local callback = ExpLib.is_type(callback,'function') and callback or tostring callback = ExpLib.is_type(callback,'function') and callback or tostring
local string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring
return setmetatable(tbl,{ return setmetatable(tbl,{
__tostring=string, __tostring=string,
__concat=function(val1,val2) return type(val1) == 'string' and val1..string(val2) or string(val1)..val2 end, __concat=function(val1,val2) return type(val1) == 'string' and val1..string(val2) or string(val1)..val2 end,
@@ -75,17 +75,17 @@ function ExpLib.add_metatable(tbl,callback,string)
}) })
end end
--- Compear types faster for faster valadation of prams --- Compare types faster for faster validation of prams
-- @usage is_type('foo','string') -- return true -- @usage is_type('foo','string') -- return true
-- @usage is_type('foo') -- return false -- @usage is_type('foo') -- return false
-- @param v the value to be tested -- @param v the value to be tested
-- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil -- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil
-- @treturn bolean is v of type test_type -- @treturn boolean is v of type test_type
function ExpLib.is_type(v,test_type) function ExpLib.is_type(v,test_type)
return test_type and v and type(v) == test_type or not test_type and not v or false return test_type and v and type(v) == test_type or not test_type and not v or false
end end
--- Compear types faster for faster valadation of prams, including giving an error if incorrect --- Compare types faster for faster validation of prams, including giving an error if incorrect
-- @usage type_error('foo','string','Value is not a string') -- return true -- @usage type_error('foo','string','Value is not a string') -- return true
-- @usage type_error('foo','table','Value is not a string') -- return error -- @usage type_error('foo','table','Value is not a string') -- return error
-- @param value the value to be tested -- @param value the value to be tested
@@ -96,7 +96,7 @@ function ExpLib.type_error(value,type,error_message)
return ExpLib.is_type(value,type) or error(error_message,3) return ExpLib.is_type(value,type) or error(error_message,3)
end end
--- A speailsied verion of type_error to test for self --- A specialised version of type_error to test for self
-- @usage self_test(self,'Object','get_name') -- @usage self_test(self,'Object','get_name')
-- @tparam table self the table that is the object -- @tparam table self the table that is the object
-- @tparam string prototype_name the name of the class -- @tparam string prototype_name the name of the class
@@ -110,11 +110,11 @@ end
-- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console -- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
-- @usage player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player -- @usage player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
-- @param rtn any value of any type that will be returned to the player or console -- @param rtn any value of any type that will be returned to the player or console
-- @tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ingroned when printing to console -- @tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ignored when printing to console
-- @tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server -- @tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server
function ExpLib.player_return(rtn,colour,player) function ExpLib.player_return(rtn,colour,player)
local colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour]
local player = player or game.player player = player or game.player
local function _return(callback,rtn) local function _return(callback,rtn)
if ExpLib.is_type(rtn,'table') then if ExpLib.is_type(rtn,'table') then
-- test for: userdata, locale string, table with __tostring meta method, any other table -- test for: userdata, locale string, table with __tostring meta method, any other table
@@ -128,8 +128,8 @@ function ExpLib.player_return(rtn,colour,player)
else callback(tostring(rtn),colour) end else callback(tostring(rtn),colour) end
end end
if player then if player then
-- allows any vaild player identifier to be used -- allows any valid player identifier to be used
local player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid Player given to player_return',2) end if not player then error('Invalid Player given to player_return',2) end
-- plays a nice sound that is different to normal message sound -- plays a nice sound that is different to normal message sound
player.play_sound{path='utility/scenario_message'} player.play_sound{path='utility/scenario_message'}
@@ -175,8 +175,8 @@ function ExpLib.tick_to_display_format(tick)
end end
end end
--- Used as a way to view the structure of a gui, used for debuging --- Used as a way to view the structure of a gui, used for debugging
-- @usage Gui_tree(root) returns all children of gui recusivly -- @usage Gui_tree(root) returns all children of gui recursively
-- @tparam LuaGuiElement root the root to start the tree from -- @tparam LuaGuiElement root the root to start the tree from
-- @treturn table the table that describes the gui -- @treturn table the table that describes the gui
function ExpLib.gui_tree(root) function ExpLib.gui_tree(root)
@@ -249,13 +249,13 @@ function table.tostring(tbl)
return "{"..table.concat(result,",") .."}" return "{"..table.concat(result,",") .."}"
end end
--- Simmilar to table.tostring but converts a lua table to a json one --- Similar to table.tostring but converts a lua table to a json one
-- @usage talbe.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}' -- @usage table.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}'
-- @tparam table lua_table the table to convert -- @tparam table lua_table the table to convert
-- @treturn string the table in a json format -- @treturn string the table in a json format
function table.json(lua_table) function table.json(lua_table)
--if game and game.table_to_json then return game.table_to_json(lua_table) end --if game and game.table_to_json then return game.table_to_json(lua_table) end
local result, done, only_indexs = {}, {}, true local result, done, only_indexes = {}, {}, true
for key,value in ipairs(lua_table) do for key,value in ipairs(lua_table) do
done[key] = true done[key] = true
if type(value) == 'table' then table.insert(result,table.json(value,true)) if type(value) == 'table' then table.insert(result,table.json(value,true))
@@ -265,14 +265,14 @@ function table.json(lua_table)
end end
for key,value in pairs(lua_table) do for key,value in pairs(lua_table) do
if not done[key] then if not done[key] then
only_indexs = false only_indexes = false
if type(value) == 'table' then table.insert(result,table.val_to_str(key)..':'..table.json(value,true)) if type(value) == 'table' then table.insert(result,table.val_to_str(key)..':'..table.json(value,true))
elseif not value then table.insert(result,table.val_to_str(key)..':null') elseif not value then table.insert(result,table.val_to_str(key)..':null')
else table.insert(result,table.val_to_str(key)..':'..table.val_to_str(value)) else table.insert(result,table.val_to_str(key)..':'..table.val_to_str(value))
end end
end end
end end
if only_indexs then return "["..table.concat(result,",").."]" if only_indexes then return "["..table.concat(result,",").."]"
else return "{"..table.concat(result,",").."}" else return "{"..table.concat(result,",").."}"
end end
end end

View File

@@ -8,13 +8,13 @@ local Role -- ExpGamingCore.Role@^4.0.0
local Sync -- ExpGamingCore.Sync@^4.0.0 local Sync -- ExpGamingCore.Sync@^4.0.0
local function get_allowed_afk_time(player) local function get_allowed_afk_time(player)
local player = Game.get_player(player) player = Game.get_player(player)
local role = Role and Role.get_highest(player) or {index=1,allow_afk_kick=not player.admin} local role = Role and Role.get_highest(player) or {index=1,allow_afk_kick=not player.admin}
local player_count = #game.connected_players local player_count = #game.connected_players
local role_count = Role and Role.meta.count or 1 local role_count = Role and Role.meta.count or 1
local role_index = role.allow_afk_kick and role.index or false local role_index = role.allow_afk_kick and role.index or false
if not base then return false end if not role_index then return false end
return (role_count/role_index)*count return (role_count/role_index)*player_count
end end
script.on_event(defines.events.on_tick,function(event) script.on_event(defines.events.on_tick,function(event)

View File

@@ -17,7 +17,7 @@ script.on_init(function(event)
end end
end):on_event('error',function(self,err) end):on_event('error',function(self,err)
if Sync then if Sync then
Sync.emit_embeded{ Sync.emit_embedded{
title='Auto Kick Error', title='Auto Kick Error',
color=Color.to_hex(defines.textcolor.bg), color=Color.to_hex(defines.textcolor.bg),
description='Auto Kick Error - Closed Thread', description='Auto Kick Error - Closed Thread',

View File

@@ -1,15 +1,14 @@
--- Adds an inventory search that is proformed on a random player every 15 seconds --- Adds an inventory search that is preformed on a random player every 15 seconds
-- @module ExpGamingPlayer.inventorySearch@4.0.0 -- @module ExpGamingPlayer.inventorySearch@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Admin = require('ExpGamingAdmin') local Admin = require('ExpGamingAdmin')
local Game = require('FactorioStdLib.Game')
local Role -- ExpGamingCore.Role@^4.0.0 local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles -- Local Variables
-- removed from none admin ranks, no further action -- removed from none admin ranks, no further action
local low_items = { local low_items = {
'loader', 'loader',
@@ -36,7 +35,7 @@ local high_items = {
} }
-- inventories which are searched -- inventories which are searched
local inventorys = { local inventories = {
defines.inventory.player_main, defines.inventory.player_main,
defines.inventory.player_quickbar, defines.inventory.player_quickbar,
defines.inventory.player_trash defines.inventory.player_trash
@@ -63,7 +62,7 @@ end
function ThisModule.search_player(player) function ThisModule.search_player(player)
for category,items in pairs(_root_tree) do for category,items in pairs(_root_tree) do
if not Role or category ~= 'low_items' and not Role.allowed(player,'admin-items') then if not Role or category ~= 'low_items' and not Role.allowed(player,'admin-items') then
for _,_inventory in pairs(inventorys) do for _,_inventory in pairs(inventories) do
local inventory = player.get_inventory(_inventory) local inventory = player.get_inventory(_inventory)
if inventory then if inventory then
for _,item in pairs(items) do for _,item in pairs(items) do

View File

@@ -9,7 +9,7 @@ local Role -- ExpGamingCore.Role@^4.0.0
local Group -- ExpGamingCore.Group@^4.0.0 local Group -- ExpGamingCore.Group@^4.0.0
local function get_player_info(player,frame,add_cam) local function get_player_info(player,frame,add_cam)
local player = Game.get_player(player) player = Game.get_player(player)
if not player then return {} end if not player then return {} end
local _player = {} local _player = {}
_player.index = player.index _player.index = player.index
@@ -26,7 +26,7 @@ local function get_player_info(player,frame,add_cam)
_player.roles = roles _player.roles = roles
end end
if frame then if frame then
local frame = frame.add{type='frame',direction='vertical',style='image_frame'} frame = frame.add{type='frame',direction='vertical',style='image_frame'}
frame.style.width = 200 frame.style.width = 200
if Role then frame.style.height = 300 if Role then frame.style.height = 300
else frame.style.height = 260 end else frame.style.height = 260 end

View File

@@ -8,7 +8,7 @@ local Gui = require('ExpGamingCore.Gui')
local Admin -- ExpGamingAdmin@^4.0.0 local Admin -- ExpGamingAdmin@^4.0.0
local AdminGui -- ExpGamingAdmin.Gui@^4.0.0 local AdminGui -- ExpGamingAdmin.Gui@^4.0.0
-- Local Varibles -- Local Variables
local playerInfo = function(player,frame) local playerInfo = function(player,frame)
frame.add{ frame.add{
type='label', type='label',
@@ -40,12 +40,12 @@ local ThisModule = {
local global = global{ local global = global{
update=0, update=0,
delay=10, delay=10,
intervial=54000 interval=54000
} }
function ThisModule.update(tick) function ThisModule.update(tick)
local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick
if tick + global.delay > global.update - global.intervial then if tick + global.delay > global.update - global.interval then
global.update = tick + global.delay global.update = tick + global.delay
end end
end end
@@ -113,7 +113,7 @@ ThisModule.Gui = Gui.left{
script.on_event(defines.events.on_tick,function(event) script.on_event(defines.events.on_tick,function(event)
if event.tick > global.update then if event.tick > global.update then
ThisModule.Gui() ThisModule.Gui()
global.update = event.tick + global.intervial global.update = event.tick + global.interval
end end
end) end)

View File

@@ -8,7 +8,7 @@ local Server = require('ExpGamingCore.Server')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local Role -- ExpGamingCore.Server@^4.0.0 local Role -- ExpGamingCore.Server@^4.0.0
-- Local Varibles -- Local Variables
local poll_time_out = 90 -- In seconds local poll_time_out = 90 -- In seconds
-- Module Define -- Module Define
@@ -27,7 +27,7 @@ local global = global{
-- Function Define -- Function Define
local function _poll_data(question,answers) local function _poll_data(question,answers)
local poll = { local rtn_poll = {
uuid=Server.uuid(), uuid=Server.uuid(),
question=question, question=question,
answers=answers or {'None'}, answers=answers or {'None'},
@@ -35,7 +35,7 @@ local function _poll_data(question,answers)
voted={} voted={}
} }
Server.new_thread{ Server.new_thread{
data={poll_uuid=poll.uuid}, data={poll_uuid=rtn_poll.uuid},
timeout=poll_time_out*60 timeout=poll_time_out*60
}:on_event('timeout',function(self) }:on_event('timeout',function(self)
local uuid = tostring(self.data.poll_uuid) local uuid = tostring(self.data.poll_uuid)
@@ -58,9 +58,9 @@ local function _poll_data(question,answers)
game.print({'ExpGamingPlayer-polls.winner',highest[1]},defines.textcolor.info) game.print({'ExpGamingPlayer-polls.winner',highest[1]},defines.textcolor.info)
verbose('Ended Poll: '..poll.question..' ('..uuid..') Highest: '..highest[1]) verbose('Ended Poll: '..poll.question..' ('..uuid..') Highest: '..highest[1])
end):open() end):open()
global.active[tostring(poll.uuid)]=poll global.active[tostring(rtn_poll.uuid)]=rtn_poll
verbose('Created Poll: '..question..' ('..poll.uuid..')') verbose('Created Poll: '..question..' ('..rtn_poll.uuid..')')
return poll.uuid return rtn_poll.uuid
end end
local function draw_poll(frame) local function draw_poll(frame)
@@ -86,18 +86,18 @@ local function draw_poll(frame)
end end
end end
local function _opptions(player,root_frame) local function _options(player,root_frame)
local opptions = {'Please Select An Opption'} local options = {'Please Select An option'}
local uuid = root_frame.name local uuid = root_frame.name
local poll = global.active[uuid] local poll = global.active[uuid]
if not poll then return {'Invalid Poll'} end if not poll then return {'Invalid Poll'} end
for _,answer in pairs(poll.answers) do for _,answer in pairs(poll.answers) do
table.insert(opptions,answer) table.insert(options,answer)
end end
return opptions return options
end end
local opption_drop_down = Gui.inputs.add_drop_down('opption-drop-down-polls',_opptions,1,function(player,selected,items,element) local option_drop_down = Gui.inputs.add_drop_down('option-drop-down-polls',_options,1,function(player,selected,items,element)
local uuid = element.parent.name local uuid = element.parent.name
local poll = global.active[uuid] local poll = global.active[uuid]
if not poll then return end if not poll then return end
@@ -146,17 +146,17 @@ local poll_question_input = Gui.inputs.add_text('poll-question-input',true,'Ques
else options.question.caption = text end else options.question.caption = text end
end) end)
local _self_referace_poll_option_input = nil local _self_reference_poll_option_input = nil
local poll_option_input = Gui.inputs.add_text('poll-option-input',true,'Enter Option',function(player,text,element) local poll_option_input = Gui.inputs.add_text('poll-option-input',true,'Enter Option',function(player,text,element)
local options = element.parent.parent.parent.options local options = element.parent.parent.parent.options
if not options[element.parent.name] then options.add{type='label',name=element.parent.name,caption=text} if not options[element.parent.name] then options.add{type='label',name=element.parent.name,caption=text}
else options[element.parent.name].caption = text end else options[element.parent.name].caption = text end
if options.last.caption == element.parent.name then if options.last.caption == element.parent.name then
options.last.caption = tonumber(options.last.caption)+1 options.last.caption = tonumber(options.last.caption)+1
_self_referace_poll_option_input(element.parent.parent.add{type='flow',name=options.last.caption}).style.minimal_width = 200 _self_reference_poll_option_input(element.parent.parent.add{type='flow',name=options.last.caption}).style.minimal_width = 200
end end
end) end)
_self_referace_poll_option_input = poll_option_input _self_reference_poll_option_input = poll_option_input
local function poll_assembler(frame) local function poll_assembler(frame)
frame.clear() frame.clear()
@@ -220,7 +220,7 @@ ThisModule.Gui = Gui.popup{
flow.add{type='label',caption={'ExpGamingPlayer-polls.time-left',poll_time_out}} flow.add{type='label',caption={'ExpGamingPlayer-polls.time-left',poll_time_out}}
flow.add{type='label',caption='Question: '..poll.question} flow.add{type='label',caption='Question: '..poll.question}
flow.add{type='label',name='answer',caption='Your Answer: None'} flow.add{type='label',name='answer',caption='Your Answer: None'}
opption_drop_down(flow) option_drop_down(flow)
end end
}:add_left{ }:add_left{
caption='utility/item_editor_icon', caption='utility/item_editor_icon',
@@ -245,11 +245,11 @@ ThisModule.Gui = Gui.popup{
caption='Viewing Poll: 1', caption='Viewing Poll: 1',
style='caption_label' style='caption_label'
} }
local btn = next:draw(title) btn = next:draw(title)
btn.style.width = 20 btn.style.width = 20
btn.style.height = 20 btn.style.height = 20
if Role and Role.allowed(frame.player_index,'create-poll') or game.players[frame.player_index].admin then if Role and Role.allowed(frame.player_index,'create-poll') or game.players[frame.player_index].admin then
local btn = create_poll:draw(title) btn = create_poll:draw(title)
btn.style.width = 20 btn.style.width = 20
btn.style.height = 20 btn.style.height = 20
end end
@@ -269,5 +269,5 @@ ThisModule.Gui = Gui.popup{
-- Event Handlers Define -- Event Handlers Define
-- Module Return -- Module Return
-- when called it will toogle the left gui for this player -- when called it will toggle the left gui for this player
return setmetatable(ThisModule,{__call=function(self,...) self.Gui(...) end}) return setmetatable(ThisModule,{__call=function(self,...) self.Gui(...) end})

View File

@@ -7,7 +7,7 @@
local Server = require('ExpGamingCore.Server') local Server = require('ExpGamingCore.Server')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
-- Local Varibles -- Local Variables
--{type='slider',object='',key='',name='',min=x,max=y} --{type='slider',object='',key='',name='',min=x,max=y}
--{type='function',object='',key='',name='',param={}} --{type='function',object='',key='',name='',param={}}
local basic_settings = { local basic_settings = {
@@ -122,8 +122,7 @@ local are_you_sure = Gui.inputs.add_checkbox('game-settings-are-you-sure',true,n
end) end)
local function _draw_setting(frame,setting) local function _draw_setting(frame,setting)
local frame = frame.add{type='flow'} frame = frame.add{type='flow'}.add{
local frame = frame.add{
type='flow', type='flow',
name=setting._group name=setting._group
} }

View File

@@ -1,10 +1,10 @@
--- Creates a gui for making and reciving announcements --- Creates a gui for making and receiving announcements
-- @module GuiAnnouncements@4.0.0 -- @module GuiAnnouncements@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- maybe make this not require Role and have it optinal -- maybe make this not require Role and have it optional
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
@@ -27,15 +27,15 @@ local function _roles(player)
return roles return roles
end end
local role_drop_down = Gui.inputs.add_drop_down('rank-drop-down-annoncements',_roles,1,function(player,selected,items,element) local role_drop_down = Gui.inputs.add_drop_down('rank-drop-down-announcements',_roles,1,function(player,selected,items,element)
element.parent.role.caption = selected element.parent.role.caption = selected
if selected == 'Select Role' then element.parent['send-annoncement'].style.visible = false if selected == 'Select Role' then element.parent['send-announcement'].style.visible = false
else element.parent['send-annoncement'].style.visible = true end else element.parent['send-announcement'].style.visible = true end
end) end)
local send_popup = Gui.inputs{ local send_popup = Gui.inputs{
type='button', type='button',
name='send-annoncement', name='send-announcement',
caption='utility/export_slot' caption='utility/export_slot'
}:on_event('click',function(event) }:on_event('click',function(event)
local player = Game.get_player(event) local player = Game.get_player(event)
@@ -74,7 +74,7 @@ ThisModule.Gui = Gui.popup{
tooltip={'GuiAnnouncements.tooltip'}, tooltip={'GuiAnnouncements.tooltip'},
draw=function(self,frame) draw=function(self,frame)
frame.caption = {'GuiAnnouncements.name'} frame.caption = {'GuiAnnouncements.name'}
local frame = frame.add{ frame = frame.add{
type='flow', type='flow',
direction='vertical' direction='vertical'
} }

View File

@@ -2,7 +2,7 @@
-- @module PlayerAutoColor@4.0.0 -- @module PlayerAutoColor@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Color = require('FactorioStdLib.Color') local Color = require('FactorioStdLib.Color')
@@ -28,7 +28,7 @@ local global = global{
} }
-- Event Handlers Define -- Event Handlers Define
Event.register(defines.events.on_player_created, function(event) script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
local colours = table.keys(defines.color) local colours = table.keys(defines.color)
player.color = defines.color.black player.color = defines.color.black
@@ -44,4 +44,4 @@ Event.register(defines.events.on_player_created, function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,12 +2,12 @@
-- @module SpawnArea@4.0.0 -- @module SpawnArea@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
-- Local Varibles -- Local Variables
local turret_enabled = true local turret_enabled = true
local turret_ammo = 'uranium-rounds-magazine' local turret_ammo = 'uranium-rounds-magazine'
@@ -17,8 +17,8 @@ local entity_positions = require(module_path..'/src/spawn_entities')
local global_offset = {x=0,y=-2} local global_offset = {x=0,y=-2}
local decon_radius = 20 local decon_radius = 20
local decon_tile = 'concrete' local decon_tile = 'concrete'
local partern_radius = 50 local pattern_radius = 50
local partern_tile = 'stone-path' local pattern_tile = 'stone-path'
-- Module Define -- Module Define
local module_verbose = false local module_verbose = false
@@ -45,10 +45,10 @@ end
function ThisModule.auto_turret(surface,pos) function ThisModule.auto_turret(surface,pos)
if not turret_enabled then error('Auto Turrets are disabled.') end if not turret_enabled then error('Auto Turrets are disabled.') end
-- adds a new turrent to the global list, returns index -- adds a new turret to the global list, returns index
local _return local _return
if surface then if surface then
local surface = Game.get_surface(surface) surface = Game.get_surface(surface)
if not surface then error('Surface is not valid.') end if not surface then error('Surface is not valid.') end
local posx = pos.x or pos[1] or error('Position is not valid.') local posx = pos.x or pos[1] or error('Position is not valid.')
local posy = pos.y or pos[2] or error('Position is not valid.') local posy = pos.y or pos[2] or error('Position is not valid.')
@@ -57,7 +57,7 @@ function ThisModule.auto_turret(surface,pos)
-- spawns turrets and refills them -- spawns turrets and refills them
if not game.forces['spawn'] then game.create_force('spawn').set_cease_fire('player',true) game.forces['player'].set_cease_fire('spawn',true) end if not game.forces['spawn'] then game.create_force('spawn').set_cease_fire('player',true) game.forces['player'].set_cease_fire('spawn',true) end
for _,pos in pairs(global) do for _,pos in pairs(global) do
local surface = game.surfaces[pos[1]] surface = game.surfaces[pos[1]]
local turret = surface.find_entity('gun-turret',{pos[2],pos[3]}) local turret = surface.find_entity('gun-turret',{pos[2],pos[3]})
if not turret then if not turret then
turret = surface.create_entity{name='gun-turret',position={pos[2],pos[3]},force='spawn'} turret = surface.create_entity{name='gun-turret',position={pos[2],pos[3]},force='spawn'}
@@ -83,34 +83,34 @@ script.on_event(defines.events.on_player_created, function(event)
local player = Game.get_player(event) local player = Game.get_player(event)
local surface = player.surface local surface = player.surface
local offset = {x=0,y=0} local offset = {x=0,y=0}
local partern_base_tile = surface.get_tile(player.position).name local pattern_base_tile = surface.get_tile(player.position).name
if partern_base_tile == 'deepwater' or partern_base_tile == 'water' then partern_base_tile = 'grass-1' end if pattern_base_tile == 'deepwater' or pattern_base_tile == 'water' then pattern_base_tile = 'grass-1' end
local base_tiles = {} local base_tiles = {}
local tiles = {} local tiles = {}
-- generates a safe area of land and removes all entites -- generates a safe area of land and removes all entities
for x = -partern_radius, partern_radius do for x = -pattern_radius, pattern_radius do
for y = -partern_radius, partern_radius do for y = -pattern_radius, pattern_radius do
if x^2+y^2 < decon_radius^2 then if x^2+y^2 < decon_radius^2 then
table.insert(base_tiles,{name=decon_tile,position={x+offset.x,y+offset.y}}) table.insert(base_tiles,{name=decon_tile,position={x+offset.x,y+offset.y}})
local entities = surface.find_entities_filtered{area={{x+offset.x-1,y+offset.y-1},{x+offset.x,y+offset.y}}} local entities = surface.find_entities_filtered{area={{x+offset.x-1,y+offset.y-1},{x+offset.x,y+offset.y}}}
for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end
elseif x^2+y^2 < partern_radius^2 then elseif x^2+y^2 < pattern_radius^2 then
table.insert(base_tiles,{name=partern_base_tile,position={x+offset.x,y+offset.y}}) table.insert(base_tiles,{name=pattern_base_tile,position={x+offset.x,y+offset.y}})
end end
end end
end end
surface.set_tiles(base_tiles) surface.set_tiles(base_tiles)
-- creates the partern in the spawn -- creates the pattern in the spawn
for _,position in pairs(tile_positions) do for _,position in pairs(tile_positions) do
table.insert(tiles,{name=partern_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}}) table.insert(tiles,{name=pattern_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}})
end end
surface.set_tiles(tiles) surface.set_tiles(tiles)
-- spawns all the entites in spawn -- spawns all the entities in spawn
for _,entity in pairs(entity_positions) do for _,entity in pairs(entity_positions) do
local entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'} entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'}
entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false
end end
-- generates spawn turrents and afk belts -- generates spawn turrets and afk belts
if turret_enabled then ThisModule.auto_turret() end if turret_enabled then ThisModule.auto_turret() end
ThisModule.afk_belt(surface,{offset.x-5,offset.y-5}) ThisModule.afk_belt(surface,{offset.x-5,offset.y-5})
ThisModule.afk_belt(surface,{offset.x+5,offset.y-5}) ThisModule.afk_belt(surface,{offset.x+5,offset.y-5})
@@ -123,4 +123,4 @@ script.on_event(defines.events.on_player_created, function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -2,14 +2,14 @@
-- @module WarpPoints@4.0.0 -- @module WarpPoints@4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
local Role -- ExpGamingCore.Role@^4.0.0 local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles -- Local Variables
local warp_tiles = require(module_path..'/src/warp_tiles') local warp_tiles = require(module_path..'/src/warp_tiles')
local warp_entities = require(module_path..'/src/warp_entities') local warp_entities = require(module_path..'/src/warp_entities')
@@ -49,7 +49,6 @@ function ThisModule.remove_warp_point(name)
local surface = game.surfaces[warp.surface] local surface = game.surfaces[warp.surface]
local offset = warp.position local offset = warp.position
local tiles = {} local tiles = {}
local tiles = {}
-- clears the area where the warp was -- clears the area where the warp was
for x = -warp_radius, warp_radius do for x = -warp_radius, warp_radius do
for y = -warp_radius, warp_radius do for y = -warp_radius, warp_radius do
@@ -72,9 +71,9 @@ end
-- @tparam surface surface the surface that the warp point is on -- @tparam surface surface the surface that the warp point is on
-- @tparam force force the force that the warp point will belong to -- @tparam force force the force that the warp point will belong to
-- @tparam string name the name of the warp point to be made -- @tparam string name the name of the warp point to be made
function ThisModule.make_warp_point(position,surface,force,name) function ThisModule.make_warp_point(position,surface,force,warpName)
local warp = global.warps[name] local warp = global.warps[warpName]
if warp then return end; warp = nil if warp then return end
local offset = {x=math.floor(position.x),y=math.floor(position.y)} local offset = {x=math.floor(position.x),y=math.floor(position.y)}
local old_tile = surface.get_tile(offset).name local old_tile = surface.get_tile(offset).name
local base_tiles = {} local base_tiles = {}
@@ -88,22 +87,22 @@ function ThisModule.make_warp_point(position,surface,force,name)
end end
end end
surface.set_tiles(base_tiles) surface.set_tiles(base_tiles)
-- this adds the patern and entities -- this adds the pattern and entities
for _,position in pairs(warp_tiles) do for _,pos in pairs(warp_tiles) do
table.insert(tiles,{name=warp_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}}) table.insert(tiles,{name=warp_tile,position={pos[1]+offset.x+global_offset.x,pos[2]+offset.y+global_offset.y}})
end end
surface.set_tiles(tiles) surface.set_tiles(tiles)
for _,entity in pairs(warp_entities) do for _,entity in pairs(warp_entities) do
local entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'} entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'}
entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false
end end
-- creates a tag on the map for the wap point -- creates a tag on the map for the wap point
local tag = force.add_chart_tag(surface,{ local tag = force.add_chart_tag(surface,{
position={offset.x+0.5,offset.y+0.5}, position={offset.x+0.5,offset.y+0.5},
text='Warp: '..name, text='Warp: '..warpName,
icon={type='item',name=warp_item} icon={type='item',name=warp_item}
}) })
global.warps[name] = {tag=tag,surface=surface.index,position=tag.position,old_tile=old_tile} global.warps[warpName] = {tag=tag,surface=surface.index,position=tag.position,old_tile=old_tile}
local _temp = {Spawn=global.warps.Spawn} local _temp = {Spawn=global.warps.Spawn}
global.warps.Spawn = nil global.warps.Spawn = nil
for name,data in pairs(table.keysort(global.warps)) do _temp[name] = data end for name,data in pairs(table.keysort(global.warps)) do _temp[name] = data end
@@ -190,7 +189,7 @@ ThisModule.Gui = Gui.left{
if cooldown > 0 then frame.style.visible = false return if cooldown > 0 then frame.style.visible = false return
elseif not Role and player.admin or Role and Role.allowed(player,'always-warp') then return elseif not Role and player.admin or Role and Role.allowed(player,'always-warp') then return
elseif player.surface.get_tile(player.position).name == warp_tile elseif player.surface.get_tile(player.position).name == warp_tile
and player.surface.name == 'nauvis' and player.surface.name == 'nauvis'
then return then return
elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then return elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then return
else frame.style.visible = false end else frame.style.visible = false end
@@ -199,7 +198,7 @@ ThisModule.Gui = Gui.left{
local cooldown = global.cooldowns[player.index] or 0 local cooldown = global.cooldowns[player.index] or 0
if not Role and player.admin or Role and Role.allowed(player,'always-warp') then return true if not Role and player.admin or Role and Role.allowed(player,'always-warp') then return true
elseif player.surface.get_tile(player.position).name == warp_tile elseif player.surface.get_tile(player.position).name == warp_tile
and player.surface.name == 'nauvis' and player.surface.name == 'nauvis'
then return true then return true
elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then return true elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then return true
elseif cooldown > 0 then return {'WarpPoints.cooldown',cooldown} elseif cooldown > 0 then return {'WarpPoints.cooldown',cooldown}
@@ -213,7 +212,7 @@ script.on_event(defines.events.on_tick,function(event)
if not (event.tick % 60 == 0) then return end if not (event.tick % 60 == 0) then return end
for index,time in pairs(global.cooldowns) do for index,time in pairs(global.cooldowns) do
if time > 0 then if time > 0 then
global.cooldowns[index] = time-1 global.cooldowns[index] = time-1
if global.cooldowns[index] == 0 then player_return({'WarpPoints.cooldown-zero'},defines.textcolor.low,index) end if global.cooldowns[index] == 0 then player_return({'WarpPoints.cooldown-zero'},defines.textcolor.low,index) end
end end
end end
@@ -224,9 +223,9 @@ script.on_event(defines.events.on_player_changed_position, function(event)
local cooldown = global.cooldowns[player.index] or 0 local cooldown = global.cooldowns[player.index] or 0
local tile = player.surface.get_tile(player.position).name local tile = player.surface.get_tile(player.position).name
if not Role and player.admin or Role and not Role.allowed(player,'always-warp') and cooldown == 0 then if not Role and player.admin or Role and not Role.allowed(player,'always-warp') and cooldown == 0 then
if tile == warp_tile and player.surface.name == 'nauvis' then if tile == warp_tile and player.surface.name == 'nauvis' then
ThisModule.Gui:open(player) ThisModule.Gui:open(player)
elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then elseif player.position.x^2+player.position.y^2 < (warp_radius*spawn_warp_scale)^2 then
ThisModule.Gui:open(player) ThisModule.Gui:open(player)
else ThisModule.Gui:close(player) end else ThisModule.Gui:close(player) end
end end
@@ -246,4 +245,4 @@ script.on_event(defines.events.on_player_created, function(event)
end) end)
-- Module Return -- Module Return
return ThisModule return ThisModule

View File

@@ -1,19 +1,19 @@
--- Makes paths which wear down and paths where entites are placed. --- Makes paths which wear down and paths where entities are placed.
-- @module WornPaths@^4.0.0 -- @module WornPaths@^4.0.0
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule -- @alias ThisModule
-- Module Require -- Module Require
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game')
-- Local Varibles -- Local Variables
local entites = require(module_path..'/src/entites') local entities = require(module_path..'/src/entites')
local paths = require(module_path..'/src/paths') local paths = require(module_path..'/src/paths')
for tile,value in pairs(paths) do value[1]=-1/value[1] end for _,value in pairs(paths) do value[1]=-1/value[1] end
local placed_paths = require(module_path..'/src/placed') local placed_paths = require(module_path..'/src/placed')
local adjacency_boost = 2 -- makes paths more lickly to be next to each other; must be greater than 0 local adjacency_boost = 2 -- makes paths more likely to be next to each other; must be greater than 0
adjacency_boost = 10/adjacency_boost -- dont change this line adjacency_boost = 10/adjacency_boost -- dont change this line
-- Module Define -- Module Define
@@ -28,7 +28,7 @@ local function global_key(surface,pos)
return 'S'..surface.name..'X'..math.floor(pos.x)..'Y'..math.floor(pos.y) return 'S'..surface.name..'X'..math.floor(pos.x)..'Y'..math.floor(pos.y)
end end
--- Downgrads a tile in this position --- Downgrades a tile in this position
-- @usage ThisModule.down_grade(surface,{x=10,y=10}) -- @usage ThisModule.down_grade(surface,{x=10,y=10})
-- @tparam surface surface the surface the tile is on -- @tparam surface surface the surface the tile is on
-- @tparam table pos the position of the tile to change -- @tparam table pos the position of the tile to change
@@ -36,7 +36,7 @@ function ThisModule.down_grade(surface,pos)
local tile = surface.get_tile(pos).name local tile = surface.get_tile(pos).name
local new_tile = paths[tile][2] local new_tile = paths[tile][2]
if new_tile == 'world-gen' then if new_tile == 'world-gen' then
new_tile = global[global_key(surface,pos)] or 'grass-1' new_tile = global[global_key(surface,pos)] or 'grass-1'
end end
surface.set_tiles{{name=new_tile,position=pos}} surface.set_tiles{{name=new_tile,position=pos}}
end end
@@ -46,15 +46,15 @@ script.on_event({defines.events.on_player_built_tile,defines.events.on_robot_bui
local surface = event.surface_index and game.surfaces[event.surface_index] or event.robot and event.robot.surface local surface = event.surface_index and game.surfaces[event.surface_index] or event.robot and event.robot.surface
local old_tiles = event.tiles local old_tiles = event.tiles
for _,old_tile in pairs(old_tiles) do for _,old_tile in pairs(old_tiles) do
if placed_paths[old_tile.old_tile.name] or old_tile.old_tile.name == 'water' or old_tile.old_tile.name == 'deepwater' then else if not placed_paths[old_tile.old_tile.name] and old_tile.old_tile.name ~= 'water' and old_tile.old_tile.name ~= 'deepwater' then
global[global_key(surface,old_tile.position)]=old_tile.old_tile.name -- not a mistake, this makes it have dimising returns global[global_key(surface,old_tile.position)]=old_tile.old_tile.name -- not a mistake, this makes it have demising returns
end end
end end
end) end)
script.on_event(defines.events.on_player_changed_position, function(event) script.on_event(defines.events.on_player_changed_position, function(event)
local player = Game.get_player(event) local player = Game.get_player(event)
if player and player.valid and game.tick > 10 then else return end if not player or not player.valid or game.tick < 10 then return end
if player.afk_time > 300 then return end if player.afk_time > 300 then return end
local surface = player.surface local surface = player.surface
local pos = player.position local pos = player.position
@@ -76,7 +76,7 @@ end)
script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function(event) script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function(event)
local entity = event.created_entity local entity = event.created_entity
local surface = entity.surface local surface = entity.surface
if entites[entity.name] then if entities[entity.name] then
local box = entity.prototype.collision_box local box = entity.prototype.collision_box
for x = box.left_top.x,box.right_bottom.x do for y = box.left_top.y,box.right_bottom.y do for x = box.left_top.x,box.right_bottom.x do for y = box.left_top.y,box.right_bottom.y do
local pos = {x=entity.position.x+x,y=entity.position.y+y} local pos = {x=entity.position.x+x,y=entity.position.y+y}
@@ -87,17 +87,17 @@ script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function
end) end)
-- Module Return -- Module Return
-- when called it will downgrade a tile -- when called it will downgrade a tile
return setmetatable(ThisModule,{__call=function(self,...) self.down_grade(...) end}) return setmetatable(ThisModule,{__call=function(self,...) self.down_grade(...) end})
--[[ --[[
/interface /interface
local tile_name = surface.get_tile(position).name local tile_name = surface.get_tile(position).name
if not paths[tile_name] then return end if not paths[tile_name] then return end
local count = -9 -- this value is important local count = -9 -- this value is important
for x = -1,1 do for y = -1,1 do for x = -1,1 do for y = -1,1 do
local _pos = {position.x+x,position.y+y} local _pos = {position.x+x,position.y+y}
if placed_paths[tile_name] and not placed_paths[surface.get_tile(_pos).name] if placed_paths[tile_name] and not placed_paths[surface.get_tile(_pos).name]
or surface.get_tile(_pos).name == paths[tile_name][2] or surface.get_tile(_pos).name == paths[tile_name][2]
then count=count+1 end then count=count+1 end
end end end end
return paths[tile_name][1]/(count-adjacency_boost) return paths[tile_name][1]/(count-adjacency_boost)