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

View File

@@ -2,9 +2,9 @@
-- @module AdvancedStartingItems@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Local Varibles
-- Local Variables
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,
['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,
['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,
['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,
['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,
['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,
@@ -28,7 +28,7 @@ local module_verbose = false
local ThisModule = {}
-- 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]
if event.player_index == 1 then
player.force.friendly_fire = false
@@ -42,4 +42,4 @@ Event.register(defines.events.on_player_created, function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ChatPopup@4.0.0
-- @author badgamernl
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ChatPopup
-- @alias ChatPopup
-- Module Require
local Game = require('FactorioStdLib.Game')
@@ -19,7 +19,7 @@ function ChatPopup.sendFlyingText(player, text)
for i=1, #text, chunkSize do
chunks[#chunks+1] = text:sub(i,i+chunkSize - 1)
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)
for i,value in ipairs(chunks) do
_player.surface.create_entity{
@@ -31,11 +31,11 @@ function ChatPopup.sendFlyingText(player, text)
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]
if not player then return end
if not event.message then return end
-- Send message player send to player itself
local message = player.name .. ': ' .. event.message
ChatPopup.sendFlyingText(player, message)
@@ -50,7 +50,7 @@ Event.register(defines.events.on_console_chat, function(event)
end
end
end
end)
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
-- @author badgamernl
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais DamagePopup
-- @alias DamagePopup
-- Module Require
local Color = require('FactorioStdLib.Color')
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 cause = event.cause
local damage = event.original_damage_amount
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
@@ -36,7 +36,7 @@ Event.register(defines.events.on_entity_damaged, function(event)
entity.surface.create_entity{
name="flying-text",
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
}
end

View File

@@ -2,7 +2,7 @@
-- @module DeathMarkers@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Define
local module_verbose = false
@@ -14,7 +14,7 @@ local global = global{
}
-- 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 tag = player.force.add_chart_tag(player.surface,{
position=player.position,
@@ -24,7 +24,7 @@ Event.register(defines.events.on_player_died, function(event)
table.insert(global.corpses,tag)
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 not global.corpses then global.corpses = {} end
local key = 1
@@ -42,4 +42,4 @@ Event.register(defines.events.on_tick, function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

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

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Ban@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Admin = require('ExpGamingAdmin')
@@ -27,11 +27,11 @@ AdminGui.add_button('Ban','utility/danger_icon',{'ExpGamingAdmin.tooltip-ban'},f
end)
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 reason = Admin.create_reason(reason,by_player_name)
reason = Admin.create_reason(reason,by_player_name)
Admin.set_banned(player,true)
if Sync then Sync.emit_embeded{
if Sync then Sync.emit_embedded{
title='Player Ban',
color=Color.to_hex(defines.textcolor.crit),
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
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Admin = require('ExpGamingAdmin')
@@ -13,7 +13,7 @@ local module_verbose = false
local ThisModule = {}
-- Function Define
local inventorys = {
local inventories = {
defines.inventory.player_main,
defines.inventory.player_quickbar,
defines.inventory.player_trash,
@@ -23,7 +23,7 @@ local inventorys = {
}
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
while not chest or not chest.get_inventory(defines.inventory.chest).can_insert(item) do
chest = table.remove(chests,1)
@@ -38,14 +38,14 @@ function Admin.move_item_to_spawn(item,surface,chests)
end
function Admin.move_inventory(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if not player then return end
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)
if inventory then
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)
end
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 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.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)
end)

View File

@@ -24,5 +24,5 @@ commands.add_command('clear-warnings', 'Clears a player\'s warnings', {
}, function(event,args)
local player = args.player
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)

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.Gui@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais AdminGui
-- @alias AdminGui
-- Module Require
local Admin = require('ExpGamingAdmin')
@@ -10,7 +10,6 @@ local Gui = require('ExpGamingCore.Gui')
local Role = require('ExpGamingCore.Role')
local Game = require('FactorioStdLib.Game')
local playerInfo -- ExpGamingPlayer.playerInfo@^4.0.0
local mod_gui = require('mod-gui')
-- Module Define
local module_verbose = false
@@ -42,7 +41,7 @@ function AdminGui.add_button(name,caption,tooltip,callback)
tooltip=tooltip
}:on_event('click',function(event)
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)
end)
end
@@ -68,12 +67,12 @@ function AdminGui.draw(frame,filter_buttons)
end
-- Gui Define
local function _players(_player,root_frame,state)
local function get_players(_player,root_frame,state)
local players = {'Select Player'}
local _players = state and game.players or game.connected_players
for _,player in pairs(_players) do
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)
end
end
@@ -82,14 +81,14 @@ local function _players(_player,root_frame,state)
end
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
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
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
local player_info_flow = element.parent.parent.info_flow
player_info_flow.clear()
@@ -142,7 +141,7 @@ Admin.center = Gui.center{
tooltip={'ExpGamingAdmin.tooltip'},
draw=function(self,frame,pre_select_player,pre_select_action)
frame.caption={'ExpGamingAdmin.name'}
local frame = frame.add{
frame = frame.add{
type='flow',
direction='horizontal'
}
@@ -166,7 +165,7 @@ Admin.center = Gui.center{
online_check:draw(dropdowns)
local _drop = player_drop_down:draw(dropdowns)
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)
local _text = reason_input:draw(dropdowns)
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
if pre_select_player then playerInfo(pre_select_player,player_info_flow,true) end
_text.style.width = 200
local label = dropdowns.add{
label = dropdowns.add{
name='warning',
type='label',
caption='',
@@ -183,17 +182,17 @@ Admin.center = Gui.center{
label.style.single_line = false
label.style.width = 200
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{
name='player',
type='label',
caption=_caption
caption=caption
}.style.visible = false
local _caption = pre_select_action or ''
caption = pre_select_action or ''
frame.add{
name='action',
type='label',
caption=_caption
caption=caption
}.style.visible = false
end
}

View File

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

View File

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

View File

@@ -2,11 +2,10 @@
-- @module ExpGamingAdmin.Reports@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Admin = require('ExpGamingAdmin')
local Server = require('ExpGamingCore.Server')
local Role = require('ExpGamingCore.Role')
local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game')
@@ -25,22 +24,22 @@ local ThisModule = {
-- Global Define
local global = global{
reports={},
varified={}
verified={}
}
-- Local Varibles
-- Local Variables
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
-- Function Define
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 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.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',
color=Color.to_hex(defines.textcolor.med),
description='A player was reported.',
@@ -51,7 +50,7 @@ local function report_message(player,by_player,reason)
end
local function cheak_reports(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if not player then return end
local reports = Admin.count_reports(player)
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
function Admin.count_reports(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if not player then return 0 end
local _count = 0
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
end
end
if global.varified[player.name] then
for _,report in pairs(global.varified[player.name]) do
_count=_count+varified_to_warings
if global.verified[player.name] then
for _ in pairs(global.verified[player.name]) do
_count=_count+verified_to_warnings
end
end
return _count
end
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 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
global.varified[player.name] = global.varified[player.name] or {}
local reports = global.varified[player.name]
if Role.has_flag(by_player,'is_verified') then
global.verified[player.name] = global.verified[player.name] or {}
local reports = global.verified[player.name]
for _,value in pairs(reports) do
if value[1] == by_player.name then return end
end
@@ -100,12 +99,12 @@ function Admin.report(player,by_player,reason)
end
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
global.reports[player.name]={}
global.varified[player.name]={}
global.verified[player.name]={}
if not no_emit and Sync then
Sync.emit_embeded{
Sync.emit_embedded{
title='Player Clear',
color=Color.to_hex(defines.textcolor.low),
description='A player had their reports cleared.',
@@ -160,4 +159,4 @@ Admin.report_btn = Gui.inputs{
end)
-- Module Return
return ThisModule
return ThisModule

View File

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

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin.KicTempBan@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
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>'
if not player or Admin.is_banned(player) then return end
Admin.set_banned(player,'temp')
if Sync then Sync.emit_embeded{
if Sync then Sync.emit_embedded{
title='Player Temp-Ban',
color=Color.to_hex(defines.textcolor.high),
description='A player was jailed.',

View File

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

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingAdmin@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais Admin
-- @alias Admin
-- Module Require
local Game = require('FactorioStdLib.Game')
@@ -34,13 +34,13 @@ local global = global{
-- Function Define
function Admin.valid_players(player,by_player)
local player = Game.get_player(player)
local by_player = Game.get_player(by_player) or SERVER
player = Game.get_player(player)
by_player = Game.get_player(by_player) or SERVER
return player, by_player
end
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 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
@@ -48,20 +48,20 @@ function Admin.create_reason(reason,name)
end
function Admin.allowed(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if Role then
return Role.allowed(player,'admin-commands')
else return player.admin end
end
function Admin.set_banned(player,set)
local player=Game.get_player(player)
player = Game.get_player(player)
if not player then return false end
global.banned[player.name] = set
end
function Admin.is_banned(player,detail)
local player=Game.get_player(player)
player = Game.get_player(player)
if not player then return false end
local banned = global.banned[player.name]
if banned == true then return true end
@@ -82,13 +82,13 @@ function Admin.take_action(action,player,by_player,reason)
end
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 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 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',
color=Color.to_hex(defines.textcolor.low),
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
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Game = require('FactorioStdLib.Game')
local Server = require('ExpGamingCore.Server')
local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles
-- Local Variables
-- lots of these are jokes, but some have uses
-- white spaces removed and made into lower
@@ -34,12 +34,12 @@ local messages = {
}
-- white spaces removed and made into lower
-- 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 commands = {
['online']=function(player) return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end,
['playtime']=function(player) return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end,
['players']=function(player) return {'ExpGamingBot-autoChat.players',#game.players} end,
['online']=function() return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end,
['playtime']=function() return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end,
['players']=function() return {'ExpGamingBot-autoChat.players',#game.players} end,
['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,
['readme']={'ExpGamingBot-autoChat.read-readme'},
@@ -49,15 +49,17 @@ local commands = {
['lenny']={'ExpGamingBot-autoChat.lenny'},
['feedback']={'ExpGamingBot-autoChat.feedback'},
['wiki']={'ExpGamingBot-autoChat.wiki'},
['hodor']=function(player) 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,
['hodor']=function() local options = {'?','.','!','!!!'} return {'ExpGamingBot-autoChat.hodor',options[math.random(#options)]} end,
['evolution']=function() return {'ExpGamingBot-autoChat.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end,
--Jokes about food and drink
['whattoeat']={'ExpGamingBot-autoChat.food'},
['makepopcorn']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self)
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,
['orderpizza']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self)
@@ -66,6 +68,7 @@ local commands = {
end
self.data[2]=self.data[2]+1
end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end,
['passsomesnaps']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self)
@@ -74,6 +77,7 @@ local commands = {
end
self.data[2]=self.data[2]+1
end):open() return {'ExpGamingBot-autoChat.get-snaps-1'} end,
['makecocktail']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self)
@@ -82,11 +86,13 @@ local commands = {
end
self.data[2]=self.data[2]+1
end):open() return {'ExpGamingBot-autoChat.get-cocktail-1'} end,
['makecoffee']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self)
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,
['orderpizza']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true
}:on_event('timeout',function(self)
@@ -95,21 +101,25 @@ local commands = {
end
self.data[2]=self.data[2] + 1
end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end,
['maketea']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self)
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,
['popcorn']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self)
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,
['meadplease']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self)
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,
['passabeer']=function(player) Server.new_thread{
timeout=math.floor(180*(math.random()+0.5)),data=player.name
}:on_event('timeout',function(self)
@@ -153,4 +163,4 @@ script.on_event(defines.events.on_console_chat,function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingBot.autoMessage
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Server = require('ExpGamingCore.Server')
@@ -10,7 +10,7 @@ local Game = require('FactorioStdLib.Game')
local Role -- ExpGamingCore.Role@4.0.0
local Sync -- ExpGamingCore.Sync@4.0.0
-- Local Varibles
-- Local Variables
-- Module Define
local module_verbose = false
@@ -25,7 +25,7 @@ local ThisModule = {
}
-- Event Handlers Define
script.on_init(function(event)
script.on_init(function()
Server.new_thread{
name='auto-message',
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
if not data.high_role or not data.low_role
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
for _,message in pairs(data.low) do
player_return({'ExpGamingBot-autoMessage.message',message},nil,player)
end
end):on_event('error',function(self,err)
if Sync then Sync.emit_embeded{
if Sync then Sync.emit_embedded{
title='Auto Message Error',
color=Color.to_hex(defines.textcolor.bg),
description='Auto Message Error - Closed Thread',
@@ -72,4 +71,4 @@ script.on_init(function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingBot.discordAlerts@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
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>'
if data.by == '<server>' then return end
if command == 'config' or command == 'banlist' then
Sync.emit_embeded{
Sync.emit_embedded{
title='Edit To '..data.title,
color=Color.to_hex(defines.textcolor.bg),
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 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'
Sync.emit_embeded{
Sync.emit_embedded{
title='Player '..data.title,
color=data.colour,
description='There was a player '..data.command..'.',
@@ -60,4 +60,4 @@ script.on_event(defines.events.on_console_command,function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

@@ -37,7 +37,7 @@ script.on_event(defines.events.on_player_respawned,function(event)
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)
local player = Game.get_player(event)
if player.admin then
@@ -74,10 +74,10 @@ return {
script.on_event(defines.events.role_change,function(event)
local player = Game.get_player(event)
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
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
end
end)

View File

@@ -3,7 +3,7 @@
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
--- Toogles cheat mode for a player
--- Toggles cheat mode for a player
-- @command cheat-mode
-- @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', {

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]}
elseif command == 'remove' then
if not homes[name] then player_return{'ExpGamingCommands-home.invalid',name} end
homes[name] = nil
homes[name] = nil
homes._n=homes._n-1
player_return{'ExpGamingCommands-home.remove',name}
elseif command == 'goto' then
@@ -42,6 +42,6 @@ commands.add_command('home', 'Allows you to set, remove and goto your homes', {
else
player_return{'ExpGamingCommands-home.homes',homes._n,homes._m}
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)

View File

@@ -28,7 +28,7 @@ local ThisModule = {
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
-- @function repairDisallow
-- @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
-- @command repair
-- @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'}
}, function(event,args)
local range = args.range

View File

@@ -13,7 +13,7 @@ local Color = require('FactorioStdLib.Color')
-- @usage return commands.error('err message')
commands.error = setmetatable({},{__call=function(...) return ... end})
commands._add_command = commands.add_command
local data = {}
local commandDataStore = {}
local middleware = {}
--- 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
-- @treturn table the command data
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
-- @usage commands.validate[type](value,event,...)
-- @tparam string type the type that the value should be
@@ -40,11 +40,11 @@ setmetatable(commands,{
-- @return[2] error constant
-- @return[2] the err message
-- @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_inf same as string but is infite in length, must be last arg
-- @field string_len same as string but can define a max lengh
-- @field string basically does nothing but a type filed is required
-- @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 length
-- @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 after it has been floored min < math.floor(X) <= max
-- @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_alive converts the input to a player if the player is a lower rank than the user and online and alive
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,
['string']=function(value,event) return tostring(value) end,
['string-inf']=function(value,event) return tostring(value) end,
['string-list']=function(value,event,list)
['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) return tostring(value) end,
['string-inf']=function(value) return tostring(value) end,
['string-list']=function(value,event,list)
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,
['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
if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len',max} end return rtn end,
['number']=function(value,event)
local rtn = tonumber(value) or nil
['number']=function(value)
local rtn = tonumber(value) or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end,
['number-int']=function(value,event)
local rtn = tonumber(value) and math.floor(tonumber(value)) or nil
['number-int']=function(value)
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,
['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
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
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
if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end,
['player-online']=function(value,event)
local player,err = commands.validate['player'](value)
['player-online']=function(value)
local player,err = commands.validate['player'](value)
if err then return commands.error(err) end
local rtn = player.connected and player or nil
if not rtn then return commands.error{'ExpGamingCore_Command.error-player-online'} end return rtn end,
['player-alive']=function(value,event)
local player,err = commands.validate['player-online'](value)
['player-alive']=function(value)
local player,err = commands.validate['player-online'](value)
if err then return commands.error(err) end
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,
['player-rank']=function(value,event)
local player,err = commands.validate['player'](value)
if err then return commands.error(err) end
['player-rank']=function(value,event)
local player,err = commands.validate['player'](value)
if err then return commands.error(err) end
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,
['player-rank-online']=function(value,event)
local player,err = commands.validate['player-online'](value)
if err then return commands.error(err) end
local player,err = commands.validate['player-rank'](player)
['player-rank-online']=function(value)
local player,err = commands.validate['player-online'](value)
if err then return commands.error(err) end
local player,err = commands.validate['player-rank'](player)
if err then return commands.error(err) end return player end,
['player-rank-alive']=function(value,event)
local player,err = commands.validate['player-alive'](value)
if err then return commands.error(err) end
local player,err = commands.validate['player-rank'](player)
['player-rank-alive']=function(value)
local player,err = commands.validate['player-alive'](value)
if err then return commands.error(err) end
local player,err = commands.validate['player-rank'](player)
if err then return commands.error(err) end return player end,
}
--- 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
-- @treturn string the formated string for the inputs
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
local rtn = ''
for name,data in pairs(command.inputs) do
@@ -136,13 +136,13 @@ function commands.validate_args(event)
local rtn = {}
local count = 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
-- checks that there is some args given if there is ment to be
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 meant to be
if not event.parameter then
if count == count_opt then return rtn
else return commands.error('invalid-inputs') 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 index = 0
for _,word in pairs(words) do
@@ -158,7 +158,7 @@ function commands.validate_args(event)
end
end
-- assigns the values from the words to the args
local index = 0
index = 0
for name,data in pairs(command.inputs) do
index = index+1
local arg = words[index]
@@ -178,10 +178,10 @@ end
-- @tparam ?index|name|player| player the player to test as
-- @treturn table a table containg all the commands the player can use
function commands.get_commands(player)
player = Game.get_player(player)
local commands = {}
local player = Game.get_player(player)
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
local success, err = pcall(callback,player,name,data)
if not success then error(err)
@@ -207,7 +207,7 @@ end
local function run_custom_command(command)
local data = commands.data[command.name]
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
local success, err = pcall(callback,player,command.name,command)
if not success then error(err)
@@ -243,7 +243,7 @@ end
-- @usage --see examples in file
-- @tparam string name the name 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
commands.add_command = function(name, description, inputs, callback)
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
verbose('Created Command: '..name)
-- 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 'No Description'
local inputs = is_type(inputs,'table') and inputs or {['param']={false,'string-inf'}}
data[name] = {
inputs = is_type(inputs,'table') and inputs or {['param']={false,'string-inf'}}
commandDataStore[name] = {
name=name,
description=description,
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
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)
data[name].help = help
commandDataStore[name].help = help
commands._add_command(name,help,function(...)
local success, err = Manager.sandbox(run_custom_command,{},...)
if not success then error(err) end
end)
return data[name]
return commandDataStore[name]
end
return commands
@@ -289,8 +289,8 @@ return commands
commands.add_command('foo',{'foo.description'},{
['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
['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
['reason']={false,'string-inf'} -- an optinal arg that is and infite lengh (useful for reasons)
['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 optional arg that is and infinite length (useful for reasons)
},function(event,args)
args.player.print(args.number)
if args.reasons then args.player.print(args.reason) end

View File

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

View File

@@ -15,11 +15,11 @@ center._prototype = {}
--- Adds a new obj to the center gui
-- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function}
-- @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
function center.add(obj)
if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end
if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end
verbose('Created Center Gui: '..obj.name)
setmetatable(obj,{__index=center._prototype,__call=function(self,player,...) return center.open(player,self.name,...) end})
obj.tabs = {}
@@ -30,32 +30,32 @@ function center.add(obj)
end
--- Used to get the center frame of the player, used mainly in script
-- @usage Gui.center.get_flow(player) -- returns gui emelemt
-- @param player a player indifier to get the flow for
-- @usage Gui.center.get_flow(player) -- returns gui element
-- @param player a player identifier to get the flow for
-- @treturn table the gui element flow
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
return player.gui.center.exp_center or player.gui.center.add{name='exp_center',type='flow'}
end
--- 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
-- @param player a player indifier to get the flow for
-- @tparam string center the name of the center frame to open
-- @treturn boelon based on if it successed or not
function center.open(player,center,...)
local player = Game.get_player(player)
-- @param player a player identifier to get the flow for
-- @tparam string center_name the name of the center frame to open
-- @treturn boolean based on if it succeeded or not
function center.open(player,center_name,...)
player = Game.get_player(player)
if not player then error('Invalid player',2) return false end
Gui.center.clear(player)
if not Gui.data.center[center] then return false end
local self = Gui.data.center[center]
if not Gui.data.center[center_name] then return false end
local self = Gui.data.center[center_name]
-- this function is the draw function passed to the open event
self:open(player,function(...) Gui.center._draw(self,...) end,...)
return true
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,...)
game.players[frame.player_index].opened=frame
if is_type(self.draw,'function') then
@@ -66,37 +66,37 @@ end
--- Used to open a center frame for a player
-- @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 tab the name of the tab to open
-- @treturn boelon based on if it successed or not
function center.open_tab(player,center,tab)
local player = Game.get_player(player)
-- @treturn boolean based on if it succeeded or not
function center.open_tab(player,center_name,tab)
player = Game.get_player(player)
if not player then error('Invalid player',2) end
if not Gui.center.open(player,center) then return false end
local name = center..'_'..tab
if not Gui.center.open(player,center_name) then return false end
local name = center_name..'_'..tab
if not Gui.data.inputs_button[name] then return false end
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
end
--- Used to clear the center frame of the player, used mainly in script
-- @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)
local player = Game.get_player(player)
player = Game.get_player(player)
center.get_flow(player).clear()
end
-- 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 from center.draw and passed to the open event
function center._prototype:open(player,draw,...)
local player = Game.get_player(player)
local draw = draw or function(...) center._draw(self,...) end
player = Game.get_player(player)
draw = draw or function(...) center._draw(self,...) end
local center_flow = center.get_flow(player)
if center_flow[self.name] then Gui.center.clear(player) return end
local center_frame = center_flow.add{
@@ -110,8 +110,8 @@ function center._prototype:open(player,draw,...)
draw(center_frame,...)
end
-- this is the default draw function if one is not provided, can be overriden
-- not recomented for direct use see Gui.center.open
-- this is the default draw function if one is not provided, can be overridden
-- not recommended for direct use see Gui.center.open
function center._prototype:draw(frame)
Gui.bar(frame,510)
local tab_bar = frame.add{
@@ -123,8 +123,8 @@ function center._prototype:draw(frame)
tab_bar.style.width = 510
tab_bar.style.height = 65
local tab_bar_scroll = tab_bar.add{
type='scroll-pane',
name='tab_bar_scroll',
type='scroll-pane',
name='tab_bar_scroll',
horizontal_scroll_policy='auto-and-reserve-space',
vertical_scroll_policy='never'
}
@@ -147,7 +147,7 @@ function center._prototype:draw(frame)
tab.style.height = 305
local tab_scroll = tab.add{
type ='scroll-pane',
name='tab_scroll',
name='tab_scroll',
horizontal_scroll_policy='never',
vertical_scroll_policy='auto'
}
@@ -155,8 +155,8 @@ function center._prototype:draw(frame)
tab_scroll.style.vertically_stretchable = true
tab_scroll.style.width = 500
local tab_scroll_flow = tab_scroll.add{
type='flow',
name='tab_scroll_flow',
type='flow',
name='tab_scroll_flow',
direction='vertical'
}
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
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)
-- @tparam string name this is the name of the tab
-- @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)
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
end
-- 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[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
-- @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({},{
__call=function(tbl,location,key,value)
if not location then return tbl end
@@ -31,7 +31,7 @@ Gui.data = setmetatable({},{
-- @usage Gui.bar(frame,100)
-- @param frame the frame to draw the line to
-- @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)
local line = frame.add{
type='progressbar',
@@ -44,11 +44,11 @@ function Gui.bar(frame,width)
return line
end
--- Adds a lable that is centered
-- @usage Gui.centered_label(frane, 'Hello, world!')
--- Adds a label that is centered
-- @usage Gui.centered_label(frame, 'Hello, world!')
-- @tparam LuaGuiElement frame the parent frame to add the label to
-- @tparam string string the string that the lable will have
function Gui.centered_label(frane, string)
-- @tparam string string the string that the label will have
function Gui.centered_label(frame, string)
local flow = frame.add {frame = 'flow'}
local flow_style = flow.style
flow_style.align = 'center'
@@ -62,13 +62,13 @@ function Gui.centered_label(frane, string)
return label
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
-- @param dropdown the dropdown that is to be effected
-- @param _item this is the item to look for
-- @return returns the dropdown if it was successful
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
for index, item in pairs(dropdown.items) do
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 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,cam=frame.camera,surface=game.surfaces['testing']}
-- @tparam table data contains all other params given below
@@ -103,7 +103,7 @@ function Gui.cam_link(data)
data.cam.name='camera'
data.cam.position= data.entity.position
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.style.width = data.width 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 update > #global.cams then update = #global.cams end
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.cam.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 global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then
local remove = {}
local player = Game.get_player(event)
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})
else table.insert(remove,index) end
@@ -173,14 +174,14 @@ script.on_event('on_player_respawned',function(event)
end)
function Gui:on_init()
if loaded_modules['ExpGamingCore.Server'] then
Server = require('ExpGamingCore.Server')
verbose('ExpGamingCore.Server is installed; Loading server src')
script.on_init(require(module_path..'/src/server',{Gui=self}))
if loaded_modules['ExpGamingCore.Server'] then
Server = require('ExpGamingCore.Server')
verbose('ExpGamingCore.Server is installed; Loading server src')
script.on_init(require(module_path..'/src/server',{Gui=self}))
end
end
function Gui:on_post()
function Gui.on_post()
Gui.test = require(module_path..'/src/test',{Gui=Gui})
end

View File

@@ -78,8 +78,8 @@ function inputs._prototype:draw(root)
local success, err = pcall(self.data._items,player,root)
if success then data.items = err else error(err) end
if is_type(self.data._index,'function') then
local success, err = pcall(self.data._index,player,root)
if success then data.selected_index = err else error(err) end
local _success, _err = pcall(self.data._index,player,root)
if _success then data.selected_index = _err else error(_err) end
end
return root.add(data)
else
@@ -87,25 +87,25 @@ function inputs._prototype:draw(root)
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 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
-- @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)
if not is_type(obj,'table') then return end
if not is_type(obj.type,'string') then return end
local type = obj.type
if type == 'button' or
type == 'sprite-button' or
type == 'choose-elem-button' or
type == 'checkbox' or
type == 'radiobutton' or
type == 'textfield' or
type == 'text-box' or
type == 'slider' or
type == 'drop-down'
then else return end
if type ~= 'button'
and type ~= 'sprite-button'
and type ~= 'choose-elem-button'
and type ~= 'checkbox'
and type ~= 'radiobutton'
and type ~= 'textfield'
and type ~= 'text-box'
and type ~= 'slider'
and type ~= 'drop-down'
then return end
verbose('Created Input: '..obj.name..' ('..obj.type..')')
if obj.type == 'button' or obj.type == 'sprite-button' then obj.style = mod_gui.button_style end
obj.draw_data = table.deepcopy(obj)
@@ -139,23 +139,23 @@ end
script.on_event(inputs.events,inputs._event_handler)
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
-- @usage Gui.inputs.add_button('test','Test','Just for testing',{{condition,callback},...})
-- @tparam string name the name of this button
-- @tparam string the display for this button, either text or sprite path
-- @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
function inputs.add_button(name,display,tooltip,callbacks)
local button = inputs.add{
local rtn_button = inputs.add{
type='button',
name=name,
caption=display,
tooltip=tooltip
}
button.data._callbacks = callbacks
button:on_event('click',function(event)
rtn_button.data._callbacks = callbacks
rtn_button:on_event('click',function(event)
local elements = Gui.data['inputs_'..event.element.type] or {}
local button = elements[event.element.name]
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 keys = {alt=event.alt,ctrl=event.control,shift=event.shift}
local element = event.element
local callbacks = button.data._callbacks
if is_type(callbacks,'function') then callbacks = {{function(...) return true end,callbacks}} end
for _,data in pairs(callbacks) do
local btn_callbacks = button.data._callbacks
if is_type(btn_callbacks,'function') then btn_callbacks = {{function() return true end,btn_callbacks}} end
for _,data in pairs(btn_callbacks) do
if is_type(data[1],'function') and is_type(data[2],'function') then
local success, err = pcall(data[1],player,mouse,keys,event)
if success and err == true then
local success, err = pcall(data[2],player,element,event)
if not success then error(err) end
local _success, _err = pcall(data[2],player,element,event)
if not _success then error(_err) end
elseif not success then error(err) end
else error('Invalid Callback Condition Format') end
end
end
end)
return button
return rtn_button
end
--- 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)
local type = 'checkbox'; if radio then type='radiobutton' end
local state = false; if is_type(default,'boolean') then state = default end
local checkbox = inputs.add{
local rtn_checkbox = inputs.add{
type=type,
name=name,
caption=display,
state=state
}
if is_type(default,'function') then checkbox.data._state = default end
checkbox.data._true = callback_true
checkbox.data._false = callback_false
checkbox:on_event('state',function(event)
if is_type(default,'function') then rtn_checkbox.data._state = default end
rtn_checkbox.data._true = callback_true
rtn_checkbox.data._false = callback_false
rtn_checkbox:on_event('state',function(event)
local checkbox = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local state = event.element.state
if state then
if event.element.state then
if is_type(checkbox.data._true,'function') then
local success, err = pcall(checkbox.data._true,player,event.element)
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
end
end)
return checkbox
return rtn_checkbox
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,...}
-- @param elements can be a list of elements or a single element
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
function inputs.add_text(name,box,text,callback)
local type = 'textfield'; if box then type='text-box' end
local textbox = inputs.add{
local rtn_textbox = inputs.add{
type=type,
name=name,
text=text
}
textbox.data._callback = callback
textbox:on_event('text',function(event)
rtn_textbox.data._callback = callback
rtn_textbox:on_event('text',function(event)
local textbox = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local element = event.element
local callback = textbox.data._callback
if is_type(callback,'function') then
local success, err = pcall(callback,player,element.text,element)
local event_callback = textbox.data._callback
if is_type(event_callback,'function') then
local success, err = pcall(event_callback,player,element.text,element)
if not success then error(err) end
else error('Invalid Callback Condition Format') end
end)
return textbox
return rtn_textbox
end
--- 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)
-- @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)
local drop_down = inputs.add{
local rtn_dropdown = inputs.add{
type='drop-down',
name=name,
items=items,
selected_index=index
}
drop_down.data._items = items
drop_down.data._index = index
drop_down.data._callback = callback
drop_down:on_event('selection',function(event)
local drop_down = Gui.data['inputs_'..event.element.type][event.element.name]
rtn_dropdown.data._items = items
rtn_dropdown.data._index = index
rtn_dropdown.data._callback = callback
rtn_dropdown:on_event('selection',function(event)
local dropdown = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local element = event.element
local items = element.items
local selected = items[element.selected_index]
local callback = drop_down.data._callback
if is_type(callback,'function') then
local success, err = pcall(callback,player,selected,items,element)
local drop_items = element.items
local selected = drop_items[element.selected_index]
local drop_callback = dropdown.data._callback
if is_type(drop_callback,'function') then
local success, err = pcall(drop_callback,player,selected,drop_items,element)
if not success then error(err) end
else error('Invalid Callback Condition Format') end
end)
return drop_down
return rtn_dropdown
end
-- 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
-- @alias left
-- @author Cooldude2606
@@ -12,7 +12,7 @@ local Color = require('FactorioStdLib.Color')
local mod_gui = require('mod-gui')
local Gui = require('ExpGamingCore.Gui')
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 = {}
left._prototype = {}
@@ -35,11 +35,11 @@ function left.override_open(state)
end
--- 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 return_value(player) -- toggles visiblity 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
-- @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
-- @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 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 visibility for that player
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
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})
@@ -54,18 +54,18 @@ end
-- @param[opt] players the player to update for, if not given all players are updated, can be one player
function left.update(frame,players)
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
local frames = Gui.data.left or {}
if frame then frames = {[frame]=frames[frame]} or {} end
for name,left in pairs(frames) do
if _left then left:first_open(player) end
for _,left_frame in pairs(frames) do
if left_frame then left_frame:first_open(player) end
end
end
else
local frames = Gui.data.left or {}
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{
data={players=players,frames=frames}
}:on_event('tick',function(thread)
@@ -74,8 +74,8 @@ function left.update(frame,players)
Server.new_thread{
data={player=player,frames=thread.data.frames}
}:on_event('resolve',function(thread)
for name,left in pairs(thread.data.frames) do
if left then left:first_open(thread.data.player) end
for _,left_frame in pairs(thread.data.frames) do
if left_frame then left_frame:first_open(thread.data.player) end
end
end):queue()
end):open()
@@ -91,14 +91,14 @@ function left.open(left_name,player)
local _left = Gui.data.left[left_name]
if not _left then return end
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
Server.new_thread{
data={players=players}
}:on_event('tick',function(thread)
if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1)
_left:open(player)
local next_player = table.remove(thread.data.players,1)
_left:open(next_player)
end):open()
end
end
@@ -112,14 +112,14 @@ function left.close(left_name,player)
local _left = Gui.data.left[left_name]
if not _left then return end
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
Server.new_thread{
data={players=players}
}:on_event('tick',function(thread)
if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1)
_left:close(player)
local next_player = table.remove(thread.data.players,1)
_left:close(next_player)
end):open()
end
end
@@ -129,7 +129,7 @@ end
-- @usage left:open(player)
-- @tparam luaPlayer player the player to open the gui for
function left._prototype:open(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if not player then error('Invalid Player') end
local left_flow = mod_gui.get_frame_flow(player)
if not left_flow[self.name] then self:first_open(player) end
@@ -141,7 +141,7 @@ end
-- @usage left:open(player)
-- @tparam luaPlayer player the player to close the gui for
function left._prototype:close(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if not player then error('Invalid Player') end
local left_flow = mod_gui.get_frame_flow(player)
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
-- @treturn LuaFrame the frame made/updated
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 frame = nil
if left_flow[self.name] then
frame = left_flow[self.name]
local frame
if left_flow[self.name] then
frame = left_flow[self.name]
frame.clear()
else
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
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
-- @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
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)
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
if is_type(self.can_open,'function') then
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 = true end
end
if open == true and left.style.visible ~= true then
left.style.visible = true
if open == true and left_frame.style.visible ~= true then
left_frame.style.visible = true
left_flow['gui-left-hide'].style.visible = true
else
left.style.visible = false
left_frame.style.visible = false
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
if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false 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'}
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
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
local done = {}
for _,name in pairs(order_config) do
local left = Gui.data.left[name]
if left then
local left_frame = Gui.data.left[name]
if left_frame then
done[name] = true
left:first_open(player)
left_frame:first_open(player)
end
end
for name,left in pairs(frames) do
if not done[name] then left:first_open(player) end
for name,left_frame in pairs(frames) do
if not done[name] then left_frame:first_open(player) end
end
end)
@@ -237,7 +237,7 @@ script.on_event(defines.events.on_tick,function(event)
end
end)
function left:on_init()
function left.on_init()
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
end

View File

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

View File

@@ -7,7 +7,7 @@ local Server = require('ExpGamingCore.Server')
Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui')
--- Adds a server thread that allows the camera follows to be toggled off and on
return function(event)
return function()
Server.new_thread{
name='camera-follow',
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,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)
player_return(elem.type..' '..elem.value,nil,player)
end)
local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent)
return game.players[parent.player_index].cheat_mode
end,function(player,element)
player.cheat_mode = true
local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent)
return game.players[parent.player_index].cheat_mode
end,function(player,element)
player.cheat_mode = true
end,function(player,element)
player.cheat_mode = false
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
end,function(player,element)
end,function(player,element)
if player.character then player.character.die() end
Gui.inputs.reset_radio(element.parent['test-radio-reset'])
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
end,function(player,element)
end,function(player,element)
Gui.inputs.reset_radio(element.parent['test-radio'])
end)

View File

@@ -11,7 +11,7 @@ local Game = require('FactorioStdLib.Game')
local mod_gui = require('mod-gui')
local Gui = require('ExpGamingCore.Gui')
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 = {}
@@ -52,7 +52,7 @@ end
-- @usage toolbar.draw(1)
-- @param player the player to draw the tool bar of
function toolbar.draw(player)
local player = Game.get_player(player)
player = Game.get_player(player)
if not player then return end
local toolbar_frame = mod_gui.get_button_flow(player)
toolbar_frame.clear()
@@ -81,7 +81,7 @@ function toolbar.draw(player)
end
end
function toolbar:on_init()
function toolbar.on_init()
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') 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)
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
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_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_jail',function(player,state) if player.character then player.character.active = not state end end)
Role.add_flag('allow_afk_kick')
Role.add_flag('is_donator')
Role.add_flag('is_timed')
Role.add_flag('is_varified')
Role.add_flag('is_verified')
Role.add_flag('not_reportable')
-- Root
@@ -64,7 +64,7 @@ Role{
colour={r=233,g=63,b=233},
is_admin=true,
is_spectator=true,
is_varified=true,
is_verified=true,
not_reportable=true,
allow={
['game-settings']=true,
@@ -80,7 +80,7 @@ Role{
colour={r=0,g=170,b=0},
is_admin=true,
is_spectator=true,
is_varified=true,
is_verified=true,
not_reportable=true,
allow={
['set-home']=true,
@@ -97,7 +97,7 @@ Role{
group='Admin',
colour={r=0,g=196,b=137},
is_spectator=true,
is_varified=true,
is_verified=true,
not_reportable=true,
allow={
['go-to']=true,
@@ -173,7 +173,7 @@ Role{
group='HiMember',
colour={r=140,g=120,b=200},
is_timed=true,
is_varified=true,
is_verified=true,
allow_afk_kick=true,
time=600, -- 10 hours
allow={
@@ -190,13 +190,13 @@ Role{
tag='[Member]',
group='Member',
colour={r=24,g=172,b=188},
is_varified=true,
is_verified=true,
allow_afk_kick=true,
allow={
['edit-tasklist']=true,
['make-warp']=true,
['nuke']=true,
['varified']=true
['verified']=true
}
}
Role{

View File

@@ -2,17 +2,18 @@
-- @module ExpGamingCore.Role@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais Role
-- @alias Role
-- Module Require
local Group = require('ExpGamingCore.Group')
local Game = require('FactorioStdLib.Game')
-- Local Varibles
-- Local Variables
local role_change_event_id = script.generate_event_name('on_role_change')
local RoleGlobal
-- Module Define
local _RoleSelfReference
local module_verbose = false
local Role = {
_prototype={},
@@ -24,7 +25,7 @@ local Role = {
roles=setmetatable({},{
__index=table.autokey,
__newindex=function(tbl,key,value)
rawset(tbl,key,Role.define(value))
rawset(tbl,key,_RoleSelfReference.define(value))
end
}),
on_init=function(self)
@@ -57,10 +58,11 @@ local Role = {
else error('Invalid roles, no roles to load.') end
end
}
_RoleSelfReference=Role
-- Global Define
local global = global{
change_chache_length=15,
change_cache_length=15,
changes={},
latest_change={},
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
-- @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
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(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
@@ -101,19 +103,19 @@ end
--- Used to get the role of a player or the role by name
-- @usage Role.get('foo') -- returns group foo
-- @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
function Role.get(mixed,forceIsRole)
local player = game and Game.get_player(mixed)
if player == SERVER then return {Role.meta.server} end
if not forceIsRole and player then
if not forceIsRole and player then
local rtn = {}
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
return rtn
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,'number') then
elseif is_type(mixed,'number') then
for _,role in pairs(Role.roles) do
if role.index == mixed then return role end
end
@@ -124,25 +126,25 @@ end
-- @usage Role.assign(player,'Root')
-- @usage Role.assign(player,{'Root','Foo'})
-- @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] 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
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
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
if is_type(role,'table') and not role.name then
local ctn = 0
-- 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
local ctn = 0
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
local role = Role.get(role)
role = Role.get(role)
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 #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
return role:add_player(player,by_player,batch)
end
@@ -150,31 +152,31 @@ end
--- Used to remove a player from a role(s)
-- @usage Role.unassign(player,'Root')
-- @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] 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
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
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
local ctn = 0
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
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 global.changes[player.index] then global.changes[player.index]={} end
-- this acts as a way to provent the global table getting too full
if #global.changes[player.index] > global.change_chache_length then table.remove(global.changes[player.index],1) end
-- this acts as a way to prevent the global table getting too full
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
return role:remove_player(player,by_player,batch)
end
--- 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
-- @tparam ?table|LuaPlayer|pointerToPlayer options table of options or a player
-- @treturn role the highest role given in the options
@@ -192,19 +194,19 @@ function Role.get_highest(options)
return highest
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
-- @tparam ?LuaPlayer|pointerToPlayer player the player to revert the changes of
-- @tparam[opt] ?LuaPlayer|pointerToPlayer the player who proformed the role revert
-- @tparam[opt=1] count the number of reverts to do, if 0 all changes chached are reverted
-- @treturn number the number of changes that occured
-- @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 cached are reverted
-- @treturn number the number of changes that occurred
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 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 {}
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
if count > #changes or count == 0 then count = #changes end
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
-- @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
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
@@ -229,7 +231,7 @@ function Role.add_flag(flag,callback)
Role.flags[flag] = callback or true
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
-- @tparam role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested
-- @tparam string flag the flag to test for
@@ -253,7 +255,7 @@ function Role.add_action(action)
table.insert(Role.actions,action)
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'
-- @tparam ?role|LuaPlayer|pointerToPlayer mixed the player or role that will be tested
-- @tparam string action the action to test for
@@ -269,14 +271,14 @@ function Role.allowed(mixed,action)
end
--- 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)
-- @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=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)
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 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
@@ -293,11 +295,11 @@ function Role.print(role,rtn,colour,inv)
return ctn
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=game.player] ?LuaPlayer|pointerToPlayer the player to print the info to, default the player who ran command
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
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
@@ -306,7 +308,7 @@ function Role.debug_output(role,player)
player_return(rtn,_role.colour,player)
end
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
_output(role)
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
Role._prototype.players_mt = {
__call=function(tbl) return tbl.self:get_players(tbl.connected) end,
__pairs=function(tbl)
local players = tbl.self:get_players(tbl.connected)
local function next_pair(tbl,k)
k, v = next(players, k)
__pairs=function(tbl)
local players = tbl.self:get_players(tbl.connected)
local function next_pair(tbl,key)
local k, v = next(players, key)
if v then return k,v end
end
return next_pair, players, nil
end,
__ipairs=function(tbl)
local players = tbl.self:get_players(tbl.connected)
local function next_pair(tbl,k)
k, v = next(players, k)
local players = tbl.self:get_players(tbl.connected)
local function next_pair(tbl,key)
local k, v = next(players, key)
if v then return k,v end
end
return next_pair, players, nil
@@ -374,10 +376,10 @@ Role._prototype.players_mt = {
--- 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
-- @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)
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
@@ -387,8 +389,8 @@ function Role._prototype:print(rtn,colour)
end
--- Returns a table that describes all the permissions and which this role is allowed
-- @usage role:get_permissions() -- retuns table of permissions
-- @treturn table a table of permisions, only includes ones which were defined with Role.add_action
-- @usage role:get_permissions() -- returns table of permissions
-- @treturn table a table of permissions, only includes ones which were defined with Role.add_action
function Role._prototype:get_permissions()
if not self_test(self,'role','get_permissions') then return end
local rtn = {}
@@ -400,12 +402,12 @@ end
-- @usage role:add_player(player)
-- @tparam ?LuaPlayer|PointerToPlayer player the player to add
-- @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)
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
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.players[player.index] then global.players[player.index] = {} end
local highest = Role.get_highest(player) or Role.meta.default
@@ -429,12 +431,12 @@ end
-- @usage role:remove_player(player)
-- @tparam ?LuaPlayer|PointerToPlayer player the player to remove
-- @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)
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
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.players[player.index] then global.players[player.index] = {} end
local highest = Role.get_highest(player) or Role.meta.default
@@ -458,13 +460,13 @@ end
-- Event Handlers Define
script.on_event(role_change_event_id,function(event)
-- varible init
-- variable init
local player = Game.get_player(event)
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)
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
-- assign new tag and group of highest role
Group.assign(player,highest.group)
@@ -476,7 +478,7 @@ script.on_event(role_change_event_id,function(event)
-- send a message to other players
if event.batch_index == 1 then
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 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}}
@@ -524,4 +526,4 @@ end)
-- Module Return
-- 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()
if not game then return {'Offline'} end
local _rtn = {}
for name,role in pairs(Role.roles) do
for _,role in pairs(Role.roles) do
local players = role:get_players()
local _players = {}
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
if Sync.add_to_gui then
Sync.add_to_gui(function(player,frame)
Sync.add_to_gui(function(player)
local names = {}
for _,role in pairs(Role.get(player)) do table.insert(names,role.name) end
return 'You have been assigned the roles: '..table.concat(names,', ')
end)
end
-- adds a discord emit for rank chaning
-- adds a discord emit for rank changing
script.on_event('on_role_change',function(event)
local role = Role.get(event.role_name)
local player = Game.get_player(event)
local by_player = Game.get_player(event.by_player_index) or SERVER
if role.is_jail and RoleGlobal.last_change[1] ~= player.index then
Sync.emit_embeded{
Sync.emit_embedded{
title='Player Jail',
color=Color.to_hex(defines.textcolor.med),
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 timeout an index for threads which will timeout (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 print_to contains players that event details will be printed to
-- @field uuid contains the random number generator for the uuid system
@@ -39,7 +39,7 @@ local global = global{
-- @treturn string the new uuid
Server.uuid = add_metatable({},function()
-- when it is called as a function
local uuid = 0
local uuid
if game then
global.uuid=global.uuid+1
uuid=global.uuid+pre_load_uuid
@@ -68,8 +68,8 @@ Server.threads = setmetatable({},{
__newindex=function(tbl,key,value) rawset(global.all,key,value) end,
__pairs=function(tbl)
local tbl = global.all
local function next_pair(tbl,k)
k, v = next(tbl, k)
local function next_pair(tbl,key)
local k, v = next(tbl, key)
if type(v) ~= nil and k ~= '_n' then return k,v
else return next(tbl, k) end
end
@@ -79,15 +79,15 @@ Server.threads = setmetatable({},{
--- Generates a new thread object
-- @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
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
-- @param mixed either a uuid or the name given to a thread
-- @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)
local threads = global
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
-- @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
-- @treturn boolean was it added successfuly
-- @treturn boolean was it added successfully
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._resolve then return false end
@@ -109,15 +109,15 @@ end
--- 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(true) -- forcefuly close all threads
-- @tparam bolean with_force use force when closing
-- @usage Server.close_all_threads(true) -- forcefully close all threads
-- @tparam boolean with_force use force when closing
function Server.close_all_threads(with_force)
if not with_force then
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
--- 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()
function Server.run_tick_threads()
table.each(global.tick,function(uuid)
@@ -146,8 +146,8 @@ end
-- @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
function Server._thread_debuger(player,event,state)
local player = Game.get_player(player)
local event = tonumber(event) or Manager.event.names[event]
player = Game.get_player(player)
event = tonumber(event) or Manager.event.names[event]
local print_to = global.print_to
print_to[player.index] = print_to[player.index] or {}
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
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
-- @usage script.on_event(defines.events,Server._thread_handler) -- adds this handler
-- @tparam table event the event that is called
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)
if event.name == defines.events.on_tick then return true end
if print_to[event.name] then
@@ -189,7 +189,7 @@ end
--- Adds a event handler to tell threads about events
-- @usage Server.add_thread_handler(defines.event)
-- @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)
if not is_type(event,'number') then return false end
local threads = global
@@ -204,9 +204,9 @@ end
--- 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)',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[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
-- @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
@@ -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
-- creates the resolve function for the thread
use_thread:on_event('resolve',function(thread)
local callback = table.remove(thread.data,1)
callback = is_type(callback,'function') and callback or loadstring(callback)
local env = table.remove(thread.data,1)
if is_type(env,'table') and not is_type(env.__self,'userdata') and env._env == true then
local success, err = Manager.sandbox(callback,env,unpack(thread.data))
local thread_callback = table.remove(thread.data,1)
thread_callback = is_type(thread_callback,'function') and thread_callback or loadstring(thread_callback)
local thread_env = table.remove(thread.data,1)
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(thread_callback,thread_env,unpack(thread.data))
if not success then error(err) end
return err
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
return err
end
@@ -254,13 +254,13 @@ function Server.interface(callback,use_thread,env,...)
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
-- @alias Server._thread
-- @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 reopen when true the thread will reopen itself untill 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 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 be able to access
Server._thread = {}
local _env_metatable = {
@@ -271,15 +271,15 @@ local _env_metatable = {
-- @usage new_thread = thread:create()
-- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any}
-- @treturn Server._thread the new thread object
function Server._thread:create(obj)
local obj = obj or {}
function Server._thread.create(obj)
obj = obj or {}
setmetatable(obj,{__index=Server._thread})
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._env = true
obj._env._ENV = nil -- provents infinte recusion
-- removes any modules from the _env to save space in global (less time to serizle)
obj._env._ENV = nil -- prevents infinite recursion
-- removes any modules from the _env to save space in global (less time to serialize)
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
setmetatable(obj._env,_env_metatable)
@@ -288,21 +288,21 @@ function Server._thread:create(obj)
return obj
end
--- Opens and queses a thread
--- Opens and queues a thread
-- @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
function Server._thread:queue()
self:open()
return Server.queue_thread(self)
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
-- @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
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
skip_location_check or is_type(self.opened,'number') 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._success) or is_type(self._success,'function') and
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
end
return false
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
-- @treturn bolean if the thread was opened successfuly
-- @treturn boolean if the thread was opened successfully
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
local uuid = self.uuid
-- sets the thread to open, this is the tick it was opened
self.opened = game.tick
-- creats the global index
-- creates the global index
global.all[uuid] = global.all[uuid] or self
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 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._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 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 is_type(self._events,'table') then
if is_type(self._events,'table') then
table.each(self._events,function(callback,event,global,uuid)
-- cant be used V
--Server.add_thread_handler(event)
@@ -354,7 +354,7 @@ function Server._thread:open()
return true
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
-- @treturn boolean if the thread had a on_close function
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 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
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
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
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
-- then will look for it in the event handlers and remove it if found
if is_type(self._events,'table') then
table.each(self._events,function(callback,event)
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
-- cant be used V
--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
-- sets the thread to closed
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 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
-- else it will just be wiped from the global index
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)
-- @usage thread:resolve(x,y,z) -- return true
-- @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(...)
local _return = false
-- checks if the resolve haddler is still present
if is_type(self._resolve,'function') then
-- checks if the resolve handler is still present
if is_type(self._resolve,'function') then
local success, err = Manager.sandbox(self._resolve,self._env,self,...)
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
-- interface is used as a way to delay the success call till the next tick
Server.interface(function(thread,err)
local success, err = Manager.sandbox(thread._success,thread._env,thread,err)
if not success then thread:error(err) end
local _success, _err = Manager.sandbox(thread._success,thread._env,thread,err)
if not _success then thread:error(_err) end
end,true,self,err)
-- later returns true if there was a call to the success handler
_return = true
@@ -422,9 +422,9 @@ function Server._thread:resolve(...)
return _return
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
-- @treturn bolean if the thread timed out
-- @treturn boolean if the thread timed out
function Server._thread:check_timeout()
local _return = false
-- makes sure the thread is still valid
@@ -436,7 +436,7 @@ function Server._thread:check_timeout()
Manager.sandbox(self._timeout,self._env,self)
end
_return = true
-- closes the thread to provent any further event calls
-- closes the thread to prevent any further event calls
self:close()
end
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
-- @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
function Server._thread:error(err)
local _return = false
@@ -453,12 +453,12 @@ function Server._thread:error(err)
_return = true
else
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
return _return
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_only_events = ['close','timeout','tick','resolve','success','error']
-- @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
function Server._thread:on_event(event,callback)
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)
if value and is_type(callback,'function') then
-- 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)
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
setmetatable(thread,{__index=Server._thread})
setmetatable(thread._env,_env_metatable)
@@ -535,7 +535,7 @@ return Server
end)
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{
name='tree-decon',
data={}

View File

@@ -7,7 +7,6 @@
--- This file will be loaded when ExpGamingCore.Command is present
-- @function _comment
local Game = require('FactorioStdLib.Game')
local Server = Server
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)
end
-- 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
local success, err = Server.interface(callback,false,env)
-- 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
-- @alias Sync
-- @author Cooldude2606
@@ -16,10 +16,10 @@ local module_verbose = false --true|false
-- @field server_name the server name
-- @field server_description a short description 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 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 ranks a list of player ranks
-- @field rockets the number of rockets launched
@@ -58,9 +58,9 @@ local global = global{
-- @field afk_players the number of afk players
-- @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'}
-- @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)
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)}
@@ -70,7 +70,7 @@ end
-- @usage Sync.print('Test','Cooldude2606')
-- @tparam string player_message the message to be printed in chat
-- @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 prefix add a prefix before the chat eg [IRC]
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 tag = player_tag and player_tag ~= '' and ' '..player_tag or ''
local colour = type(player_colour) == 'string' and player_colour or '#FFFFFF'
local prefix = prefix and prefix..' ' or ''
-- if it is an ingame player it will over ride the given params
prefix = prefix and prefix..' ' or ''
-- if it is an in game player it will over ride the given params
if player then
tag = ' '..player.tag
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)
end
--- Outline of the paramaters accepted by Sync.emit_embeded
--- Outline of the parameters accepted by Sync.emit_embedded
-- @table EmitEmbededParamaters
-- @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}
@@ -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)
--- 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' ... }
-- @tparam table args a table which contains everything that the embeded will use
-- @usage Sync.emit_embedded{title='BAN',color='0x0',description='A player was banned' ... }
-- @tparam table args a table which contains everything that the embedded will use
-- @see EmitEmbededParamaters
function Sync.emit_embeded(args)
if not is_type(args,'table') then error('Args table not given to Sync.emit_embeded',2) end
function Sync.emit_embedded(args)
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
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'
@@ -130,14 +130,14 @@ function Sync.emit_embeded(args)
table.insert(fields,f)
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 = {
title=title,
description=description,
color=color,
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
--- 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)
if not game then return error(error()) end
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)
--- Used to get the number of admins currently online
@@ -169,7 +169,7 @@ end
-- @treturn number the number of afk players
function Sync.count_afk_times(time)
if not game then return 0 end
local time = time or 7200
time = time or 7200
local rtn = {}
for _,player in pairs(game.connected_players) do
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
end,
__pairs=function(tbl)
local tbl = global
local function next_pair(tbl,k)
k, v = next(tbl, k)
tbl = global
local function next_pair(tbl,key)
local k, v = next(tbl, key)
if type(v) ~= nil then return k,v end
end
return next_pair, tbl, nil
end,
__ipairs=function(tbl)
local tbl = global
tbl = global
local function next_pair(tbl, i)
i = i + 1
local v = tbl[i]
@@ -305,7 +305,7 @@ end
-- @usage Sync.time('Sun Apr 1 18:44:30 UTC 2018')
-- @usage Sync.time -- string
-- @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)
local info = Sync.info
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
-- @alias Sync
-- @author Cooldude2606
@@ -7,17 +7,16 @@
--- This file will be loaded when ExpGamingCore.Gui is present
-- @function _comment
local Game = require('FactorioStdLib.Game')
local Gui = require('ExpGamingCore.Gui')
local Sync = Sync -- this is to force sync to remain in the ENV
local Sync_gui_functions = {}
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
-- @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,...)
if game then return false end
if is_type(element,'function') then
@@ -29,10 +28,10 @@ function Sync.add_to_gui(element,...)
return true
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)
--- Formats a lable to be a certain format
--- Formats a label to be a certain format
-- @local label_format
local function label_format(label,width)
label.style.width = width
@@ -49,7 +48,7 @@ Sync.info_gui = Gui.center{
draw=function(self,frame)
frame.caption = ''
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'}
h_flow.add{type='sprite',sprite=logo_sprite_path}
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(frame,600)
local _frame = frame
local frame = frame.add{
frame = frame.add{
type='frame',
direction='vertical',
style='image_frame'

View File

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

View File

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

View File

@@ -13,8 +13,8 @@ Sync.add_update('rockets',function()
_return.time = Sync.tick_format(time)
_return.fastest = Sync.tick_format(global.fastest)
_return.milestones = {}
for milestone,time in pairs(global.milestones) do
_return.milestones[milestone] = Sync.tick_format(time)
for milestone,next_time in pairs(global.milestones) do
_return.milestones[milestone] = Sync.tick_format(next_time)
end
return _return
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
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game')
-- Local Varibles
-- Local Variables
local science_packs = {
'science-pack-1',
'science-pack-2',
@@ -23,7 +23,7 @@ local science_packs = {
local module_verbose = false
local ThisModule = {
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
}
@@ -48,7 +48,7 @@ ThisModule.Gui = Gui.left{
verbose('Added Science Global for: '..player.force.name)
global[player.force.name] = table.deepcopy(global._base)
end
force_data = global[player.force.name]
local force_data = global[player.force.name]
frame.caption = {'ExpGamingInfo-Science.name'}
frame.add{
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)
-- 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})

View File

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

View File

@@ -2,7 +2,7 @@
-- @module ExpGamingInfo.Tasklist
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Gui = require('ExpGamingCore.Gui')
@@ -102,26 +102,26 @@ local add = Gui.inputs{
end)
local function _tasks(player)
local player = Game.get_player(player)
player = Game.get_player(player)
local data = global._edit[player.index]
if not data then return global.tasks end
local _edit = false
local editing = false
for _,v in pairs(data._editing) do
if v == true then
_edit = true
editing = true
break
end
end
if data._edit and not _edit then
if data._edit and not editing then
global.tasks = table.deepcopy(data._tasks)
global._edit[player.index] = table.deepcopy(global._base)
Gui.left.update('tasklist')
return global.tasks
elseif not data._edit and _edit then
elseif not data._edit and editing then
data._edit = true
for key,_ in pairs(data._tasks) do if not data._editing[key] then data._editing[key] = false end end
return data._tasks
elseif _edit then return data._tasks
elseif editing then return data._tasks
else return global.tasks
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 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'}
-- @tparam table tbl table to be unpacked
function ExpLib.unpack_to_G(tbl)
@@ -25,7 +25,7 @@ end
-- @treturn table the env table with _G keys removed
-- @warning does not work from console
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})
while true do
if not debug.getinfo(level) then break end
@@ -46,7 +46,7 @@ end
-- @warning does not work from console
function ExpLib.get_upvalues(level)
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
local upvalues = setmetatable({},{__index=_G})
local i = 1
@@ -58,7 +58,7 @@ function ExpLib.get_upvalues(level)
return upvalues
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
-- @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
@@ -66,8 +66,8 @@ end
-- @treturn table the new table with its metatable set
function ExpLib.add_metatable(tbl,callback,string)
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
local string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring
callback = ExpLib.is_type(callback,'function') and callback or 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,{
__tostring=string,
__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
--- 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') -- return false
-- @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
-- @treturn bolean is v of type test_type
-- @treturn boolean is v of type 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
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','table','Value is not a string') -- return error
-- @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)
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')
-- @tparam table self the table that is the object
-- @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!',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
-- @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
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]
local player = player or game.player
colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour]
player = player or game.player
local function _return(callback,rtn)
if ExpLib.is_type(rtn,'table') then
-- 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
end
if player then
-- allows any vaild player identifier to be used
local player = Game.get_player(player)
-- allows any valid player identifier to be used
player = Game.get_player(player)
if not player then error('Invalid Player given to player_return',2) end
-- plays a nice sound that is different to normal message sound
player.play_sound{path='utility/scenario_message'}
@@ -175,8 +175,8 @@ function ExpLib.tick_to_display_format(tick)
end
end
--- Used as a way to view the structure of a gui, used for debuging
-- @usage Gui_tree(root) returns all children of gui recusivly
--- Used as a way to view the structure of a gui, used for debugging
-- @usage Gui_tree(root) returns all children of gui recursively
-- @tparam LuaGuiElement root the root to start the tree from
-- @treturn table the table that describes the gui
function ExpLib.gui_tree(root)
@@ -249,13 +249,13 @@ function table.tostring(tbl)
return "{"..table.concat(result,",") .."}"
end
--- Simmilar to table.tostring but converts a lua table to a json one
-- @usage talbe.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}'
--- Similar to table.tostring but converts a lua table to a json one
-- @usage table.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}'
-- @tparam table lua_table the table to convert
-- @treturn string the table in a json format
function table.json(lua_table)
--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
done[key] = true
if type(value) == 'table' then table.insert(result,table.json(value,true))
@@ -265,14 +265,14 @@ function table.json(lua_table)
end
for key,value in pairs(lua_table) do
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))
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))
end
end
end
if only_indexs then return "["..table.concat(result,",").."]"
if only_indexes then return "["..table.concat(result,",").."]"
else return "{"..table.concat(result,",").."}"
end
end

View File

@@ -8,13 +8,13 @@ local Role -- ExpGamingCore.Role@^4.0.0
local Sync -- ExpGamingCore.Sync@^4.0.0
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 player_count = #game.connected_players
local role_count = Role and Role.meta.count or 1
local role_index = role.allow_afk_kick and role.index or false
if not base then return false end
return (role_count/role_index)*count
if not role_index then return false end
return (role_count/role_index)*player_count
end
script.on_event(defines.events.on_tick,function(event)

View File

@@ -17,7 +17,7 @@ script.on_init(function(event)
end
end):on_event('error',function(self,err)
if Sync then
Sync.emit_embeded{
Sync.emit_embedded{
title='Auto Kick Error',
color=Color.to_hex(defines.textcolor.bg),
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
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Admin = require('ExpGamingAdmin')
local Game = require('FactorioStdLib.Game')
local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles
-- Local Variables
-- removed from none admin ranks, no further action
local low_items = {
'loader',
@@ -36,7 +35,7 @@ local high_items = {
}
-- inventories which are searched
local inventorys = {
local inventories = {
defines.inventory.player_main,
defines.inventory.player_quickbar,
defines.inventory.player_trash
@@ -63,7 +62,7 @@ end
function ThisModule.search_player(player)
for category,items in pairs(_root_tree) do
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)
if inventory then
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 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
local _player = {}
_player.index = player.index
@@ -26,7 +26,7 @@ local function get_player_info(player,frame,add_cam)
_player.roles = roles
end
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
if Role then frame.style.height = 300
else frame.style.height = 260 end

View File

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

View File

@@ -8,7 +8,7 @@ local Server = require('ExpGamingCore.Server')
local Gui = require('ExpGamingCore.Gui')
local Role -- ExpGamingCore.Server@^4.0.0
-- Local Varibles
-- Local Variables
local poll_time_out = 90 -- In seconds
-- Module Define
@@ -27,7 +27,7 @@ local global = global{
-- Function Define
local function _poll_data(question,answers)
local poll = {
local rtn_poll = {
uuid=Server.uuid(),
question=question,
answers=answers or {'None'},
@@ -35,7 +35,7 @@ local function _poll_data(question,answers)
voted={}
}
Server.new_thread{
data={poll_uuid=poll.uuid},
data={poll_uuid=rtn_poll.uuid},
timeout=poll_time_out*60
}:on_event('timeout',function(self)
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)
verbose('Ended Poll: '..poll.question..' ('..uuid..') Highest: '..highest[1])
end):open()
global.active[tostring(poll.uuid)]=poll
verbose('Created Poll: '..question..' ('..poll.uuid..')')
return poll.uuid
global.active[tostring(rtn_poll.uuid)]=rtn_poll
verbose('Created Poll: '..question..' ('..rtn_poll.uuid..')')
return rtn_poll.uuid
end
local function draw_poll(frame)
@@ -86,18 +86,18 @@ local function draw_poll(frame)
end
end
local function _opptions(player,root_frame)
local opptions = {'Please Select An Opption'}
local function _options(player,root_frame)
local options = {'Please Select An option'}
local uuid = root_frame.name
local poll = global.active[uuid]
if not poll then return {'Invalid Poll'} end
for _,answer in pairs(poll.answers) do
table.insert(opptions,answer)
table.insert(options,answer)
end
return opptions
return options
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 poll = global.active[uuid]
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
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 options = element.parent.parent.parent.options
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
if options.last.caption == element.parent.name then
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)
_self_referace_poll_option_input = poll_option_input
_self_reference_poll_option_input = poll_option_input
local function poll_assembler(frame)
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='Question: '..poll.question}
flow.add{type='label',name='answer',caption='Your Answer: None'}
opption_drop_down(flow)
option_drop_down(flow)
end
}:add_left{
caption='utility/item_editor_icon',
@@ -245,11 +245,11 @@ ThisModule.Gui = Gui.popup{
caption='Viewing Poll: 1',
style='caption_label'
}
local btn = next:draw(title)
btn = next:draw(title)
btn.style.width = 20
btn.style.height = 20
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.height = 20
end
@@ -269,5 +269,5 @@ ThisModule.Gui = Gui.popup{
-- Event Handlers Define
-- 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})

View File

@@ -7,7 +7,7 @@
local Server = require('ExpGamingCore.Server')
local Gui = require('ExpGamingCore.Gui')
-- Local Varibles
-- Local Variables
--{type='slider',object='',key='',name='',min=x,max=y}
--{type='function',object='',key='',name='',param={}}
local basic_settings = {
@@ -122,8 +122,7 @@ local are_you_sure = Gui.inputs.add_checkbox('game-settings-are-you-sure',true,n
end)
local function _draw_setting(frame,setting)
local frame = frame.add{type='flow'}
local frame = frame.add{
frame = frame.add{type='flow'}.add{
type='flow',
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
-- @author Cooldude2606
-- @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
local Game = require('FactorioStdLib.Game')
@@ -27,15 +27,15 @@ local function _roles(player)
return roles
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
if selected == 'Select Role' then element.parent['send-annoncement'].style.visible = false
else element.parent['send-annoncement'].style.visible = true end
if selected == 'Select Role' then element.parent['send-announcement'].style.visible = false
else element.parent['send-announcement'].style.visible = true end
end)
local send_popup = Gui.inputs{
type='button',
name='send-annoncement',
name='send-announcement',
caption='utility/export_slot'
}:on_event('click',function(event)
local player = Game.get_player(event)
@@ -74,7 +74,7 @@ ThisModule.Gui = Gui.popup{
tooltip={'GuiAnnouncements.tooltip'},
draw=function(self,frame)
frame.caption = {'GuiAnnouncements.name'}
local frame = frame.add{
frame = frame.add{
type='flow',
direction='vertical'
}

View File

@@ -2,7 +2,7 @@
-- @module PlayerAutoColor@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Color = require('FactorioStdLib.Color')
@@ -28,7 +28,7 @@ local global = global{
}
-- 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 colours = table.keys(defines.color)
player.color = defines.color.black
@@ -44,4 +44,4 @@ Event.register(defines.events.on_player_created, function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

@@ -2,12 +2,12 @@
-- @module SpawnArea@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Game = require('FactorioStdLib.Game')
-- Local Varibles
-- Local Variables
local turret_enabled = true
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 decon_radius = 20
local decon_tile = 'concrete'
local partern_radius = 50
local partern_tile = 'stone-path'
local pattern_radius = 50
local pattern_tile = 'stone-path'
-- Module Define
local module_verbose = false
@@ -45,10 +45,10 @@ end
function ThisModule.auto_turret(surface,pos)
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
if surface then
local surface = Game.get_surface(surface)
surface = Game.get_surface(surface)
if not surface then error('Surface is not valid.') end
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.')
@@ -57,7 +57,7 @@ function ThisModule.auto_turret(surface,pos)
-- 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
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]})
if not turret then
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 surface = player.surface
local offset = {x=0,y=0}
local partern_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
local pattern_base_tile = surface.get_tile(player.position).name
if pattern_base_tile == 'deepwater' or pattern_base_tile == 'water' then pattern_base_tile = 'grass-1' end
local base_tiles = {}
local tiles = {}
-- generates a safe area of land and removes all entites
for x = -partern_radius, partern_radius do
for y = -partern_radius, partern_radius do
-- generates a safe area of land and removes all entities
for x = -pattern_radius, pattern_radius do
for y = -pattern_radius, pattern_radius do
if x^2+y^2 < decon_radius^2 then
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}}}
for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end
elseif x^2+y^2 < partern_radius^2 then
table.insert(base_tiles,{name=partern_base_tile,position={x+offset.x,y+offset.y}})
elseif x^2+y^2 < pattern_radius^2 then
table.insert(base_tiles,{name=pattern_base_tile,position={x+offset.x,y+offset.y}})
end
end
end
surface.set_tiles(base_tiles)
-- creates the partern in the spawn
-- creates the pattern in the spawn
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
surface.set_tiles(tiles)
-- spawns all the entites in spawn
-- spawns all the entities in spawn
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
end
-- generates spawn turrents and afk belts
-- generates spawn turrets and afk belts
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})
@@ -123,4 +123,4 @@ script.on_event(defines.events.on_player_created, function(event)
end)
-- Module Return
return ThisModule
return ThisModule

View File

@@ -2,14 +2,14 @@
-- @module WarpPoints@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Gui = require('ExpGamingCore.Gui')
local Game = require('FactorioStdLib.Game')
local Role -- ExpGamingCore.Role@^4.0.0
-- Local Varibles
-- Local Variables
local warp_tiles = require(module_path..'/src/warp_tiles')
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 offset = warp.position
local tiles = {}
local tiles = {}
-- clears the area where the warp was
for x = -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 force force the force that the warp point will belong to
-- @tparam string name the name of the warp point to be made
function ThisModule.make_warp_point(position,surface,force,name)
local warp = global.warps[name]
if warp then return end; warp = nil
function ThisModule.make_warp_point(position,surface,force,warpName)
local warp = global.warps[warpName]
if warp then return end
local offset = {x=math.floor(position.x),y=math.floor(position.y)}
local old_tile = surface.get_tile(offset).name
local base_tiles = {}
@@ -88,22 +87,22 @@ function ThisModule.make_warp_point(position,surface,force,name)
end
end
surface.set_tiles(base_tiles)
-- this adds the patern and entities
for _,position 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}})
-- this adds the pattern and entities
for _,pos in pairs(warp_tiles) do
table.insert(tiles,{name=warp_tile,position={pos[1]+offset.x+global_offset.x,pos[2]+offset.y+global_offset.y}})
end
surface.set_tiles(tiles)
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
end
-- creates a tag on the map for the wap point
local tag = force.add_chart_tag(surface,{
position={offset.x+0.5,offset.y+0.5},
text='Warp: '..name,
text='Warp: '..warpName,
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}
global.warps.Spawn = nil
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
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
and player.surface.name == 'nauvis'
and player.surface.name == 'nauvis'
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
@@ -199,7 +198,7 @@ ThisModule.Gui = Gui.left{
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
elseif player.surface.get_tile(player.position).name == warp_tile
and player.surface.name == 'nauvis'
and player.surface.name == 'nauvis'
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}
@@ -213,7 +212,7 @@ script.on_event(defines.events.on_tick,function(event)
if not (event.tick % 60 == 0) then return end
for index,time in pairs(global.cooldowns) do
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
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 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 tile == warp_tile and player.surface.name == 'nauvis' then
if tile == warp_tile and player.surface.name == 'nauvis' then
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)
else ThisModule.Gui:close(player) end
end
@@ -246,4 +245,4 @@ script.on_event(defines.events.on_player_created, function(event)
end)
-- 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
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
-- @alais ThisModule
-- @alias ThisModule
-- Module Require
local Game = require('FactorioStdLib.Game')
-- Local Varibles
local entites = require(module_path..'/src/entites')
-- Local Variables
local entities = require(module_path..'/src/entites')
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 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
-- 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)
end
--- Downgrads a tile in this position
--- Downgrades a tile in this position
-- @usage ThisModule.down_grade(surface,{x=10,y=10})
-- @tparam surface surface the surface the tile is on
-- @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 new_tile = paths[tile][2]
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
surface.set_tiles{{name=new_tile,position=pos}}
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 old_tiles = event.tiles
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
global[global_key(surface,old_tile.position)]=old_tile.old_tile.name -- not a mistake, this makes it have dimising returns
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 demising returns
end
end
end)
script.on_event(defines.events.on_player_changed_position, function(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
local surface = player.surface
local pos = player.position
@@ -76,7 +76,7 @@ end)
script.on_event({defines.events.on_built_entity,on_robot_built_entity}, function(event)
local entity = event.created_entity
local surface = entity.surface
if entites[entity.name] then
if entities[entity.name] then
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
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)
-- Module Return
-- 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
local tile_name = surface.get_tile(position).name
/interface
local tile_name = surface.get_tile(position).name
if not paths[tile_name] then return end
local count = -9 -- this value is important
for x = -1,1 do for y = -1,1 do
local _pos = {position.x+x,position.y+y}
if placed_paths[tile_name] and not placed_paths[surface.get_tile(_pos).name]
or surface.get_tile(_pos).name == paths[tile_name][2]
if placed_paths[tile_name] and not placed_paths[surface.get_tile(_pos).name]
or surface.get_tile(_pos).name == paths[tile_name][2]
then count=count+1 end
end end
return paths[tile_name][1]/(count-adjacency_boost)