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

@@ -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