Made all functions non anon

This commit is contained in:
Cooldude2606
2018-10-26 14:46:17 +01:00
parent f14c50852c
commit ea334175ee
5 changed files with 120 additions and 115 deletions

View File

@@ -19,22 +19,8 @@ local ThisModule = {
end end
} }
-- Event Handlers Define local function on_marked_for_deconstruction(self,event)
Event.register(-1,function(event) -- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
Server.new_thread{
name='tree-decon',
data={trees={},chache={},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 #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)
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
local chache = self.data.chache[event.player_index] local chache = self.data.chache[event.player_index]
if not chache then if not chache then
local player = Game.get_player(event) local player = Game.get_player(event)
@@ -67,7 +53,22 @@ Event.register(-1,function(event)
self.data.clear = game.tick + 10 self.data.clear = game.tick + 10
end end
end end
end):open() end
-- Event Handlers Define
Event.register(-1,function(event)
Server.new_thread{
name='tree-decon',
data={trees={},chache={},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 #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,on_marked_for_deconstruction):open()
end) end)
-- Module Return -- Module Return

View File

@@ -24,6 +24,32 @@ local ThisModule = {
end end
} }
local function on_player_joined_game(self,event)
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
local player = Game.get_player(event)
if not player then return end
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
local function on_error(self,err)
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
if Sync then Sync.emit_embeded{
title='Auto Message Error',
color=Color.to_hex(defines.textcolor.bg),
description='Auto Message Error - Closed Thread',
Error=err
} end
self.reopen = false
self:close()
end
-- Event Handlers Define -- Event Handlers Define
script.on_init(function(event) script.on_init(function(event)
Server.new_thread{ Server.new_thread{
@@ -48,31 +74,7 @@ script.on_init(function(event)
game.print{'ExpGamingBot-autoMessage.message',{'ExpGamingBot-autoMessage.players-online',#game.connected_players}} game.print{'ExpGamingBot-autoMessage.message',{'ExpGamingBot-autoMessage.players-online',#game.connected_players}}
game.print{'ExpGamingBot-autoMessage.message',{'ExpGamingBot-autoMessage.map-time',tick_to_display_format(game.tick)}} game.print{'ExpGamingBot-autoMessage.message',{'ExpGamingBot-autoMessage.map-time',tick_to_display_format(game.tick)}}
self.reopen = true self.reopen = true
end):on_event(defines.events.on_player_joined_game,function(self,event) end):on_event(defines.events.on_player_joined_game,on_player_joined_game):on_event('error',on_error):open()
-- the _env should be auto loaded but it does not for some reason
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
local player = Game.get_player(event)
if not player then return end
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)
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if Sync then Sync.emit_embeded{
title='Auto Message Error',
color=Color.to_hex(defines.textcolor.bg),
description='Auto Message Error - Closed Thread',
Error=err
} end
self.reopen = false
self:close()
end):open()
end) end)
-- Module Return -- Module Return

View File

@@ -85,14 +85,11 @@ function popup.open(style,data,players)
else error('No Draw On Popup '.._popup.name) end else error('No Draw On Popup '.._popup.name) end
end end
else else
Server.new_thread{ local function on_tick(self)
data={players=players,popup=_popup,data=data} -- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
}:on_event('tick',function(thread) if #self.data.players == 0 then self:close() return end
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues local player = table.remove(self.data.players,1)
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end if self.data.popup.left then self.data.popup.left:close(player) end
if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1)
if thread.data.popup.left then thread.data.popup.left:close(player) end
local flow = popup.flow(player) local flow = popup.flow(player)
flow.style.visible=true flow.style.visible=true
local _frame = flow.add{ local _frame = flow.add{
@@ -106,12 +103,15 @@ function popup.open(style,data,players)
direction='vertical', direction='vertical',
style='image_frame' style='image_frame'
} }
thread.data.popup.close(_frame) self.data.popup.close(_frame)
if is_type(thread.data.popup.draw,'function') then if is_type(self.data.popup.draw,'function') then
local success, err = pcall(thread.data.popup.draw,frame,thread.data.data) local success, err = pcall(self.data.popup.draw,frame,self.data.data)
if not success then error(err) end if not success then error(err) end
else error('No Draw On Popup '..thread.data.popup.name) end else error('No Draw On Popup '..self.data.popup.name) end
end):open() end
Server.new_thread{
data={players=players,popup=_popup,data=data}
}:on_event('tick',on_tick):open()
end end
end end

View File

@@ -6,6 +6,21 @@ local Server = require('ExpGamingCore.Server@^4.0.0')
Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui') Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui')
local function on_player_respawned(self,event)
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
if self.data.players[event.player_index] then
local remove = {}
local player = Game.get_player(event)
for index,cam in pairs(self.data.players[event.player_index]) do
if cam.valid then table.insert(self.data.cams,{cam=cam,entity=player.character,surface=player.surface})
else table.insert(remove,index) end
end
for n,index in pairs(remove) do
table.remove(self.data.players[event.player_index],index-n+1)
end
end
end
--- Adds a server thread that allows the camera follows to be toggled off and on --- Adds a server thread that allows the camera follows to be toggled off and on
return function(event) return function(event)
Server.new_thread{ Server.new_thread{
@@ -24,22 +39,5 @@ return function(event)
end end
end end
self.data.cam_index = self.data.cam_index+update self.data.cam_index = self.data.cam_index+update
end):on_event('error',function(self,err) end):on_event(defines.events.on_player_respawned,on_player_respawned):open()
-- posible error handling if needed
error(err)
end):on_event(defines.events.on_player_respawned,function(self,event)
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if self.data.players[event.player_index] then
local remove = {}
local player = Game.get_player(event)
for index,cam in pairs(self.data.players[event.player_index]) do
if cam.valid then table.insert(self.data.cams,{cam=cam,entity=player.character,surface=player.surface})
else table.insert(remove,index) end
end
for n,index in pairs(remove) do
table.remove(self.data.players[event.player_index],index-n+1)
end
end
end):open()
end end

View File

@@ -2,12 +2,9 @@ local Sync = Sync
local get_allowed_afk_time = self local get_allowed_afk_time = self
local Server = require('ExpGamingCore.Server@^4.0.0') local Server = require('ExpGamingCore.Server@^4.0.0')
Event[defines.events.on_tick] = nil Event[defines.events.on_tick] = nil
script.on_init(function(event)
Server.new_thread{ local function on_tick(self)
name='afk-kick', -- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
}:on_event('tick',function(self)
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if (game.tick%3600) ~= 0 then return end if (game.tick%3600) ~= 0 then return end
for _,player in pairs(game.connected_players) do for _,player in pairs(game.connected_players) do
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player) local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
@@ -15,9 +12,10 @@ script.on_init(function(event)
if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end
end end
end end
end):on_event('error',function(self,err) end
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end local function on_error(self,err)
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
if Sync then if Sync then
Sync.emit_embeded{ Sync.emit_embeded{
title='Auto Kick Error', title='Auto Kick Error',
@@ -27,5 +25,11 @@ script.on_init(function(event)
} }
end end
self:close() self:close()
end):open() end
script.on_init(function(event)
Server.new_thread{
name='afk-kick',
}:on_event('tick',on_tick):on_event('error',function(self,err)
):open()
end) end)