mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Fixed _ENV
This commit is contained in:
@@ -34,10 +34,7 @@ Event.register(-1,function(event)
|
||||
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 reason
|
||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
||||
_ENV.Game = self._env.Game
|
||||
_ENV.Role = self._env.Role
|
||||
_ENV.Admin = self._env.Admin
|
||||
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||
local chache = self.data.chache[event.player_index]
|
||||
if not chache then
|
||||
local player = Game.get_player(event)
|
||||
|
||||
@@ -50,9 +50,7 @@ script.on_init(function(event)
|
||||
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 = _ENV or setmetatable({},{__index=_G})
|
||||
_ENV.Game = self._env.Game
|
||||
_ENV.Role = self._env.Role
|
||||
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
|
||||
@@ -65,8 +63,7 @@ script.on_init(function(event)
|
||||
end
|
||||
end):on_event('error',function(self,err)
|
||||
-- the _env should be auto loaded but it does not for some reason
|
||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
||||
_ENV.Sync = self._env.Sync
|
||||
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||
if Sync then Sync.emit_embeded{
|
||||
title='Auto Message Error',
|
||||
color=Color.to_hex(defines.textcolor.bg),
|
||||
|
||||
@@ -89,8 +89,7 @@ function popup.open(style,data,players)
|
||||
data={players=players,popup=_popup,data=data}
|
||||
}:on_event('tick',function(thread)
|
||||
-- the _env should be auto loaded but it does not for some reason
|
||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
||||
_ENV.popup = self._env.popup
|
||||
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||
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
|
||||
|
||||
@@ -29,8 +29,7 @@ return function(event)
|
||||
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 reason
|
||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
||||
_ENV.Game = self._env.Game
|
||||
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||
if self.data.players[event.player_index] then
|
||||
local remove = {}
|
||||
local player = Game.get_player(event)
|
||||
|
||||
@@ -264,7 +264,7 @@ end
|
||||
Server._thread = {}
|
||||
|
||||
local _env_metatable = {
|
||||
__index=function(tbl,key) if rawget(tbl,'_modules') and tbl._modules[key] then return require(tbl._modules[key]) end end
|
||||
__index=function(tbl,key) if rawget(tbl,'_modules') and tbl._modules[key] then return require(tbl._modules[key]) else return rawget(_G,key) end end
|
||||
}
|
||||
|
||||
--- Returns a new thread object
|
||||
@@ -280,6 +280,7 @@ function Server._thread:create(obj)
|
||||
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.setmetatable = setmetatable
|
||||
obj._env._modules = {}
|
||||
for name,value in pairs(obj._env) do if is_type(value,'table') and value._module_name and loaded_modules[value._module_name] == value then obj._env._modules[name] = value._module_name obj._env[name] = nil end end
|
||||
setmetatable(obj._env,_env_metatable)
|
||||
|
||||
@@ -7,8 +7,7 @@ script.on_init(function(event)
|
||||
name='afk-kick',
|
||||
}:on_event('tick',function(self)
|
||||
-- the _env should be auto loaded but it does not for some reason
|
||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
||||
_ENV.get_allowed_afk_time = self._env.get_allowed_afk_time
|
||||
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user