mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Fixed _ENV
This commit is contained in:
@@ -34,10 +34,7 @@ Event.register(-1,function(event)
|
|||||||
end
|
end
|
||||||
end):on_event(defines.events.on_marked_for_deconstruction,function(self,event)
|
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
|
-- the _env should be auto loaded but it does not for some reason
|
||||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||||
_ENV.Game = self._env.Game
|
|
||||||
_ENV.Role = self._env.Role
|
|
||||||
_ENV.Admin = self._env.Admin
|
|
||||||
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)
|
||||||
|
|||||||
@@ -50,9 +50,7 @@ script.on_init(function(event)
|
|||||||
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,function(self,event)
|
||||||
-- the _env should be auto loaded but it does not for some reason
|
-- the _env should be auto loaded but it does not for some reason
|
||||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||||
_ENV.Game = self._env.Game
|
|
||||||
_ENV.Role = self._env.Role
|
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
local data = self.data
|
local data = self.data
|
||||||
@@ -65,8 +63,7 @@ script.on_init(function(event)
|
|||||||
end
|
end
|
||||||
end):on_event('error',function(self,err)
|
end):on_event('error',function(self,err)
|
||||||
-- the _env should be auto loaded but it does not for some reason
|
-- the _env should be auto loaded but it does not for some reason
|
||||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||||
_ENV.Sync = self._env.Sync
|
|
||||||
if Sync then Sync.emit_embeded{
|
if Sync then Sync.emit_embeded{
|
||||||
title='Auto Message Error',
|
title='Auto Message Error',
|
||||||
color=Color.to_hex(defines.textcolor.bg),
|
color=Color.to_hex(defines.textcolor.bg),
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ function popup.open(style,data,players)
|
|||||||
data={players=players,popup=_popup,data=data}
|
data={players=players,popup=_popup,data=data}
|
||||||
}:on_event('tick',function(thread)
|
}:on_event('tick',function(thread)
|
||||||
-- the _env should be auto loaded but it does not for some reason
|
-- the _env should be auto loaded but it does not for some reason
|
||||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||||
_ENV.popup = self._env.popup
|
|
||||||
if #thread.data.players == 0 then thread:close() return end
|
if #thread.data.players == 0 then thread:close() return end
|
||||||
local player = table.remove(thread.data.players,1)
|
local player = table.remove(thread.data.players,1)
|
||||||
if thread.data.popup.left then thread.data.popup.left:close(player) end
|
if thread.data.popup.left then thread.data.popup.left:close(player) end
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ return function(event)
|
|||||||
error(err)
|
error(err)
|
||||||
end):on_event(defines.events.on_player_respawned,function(self,event)
|
end):on_event(defines.events.on_player_respawned,function(self,event)
|
||||||
-- the _env should be auto loaded but it does not for some reason
|
-- the _env should be auto loaded but it does not for some reason
|
||||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||||
_ENV.Game = self._env.Game
|
|
||||||
if self.data.players[event.player_index] then
|
if self.data.players[event.player_index] then
|
||||||
local remove = {}
|
local remove = {}
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ end
|
|||||||
Server._thread = {}
|
Server._thread = {}
|
||||||
|
|
||||||
local _env_metatable = {
|
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
|
--- Returns a new thread object
|
||||||
@@ -280,6 +280,7 @@ function Server._thread:create(obj)
|
|||||||
obj._env._env = true
|
obj._env._env = true
|
||||||
obj._env._ENV = nil -- provents infinte recusion
|
obj._env._ENV = nil -- provents infinte recusion
|
||||||
-- removes any modules from the _env to save space in global (less time to serizle)
|
-- removes any modules from the _env to save space in global (less time to serizle)
|
||||||
|
obj._env.setmetatable = setmetatable
|
||||||
obj._env._modules = {}
|
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
|
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)
|
setmetatable(obj._env,_env_metatable)
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ script.on_init(function(event)
|
|||||||
name='afk-kick',
|
name='afk-kick',
|
||||||
}:on_event('tick',function(self)
|
}:on_event('tick',function(self)
|
||||||
-- the _env should be auto loaded but it does not for some reason
|
-- the _env should be auto loaded but it does not for some reason
|
||||||
local _ENV = _ENV or setmetatable({},{__index=_G})
|
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
|
||||||
_ENV.get_allowed_afk_time = self._env.get_allowed_afk_time
|
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user