mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Made all functions non anon
This commit is contained in:
@@ -19,6 +19,42 @@ local ThisModule = {
|
||||
end
|
||||
}
|
||||
|
||||
local function on_marked_for_deconstruction(self,event)
|
||||
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
|
||||
local chache = self.data.chache[event.player_index]
|
||||
if not chache 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
|
||||
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
|
||||
end
|
||||
chache = self.data.chache[event.player_index]
|
||||
end
|
||||
if not event.entity.last_user or event.entity.name == 'entity-ghost' then
|
||||
if chache[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
|
||||
event.entity.cancel_deconstruction('player')
|
||||
if not chache[2] then
|
||||
chache[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)
|
||||
if Admin then Admin.give_warning(player,'<server>','Trying To Decon The Base') end
|
||||
end
|
||||
self.data.clear = game.tick + 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Event Handlers Define
|
||||
Event.register(-1,function(event)
|
||||
Server.new_thread{
|
||||
@@ -32,42 +68,7 @@ Event.register(-1,function(event)
|
||||
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]
|
||||
if not chache 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
|
||||
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
|
||||
end
|
||||
chache = self.data.chache[event.player_index]
|
||||
end
|
||||
if not event.entity.last_user or event.entity.name == 'entity-ghost' then
|
||||
if chache[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
|
||||
event.entity.cancel_deconstruction('player')
|
||||
if not chache[2] then
|
||||
chache[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)
|
||||
if Admin then Admin.give_warning(player,'<server>','Trying To Decon The Base') end
|
||||
end
|
||||
self.data.clear = game.tick + 10
|
||||
end
|
||||
end
|
||||
end):open()
|
||||
end):on_event(defines.events.on_marked_for_deconstruction,on_marked_for_deconstruction):open()
|
||||
end)
|
||||
|
||||
-- Module Return
|
||||
|
||||
@@ -24,6 +24,32 @@ local ThisModule = {
|
||||
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
|
||||
script.on_init(function(event)
|
||||
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.map-time',tick_to_display_format(game.tick)}}
|
||||
self.reopen = true
|
||||
end):on_event(defines.events.on_player_joined_game,function(self,event)
|
||||
-- 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):on_event(defines.events.on_player_joined_game,on_player_joined_game):on_event('error',on_error):open()
|
||||
end)
|
||||
|
||||
-- Module Return
|
||||
|
||||
@@ -85,14 +85,11 @@ function popup.open(style,data,players)
|
||||
else error('No Draw On Popup '.._popup.name) end
|
||||
end
|
||||
else
|
||||
Server.new_thread{
|
||||
data={players=players,popup=_popup,data=data}
|
||||
}:on_event('tick',function(thread)
|
||||
-- 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 #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 function on_tick(self)
|
||||
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
|
||||
if #self.data.players == 0 then self:close() return end
|
||||
local player = table.remove(self.data.players,1)
|
||||
if self.data.popup.left then self.data.popup.left:close(player) end
|
||||
local flow = popup.flow(player)
|
||||
flow.style.visible=true
|
||||
local _frame = flow.add{
|
||||
@@ -106,12 +103,15 @@ function popup.open(style,data,players)
|
||||
direction='vertical',
|
||||
style='image_frame'
|
||||
}
|
||||
thread.data.popup.close(_frame)
|
||||
if is_type(thread.data.popup.draw,'function') then
|
||||
local success, err = pcall(thread.data.popup.draw,frame,thread.data.data)
|
||||
self.data.popup.close(_frame)
|
||||
if is_type(self.data.popup.draw,'function') then
|
||||
local success, err = pcall(self.data.popup.draw,frame,self.data.data)
|
||||
if not success then error(err) end
|
||||
else error('No Draw On Popup '..thread.data.popup.name) end
|
||||
end):open()
|
||||
else error('No Draw On Popup '..self.data.popup.name) end
|
||||
end
|
||||
Server.new_thread{
|
||||
data={players=players,popup=_popup,data=data}
|
||||
}:on_event('tick',on_tick):open()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,6 +6,21 @@ local Server = require('ExpGamingCore.Server@^4.0.0')
|
||||
|
||||
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
|
||||
return function(event)
|
||||
Server.new_thread{
|
||||
@@ -24,22 +39,5 @@ return function(event)
|
||||
end
|
||||
end
|
||||
self.data.cam_index = self.data.cam_index+update
|
||||
end):on_event('error',function(self,err)
|
||||
-- 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):on_event(defines.events.on_player_respawned,on_player_respawned):open()
|
||||
end
|
||||
@@ -2,30 +2,34 @@ local Sync = Sync
|
||||
local get_allowed_afk_time = self
|
||||
local Server = require('ExpGamingCore.Server@^4.0.0')
|
||||
Event[defines.events.on_tick] = nil
|
||||
|
||||
local function on_tick(self)
|
||||
-- the _env should be auto loaded but does not, so to prevent desyncs it cant be an anon function
|
||||
if (game.tick%3600) ~= 0 then return end
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
|
||||
if afk then
|
||||
if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end
|
||||
end
|
||||
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 Kick Error',
|
||||
color=Color.to_hex(defines.textcolor.bg),
|
||||
description='Auto Kick Error - Closed Thread',
|
||||
Error=err
|
||||
}
|
||||
end
|
||||
self:close()
|
||||
end
|
||||
|
||||
script.on_init(function(event)
|
||||
Server.new_thread{
|
||||
name='afk-kick',
|
||||
}: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
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
|
||||
if afk then
|
||||
if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end
|
||||
end
|
||||
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 Kick Error',
|
||||
color=Color.to_hex(defines.textcolor.bg),
|
||||
description='Auto Kick Error - Closed Thread',
|
||||
Error=err
|
||||
}
|
||||
end
|
||||
self:close()
|
||||
end):open()
|
||||
}:on_event('tick',on_tick):on_event('error',function(self,err)
|
||||
):open()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user