Changed events to use common format

This commit is contained in:
Cooldude2606
2019-06-14 16:00:48 +01:00
parent 3b5ccd997e
commit b13940b74c
11 changed files with 132 additions and 121 deletions

View File

@@ -92,13 +92,13 @@ Event.add(defines.events.on_player_created,function(event)
end) end)
--- When a player gets a new role they will have the toolbar updated --- When a player gets a new role they will have the toolbar updated
Event.add(Roles.player_role_assigned,function(event) Event.add(Roles.events.on_role_assigned,function(event)
local player = Game.get_player_by_index(event.player_index) local player = Game.get_player_by_index(event.player_index)
Toolbar.update(player) Toolbar.update(player)
end) end)
--- When a player loses a role they will have the toolbar updated --- When a player loses a role they will have the toolbar updated
Event.add(Roles.player_role_unassigned,function(event) Event.add(Roles.events.on_role_unassigned,function(event)
local player = Game.get_player_by_index(event.player_index) local player = Game.get_player_by_index(event.player_index)
Toolbar.update(player) Toolbar.update(player)
end) end)

View File

@@ -163,6 +163,7 @@ local Colours = require 'resources.color_presets'
local write_json = ext_require('expcore.common','write_json') local write_json = ext_require('expcore.common','write_json')
local Roles = { local Roles = {
_prototype={},
config={ config={
order={}, -- Contains the order of the roles, lower index is better order={}, -- Contains the order of the roles, lower index is better
roles={}, -- Contains the raw info for the roles, indexed by role name roles={}, -- Contains the raw info for the roles, indexed by role name
@@ -170,9 +171,10 @@ local Roles = {
internal={}, -- Contains all internally accessed roles, such as root, default internal={}, -- Contains all internally accessed roles, such as root, default
players={} players={}
}, },
player_role_assigned=script.generate_event_name(), events = {
player_role_unassigned=script.generate_event_name(), on_role_assigned=script.generate_event_name(),
_prototype={} on_role_unassigned=script.generate_event_name(),
}
} }
--- When global is loaded it will have the metatable re-assigned to the roles --- When global is loaded it will have the metatable re-assigned to the roles
@@ -195,9 +197,9 @@ local function emit_player_roles_updated(player,type,roles,by_player_name,skip_g
local by_player = Game.get_player_from_any(by_player_name) local by_player = Game.get_player_from_any(by_player_name)
local by_player_index = by_player and by_player.index or 0 local by_player_index = by_player and by_player.index or 0
-- get the event id from the type of emit -- get the event id from the type of emit
local event = Roles.player_role_assigned local event = Roles.events.on_role_assigned
if type == 'unassign' then if type == 'unassign' then
event = Roles.player_role_unassigned event = Roles.events.on_role_unassigned
end end
-- convert the roles to objects and get the names of the roles -- convert the roles to objects and get the names of the roles
local role_names = {} local role_names = {}
@@ -775,8 +777,8 @@ local function role_update(event)
end end
--- When a player joined or has a role change then the update is triggered --- When a player joined or has a role change then the update is triggered
Event.add(Roles.player_role_assigned,role_update) Event.add(Roles.events.on_role_assigned,role_update)
Event.add(Roles.player_role_unassigned,role_update) Event.add(Roles.events.on_role_unassigned,role_update)
Event.add(defines.events.on_player_joined_game,role_update) Event.add(defines.events.on_player_joined_game,role_update)
-- Every 60 seconds the auto promote check is preformed -- Every 60 seconds the auto promote check is preformed
Event.on_nth_tick(3600,function() Event.on_nth_tick(3600,function()

View File

@@ -79,8 +79,11 @@ local Store = {
registered={}, registered={},
synced={}, synced={},
callbacks={}, callbacks={},
events = {
on_value_update=script.generate_event_name() on_value_update=script.generate_event_name()
}
} }
Global.register(Store.data,function(tbl) Global.register(Store.data,function(tbl)
Store.data = tbl Store.data = tbl
end) end)
@@ -184,7 +187,7 @@ function Store.set(location,child,value,from_sync)
data[location] = value data[location] = value
end end
script.raise_event(Store.on_value_update,{ script.raise_event(Store.events.on_value_update,{
tick=game.tick, tick=game.tick,
location=location, location=location,
child=child, child=child,
@@ -215,7 +218,7 @@ function Store.clear(location,child,from_sync)
data[location] = nil data[location] = nil
end end
script.raise_event(Store.on_value_update,{ script.raise_event(Store.events.on_value_update,{
tick=game.tick, tick=game.tick,
location=location, location=location,
child=child, child=child,
@@ -235,7 +238,7 @@ function Store.get_children(location)
end end
-- Handels syncing -- Handels syncing
Event.add(Store.on_value_update,function(event) Event.add(Store.events.on_value_update,function(event)
if Store.callbacks[event.location] then if Store.callbacks[event.location] then
Store.callbacks[event.location](event.value,event.child) Store.callbacks[event.location](event.value,event.child)
end end

View File

@@ -77,7 +77,7 @@ end
--- Reports added and removed --- Reports added and removed
if config.player_reports then if config.player_reports then
local Reports = require 'modules.addons.reports-control' local Reports = require 'modules.addons.reports-control'
Event.add(Reports.player_report_added,function(event) Event.add(Reports.events.on_player_reported,function(event)
local player_name,by_player_name = get_player_name(event) local player_name,by_player_name = get_player_name(event)
emit_event{ emit_event{
title='Report', title='Report',
@@ -88,7 +88,7 @@ if config.player_reports then
['Reason:']=event.reason ['Reason:']=event.reason
} }
end) end)
Event.add(Reports.player_report_removed,function(event) Event.add(Reports.events.on_player_report_removed,function(event)
local player_name,by_player_name = get_player_name(event) local player_name,by_player_name = get_player_name(event)
emit_event{ emit_event{
title='Report Removed', title='Report Removed',
@@ -103,7 +103,7 @@ end
--- Warnings added and removed --- Warnings added and removed
if config.player_warnings then if config.player_warnings then
local Warnings = require 'modules.addons.warnings-control' local Warnings = require 'modules.addons.warnings-control'
Event.add(Warnings.player_warning_added,function(event) Event.add(Warnings.events.on_player_warned,function(event)
local player_name,by_player_name = get_player_name(event) local player_name,by_player_name = get_player_name(event)
emit_event{ emit_event{
title='Warning', title='Warning',
@@ -113,7 +113,7 @@ if config.player_warnings then
['By:']='<inline>'..by_player_name ['By:']='<inline>'..by_player_name
} }
end) end)
Event.add(Warnings.player_warning_removed,function(event) Event.add(Warnings.events.on_player_warning_removed,function(event)
local player_name,by_player_name = get_player_name(event) local player_name,by_player_name = get_player_name(event)
emit_event{ emit_event{
title='Warning Removed', title='Warning Removed',

View File

@@ -3,21 +3,23 @@ local Game = require 'utils.game'
local Global = require 'utils.global' local Global = require 'utils.global'
local move_items = ext_require('expcore.common','move_items') local move_items = ext_require('expcore.common','move_items')
local Public = { local Jail = {
old_roles = {}, old_roles = {},
temp_bans = {}, temp_bans = {},
player_jailed=script.generate_event_name(), events = {
player_unjailed=script.generate_event_name(), on_player_jailed=script.generate_event_name(),
player_temp_banned=script.generate_event_name(), on_player_unjailed=script.generate_event_name(),
player_clear_temp_ban=script.generate_event_name() on_player_temp_banned=script.generate_event_name(),
on_player_temp_ban_cleared=script.generate_event_name()
}
} }
Global.register({ Global.register({
old_roles = Public.old_roles, old_roles = Jail.old_roles,
temp_bans = Public.temp_bans temp_bans = Jail.temp_bans
},function(tbl) },function(tbl)
Public.old_roles = tbl.old_roles Jail.old_roles = tbl.old_roles
Public.temp_bans = tbl.temp_bans Jail.temp_bans = tbl.temp_bans
end) end)
local function event_emit(event,player,by_player_name,reason) local function event_emit(event,player,by_player_name,reason)
@@ -34,15 +36,15 @@ end
-- @tparam LuaPlayer player the player that will be jailed, must not be in jail -- @tparam LuaPlayer player the player that will be jailed, must not be in jail
-- @tparam[opt='<server>'] string by_player_name the name of the player doing the action used in logs -- @tparam[opt='<server>'] string by_player_name the name of the player doing the action used in logs
-- @treturn the number of roles that were removed, nil if there was an error -- @treturn the number of roles that were removed, nil if there was an error
function Public.jail_player(player,by_player_name) function Jail.jail_player(player,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
if Roles.player_has_role(player,'Jail') then return end if Roles.player_has_role(player,'Jail') then return end
local old_roles = Roles.get_player_roles(player) local old_roles = Roles.get_player_roles(player)
Public.old_roles[player.name] = old_roles Jail.old_roles[player.name] = old_roles
Roles.unassign_player(player,old_roles,by_player_name,true) Roles.unassign_player(player,old_roles,by_player_name,true)
Roles.assign_player(player,'Jail',by_player_name,true) Roles.assign_player(player,'Jail',by_player_name,true)
event_emit(Public.player_jailed,player,by_player_name) event_emit(Jail.events.on_player_jailed,player,by_player_name)
return #old_roles return #old_roles
end end
@@ -50,14 +52,14 @@ end
-- @tparam LuaPlayer player the player that will be unjailed, must be in jail -- @tparam LuaPlayer player the player that will be unjailed, must be in jail
-- @tparam[opt='<server>'] string string by_player_name the name of the player who is doing the action -- @tparam[opt='<server>'] string string by_player_name the name of the player who is doing the action
-- @treturn the number of roles that were added, nil if there was an error -- @treturn the number of roles that were added, nil if there was an error
function Public.unjail_player(player,by_player_name) function Jail.unjail_player(player,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
if not Roles.player_has_role(player,'Jail') then return end if not Roles.player_has_role(player,'Jail') then return end
local old_roles = Public.old_roles[player.name] local old_roles = Jail.old_roles[player.name]
Roles.unassign_player(player,'Jail',by_player_name,true) Roles.unassign_player(player,'Jail',by_player_name,true)
Roles.assign_player(player,old_roles,by_player_name,true) Roles.assign_player(player,old_roles,by_player_name,true)
event_emit(Public.player_unjailed,player,by_player_name) event_emit(Jail.events.on_player_unjailed,player,by_player_name)
return #old_roles return #old_roles
end end
@@ -66,17 +68,17 @@ end
-- @tparam[opt='<server>'] string by_player_name the name of the player that is doing the action -- @tparam[opt='<server>'] string by_player_name the name of the player that is doing the action
-- @tparam[opt='None string Given.'] reason the reason that will be stored for this temp ban -- @tparam[opt='None string Given.'] reason the reason that will be stored for this temp ban
-- @treturn boolean true if successful else will return nil -- @treturn boolean true if successful else will return nil
function Public.temp_ban_player(player,by_player_name,reason) function Jail.temp_ban_player(player,by_player_name,reason)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
reason = reason or 'None Given.' reason = reason or 'None Given.'
if not player then return end if not player then return end
if Public.temp_bans[player.name] then return end if Jail.temp_bans[player.name] then return end
Public.jail_player(player,by_player_name) Jail.jail_player(player,by_player_name)
Public.temp_bans[player.name] = {reason,by_player_name} Jail.temp_bans[player.name] = {reason,by_player_name}
local inv = player.get_main_inventory() local inv = player.get_main_inventory()
move_items(inv.get_contents()) move_items(inv.get_contents())
inv.clear() inv.clear()
event_emit(Public.player_temp_banned,player,by_player_name,reason) event_emit(Jail.events.on_player_temp_banned,player,by_player_name,reason)
return true return true
end end
@@ -84,14 +86,14 @@ end
-- @tparam LuaPlayer player the player that will be cleared from temp baned, must be temp banned -- @tparam LuaPlayer player the player that will be cleared from temp baned, must be temp banned
-- @tparam[opt='<server>'] string by_player_name the name of the player that is doing the action -- @tparam[opt='<server>'] string by_player_name the name of the player that is doing the action
-- @treturn boolean true if successful else will return nil -- @treturn boolean true if successful else will return nil
function Public.clear_temp_ban_player(player,by_player_name) function Jail.clear_temp_ban_player(player,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
if not Public.temp_bans[player.name] then return end if not Jail.temp_bans[player.name] then return end
Public.unjail_player(player,by_player_name) Jail.unjail_player(player,by_player_name)
Public.temp_bans[player.name] = nil Jail.temp_bans[player.name] = nil
event_emit(Public.player_clear_temp_ban,player,by_player_name) event_emit(Jail.events.on_player_temp_ban_cleared,player,by_player_name)
return true return true
end end
return Public return Jail

View File

@@ -1,18 +1,20 @@
local Game = require 'utils.game' local Game = require 'utils.game'
local Global = require 'utils.global' local Global = require 'utils.global'
local Public = { local Reports = {
user_reports={}, user_reports={},
player_report_added = script.generate_event_name(), events = {
player_report_removed = script.generate_event_name() on_player_reported = script.generate_event_name(),
on_player_report_removed = script.generate_event_name()
}
} }
Global.register(Public.user_reports,function(tbl) Global.register(Reports.user_reports,function(tbl)
Public.user_reports = tbl Reports.user_reports = tbl
end) end)
local function event_emit(event,player,by_player_name) local function event_emit(event,player,by_player_name)
local reports = Public.user_reports[player.name] local reports = Reports.user_reports[player.name]
local reason = reports and reports[by_player_name] local reason = reports and reports[by_player_name]
script.raise_event(event,{ script.raise_event(event,{
name=event, name=event,
@@ -28,20 +30,20 @@ end
-- @tparam[opt='Non string Given.'] reason the reason that the player is being reported -- @tparam[opt='Non string Given.'] reason the reason that the player is being reported
-- @tparam[opt='<server>'] string by_player_name the name of the player doing the action -- @tparam[opt='<server>'] string by_player_name the name of the player doing the action
-- @treturn boolean true if the report was added, nil if there is an error -- @treturn boolean true if the report was added, nil if there is an error
function Public.report_player(player,reason,by_player_name) function Reports.report_player(player,reason,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
reason = reason or 'Non Given.' reason = reason or 'Non Given.'
by_player_name = by_player_name or '<server>' by_player_name = by_player_name or '<server>'
local reports = Public.user_reports[player.name] local reports = Reports.user_reports[player.name]
if not reports then if not reports then
Public.user_reports[player.name] = { Reports.user_reports[player.name] = {
[by_player_name] = reason [by_player_name] = reason
} }
elseif not reports[by_player_name] then elseif not reports[by_player_name] then
reports[by_player_name] = reason reports[by_player_name] = reason
else return false end else return false end
event_emit(Public.player_report_added,player,by_player_name) event_emit(Reports.events.on_player_reported,player,by_player_name)
return true return true
end end
@@ -49,16 +51,16 @@ end
-- @tparam LuaPlayer player the player that will have the report removed -- @tparam LuaPlayer player the player that will have the report removed
-- @tparam[opt='<server>'] string by_player_name the name of the player doing the action -- @tparam[opt='<server>'] string by_player_name the name of the player doing the action
-- @treturn boolean true if the report was removed, nil if there was an error -- @treturn boolean true if the report was removed, nil if there was an error
function Public.remove_player_report(player,by_player_name) function Reports.remove_player_report(player,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
by_player_name = by_player_name or '<server>' by_player_name = by_player_name or '<server>'
local reports = Public.user_reports[player.name] local reports = Reports.user_reports[player.name]
if reports and reports[by_player_name] then if reports and reports[by_player_name] then
event_emit(Public.player_report_removed,player,by_player_name) event_emit(Reports.events.on_player_report_removed,player,by_player_name)
reports[by_player_name] = nil reports[by_player_name] = nil
if Public.count_player_reports(player) == 0 then if Reports.count_player_reports(player) == 0 then
Public.user_reports[player.name] = nil Reports.user_reports[player.name] = nil
end end
return true return true
end end
@@ -68,15 +70,15 @@ end
--- Clears all reports from a player, will emit an event for each individual report as if remove_player_report was used --- Clears all reports from a player, will emit an event for each individual report as if remove_player_report was used
-- @tparam LuaPlayer player the player to clear the reports of -- @tparam LuaPlayer player the player to clear the reports of
-- @treturn boolean true if the reports were cleared, nil if error -- @treturn boolean true if the reports were cleared, nil if error
function Public.clear_player_reports(player) function Reports.clear_player_reports(player)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local reports = Public.user_reports[player.name] local reports = Reports.user_reports[player.name]
if reports then if reports then
for by_player_name,reason in pairs(reports) do for by_player_name,reason in pairs(reports) do
event_emit(Public.player_report_removed,player,by_player_name) event_emit(Reports.events.on_player_report_removed,player,by_player_name)
end end
Public.user_reports[player.name] = nil Reports.user_reports[player.name] = nil
return true return true
end end
return false return false
@@ -87,10 +89,10 @@ end
-- @tparam string by_player_name the player that made if the report if present (note server is not default here) -- @tparam string by_player_name the player that made if the report if present (note server is not default here)
-- @tparam[opt=false] boolean rtn_reason true will return the reason for the report rather than a boolean -- @tparam[opt=false] boolean rtn_reason true will return the reason for the report rather than a boolean
-- @treturn boolean true if a report from the player is present unless rtn_reason is true when a string is returned (or false) -- @treturn boolean true if a report from the player is present unless rtn_reason is true when a string is returned (or false)
function Public.player_is_reported_by(player,by_player_name,rtn_reason) function Reports.player_is_reported_by(player,by_player_name,rtn_reason)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local reports = Public.user_reports[player.name] local reports = Reports.user_reports[player.name]
if reports and reports[by_player_name] then if reports and reports[by_player_name] then
return rtn_reason and reports[by_player_name] or true return rtn_reason and reports[by_player_name] or true
end end
@@ -100,10 +102,10 @@ end
--- Gets all the reports that are on a player --- Gets all the reports that are on a player
-- @tparam LuaPlayer player the player to get the reports of -- @tparam LuaPlayer player the player to get the reports of
-- @treturn table a table of all the reports for this player, empty table if no reports -- @treturn table a table of all the reports for this player, empty table if no reports
function Public.get_player_reports(player) function Reports.get_player_reports(player)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
return Public.user_reports[player.name] or {} return Reports.user_reports[player.name] or {}
end end
--- Counts all reports on a player returning a number, a custom count function can be given which should return a number --- Counts all reports on a player returning a number, a custom count function can be given which should return a number
@@ -113,10 +115,10 @@ end
-- count_callback param - reason string - the reason the reason was made -- count_callback param - reason string - the reason the reason was made
-- count_callback return - number or boolean - if number then this will be added to the count, if boolean then false = 0 and true = 1 -- count_callback return - number or boolean - if number then this will be added to the count, if boolean then false = 0 and true = 1
-- @treturn number the number of reports on the player -- @treturn number the number of reports on the player
function Public.count_player_reports(player,count_callback) function Reports.count_player_reports(player,count_callback)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local reports = Public.user_reports[player.name] or {} local reports = Reports.user_reports[player.name] or {}
if not count_callback then if not count_callback then
local ctn = 0 local ctn = 0
for _ in pairs(reports) do for _ in pairs(reports) do
@@ -136,4 +138,4 @@ function Public.count_player_reports(player,count_callback)
end end
end end
return Public return Reports

View File

@@ -5,26 +5,28 @@ local config = require 'config.warnings'
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') local format_chat_player_name = ext_require('expcore.common','format_chat_player_name')
require 'utils.table' require 'utils.table'
local Public = { local Warnings = {
user_warnings={}, user_warnings={},
user_temp_warnings={}, user_temp_warnings={},
player_warning_added = script.generate_event_name(), events = {
player_warning_removed = script.generate_event_name(), on_player_warned = script.generate_event_name(),
player_temp_warning_added = script.generate_event_name(), on_player_warning_removed = script.generate_event_name(),
player_temp_warning_removed = script.generate_event_name() on_temp_warning_added = script.generate_event_name(),
on_temp_warning_removed = script.generate_event_name(),
}
} }
Global.register({ Global.register({
user_warnings = Public.user_warnings, user_warnings = Warnings.user_warnings,
user_temp_warnings = Public.user_temp_warnings user_temp_warnings = Warnings.user_temp_warnings
},function(tbl) },function(tbl)
Public.user_warnings = tbl.user_warnings Warnings.user_warnings = tbl.user_warnings
Public.user_temp_warnings = tbl.user_temp_warnings Warnings.user_temp_warnings = tbl.user_temp_warnings
end) end)
local function event_emit(event,player,by_player_name) local function event_emit(event,player,by_player_name)
local warnings = Public.user_warnings[player.name] or {} local warnings = Warnings.user_warnings[player.name] or {}
local temp_warnings = Public.user_temp_warnings[player.name] or {} local temp_warnings = Warnings.user_temp_warnings[player.name] or {}
script.raise_event(event,{ script.raise_event(event,{
name=event, name=event,
tick=game.tick, tick=game.tick,
@@ -40,19 +42,19 @@ end
-- @tparam[opt='<server>'] string by_player_name the name of the player doing the action -- @tparam[opt='<server>'] string by_player_name the name of the player doing the action
-- @tparam[opt=1] number count the number of warnings to add -- @tparam[opt=1] number count the number of warnings to add
-- @treturn number the new number of warnings -- @treturn number the new number of warnings
function Public.add_warnings(player,by_player_name,count) function Warnings.add_warnings(player,by_player_name,count)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
count = count or 1 count = count or 1
by_player_name = by_player_name or '<server>' by_player_name = by_player_name or '<server>'
local warnings = Public.user_warnings[player.name] local warnings = Warnings.user_warnings[player.name]
if not warnings then if not warnings then
Public.user_warnings[player.name] = {} Warnings.user_warnings[player.name] = {}
warnings = Public.user_warnings[player.name] warnings = Warnings.user_warnings[player.name]
end end
for _=1,count do for _=1,count do
table.insert(warnings,by_player_name) table.insert(warnings,by_player_name)
event_emit(Public.player_warning_added,player,by_player_name) event_emit(Warnings.events.on_player_warned,player,by_player_name)
end end
return #warnings return #warnings
end end
@@ -62,20 +64,20 @@ end
-- @tparam[opt='<server>'] string by_playey_name the name of the player doing the action -- @tparam[opt='<server>'] string by_playey_name the name of the player doing the action
-- @tparam[opt=1] number count the number of warnings to remove (if greater than current warning count then all are removed) -- @tparam[opt=1] number count the number of warnings to remove (if greater than current warning count then all are removed)
-- @treturn number the new number of warnings -- @treturn number the new number of warnings
function Public.remove_warnings(player,by_player_name,count) function Warnings.remove_warnings(player,by_player_name,count)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
count = count or 1 count = count or 1
by_player_name = by_player_name or '<server>' by_player_name = by_player_name or '<server>'
local warnings = Public.user_warnings[player.name] local warnings = Warnings.user_warnings[player.name]
if not warnings then return end if not warnings then return end
for _=1,count do for _=1,count do
if #warnings == 0 then break end if #warnings == 0 then break end
table.remove(warnings,1) table.remove(warnings,1)
event_emit(Public.player_warning_removed,player,by_player_name) event_emit(Warnings.events.on_player_warning_removed,player,by_player_name)
end end
if #warnings == 0 then if #warnings == 0 then
Public.user_warnings[player.name] = nil Warnings.user_warnings[player.name] = nil
return 0 return 0
end end
return #warnings return #warnings
@@ -85,16 +87,16 @@ end
-- @tparam LuaPlayer player the player to clear the warnings of -- @tparam LuaPlayer player the player to clear the warnings of
-- @tparam[oot='<server>'] string by_player_name the name of the player who is doing the action -- @tparam[oot='<server>'] string by_player_name the name of the player who is doing the action
-- @treturn boolean true if the warnings were cleared, nil if error -- @treturn boolean true if the warnings were cleared, nil if error
function Public.clear_warnings(player,by_player_name) function Warnings.clear_warnings(player,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local warnings = Public.user_warnings[player.name] local warnings = Warnings.user_warnings[player.name]
if not warnings then return end if not warnings then return end
by_player_name = by_player_name or '<server>' by_player_name = by_player_name or '<server>'
for _=1,#warnings do for _=1,#warnings do
event_emit(Public.player_warning_removed,player,by_player_name) event_emit(Warnings.events.on_player_warning_removed,player,by_player_name)
end end
Public.user_warnings[player.name] = {} Warnings.user_warnings[player.name] = {}
return true return true
end end
@@ -102,10 +104,10 @@ end
-- @tparam LuaPlayer player the player to get the warnings of -- @tparam LuaPlayer player the player to get the warnings of
-- @tparam[opt=false] table table raw_table when true will return a which contains who gave warnings (the stored in global) -- @tparam[opt=false] table table raw_table when true will return a which contains who gave warnings (the stored in global)
-- @treturn number the number of warnings a player has, a table if raw_table is true -- @treturn number the number of warnings a player has, a table if raw_table is true
function Public.get_warnings(player,raw_table) function Warnings.get_warnings(player,raw_table)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local warnings = Public.user_warnings[player.name] or {} local warnings = Warnings.user_warnings[player.name] or {}
if raw_table then if raw_table then
return warnings return warnings
else else
@@ -117,18 +119,18 @@ end
-- @tparam LuaPlayer player the player to give the warnings to -- @tparam LuaPlayer player the player to give the warnings to
-- @tparam[opt=1] number count the number of warnings to give to the player -- @tparam[opt=1] number count the number of warnings to give to the player
-- @treturn number the new number of warnings -- @treturn number the new number of warnings
function Public.add_temp_warnings(player,count) function Warnings.add_temp_warnings(player,count)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
count = count or 1 count = count or 1
local warnings = Public.user_temp_warnings[player.name] local warnings = Warnings.user_temp_warnings[player.name]
if not warnings then if not warnings then
Public.user_temp_warnings[player.name] = {} Warnings.user_temp_warnings[player.name] = {}
warnings = Public.user_temp_warnings[player.name] warnings = Warnings.user_temp_warnings[player.name]
end end
for _=1,count do for _=1,count do
table.insert(warnings,game.tick) table.insert(warnings,game.tick)
event_emit(Public.player_temp_warning_added,player,'<server>') event_emit(Warnings.events.on_temp_warning_added,player,'<server>')
end end
return #warnings return #warnings
end end
@@ -137,17 +139,17 @@ end
local temp_warning_cool_down = config.temp_warning_cool_down*3600 local temp_warning_cool_down = config.temp_warning_cool_down*3600
Event.on_nth_tick(temp_warning_cool_down/4,function() Event.on_nth_tick(temp_warning_cool_down/4,function()
local check_time = game.tick-temp_warning_cool_down local check_time = game.tick-temp_warning_cool_down
for player_name,temp_warnings in pairs(Public.user_temp_warnings) do for player_name,temp_warnings in pairs(Warnings.user_temp_warnings) do
local player = Game.get_player_from_any(player) local player = Game.get_player_from_any(player)
for index,time in pairs(temp_warnings) do for index,time in pairs(temp_warnings) do
if time <= check_time then if time <= check_time then
table.remove(temp_warnings,index) table.remove(temp_warnings,index)
player.print{'warnings.script-warning-removed',#temp_warnings,config.temp_warning_limit} player.print{'warnings.script-warning-removed',#temp_warnings,config.temp_warning_limit}
event_emit(Public.player_temp_warning_removed,player,'<server>') event_emit(Warnings.events.on_temp_warning_removed,player,'<server>')
end end
end end
if #temp_warnings == 0 then if #temp_warnings == 0 then
Public.user_temp_warnings[player_name] = nil Warnings.user_temp_warnings[player_name] = nil
end end
end end
end) end)
@@ -156,16 +158,16 @@ end)
-- @tparam LuaPlayer player the player to clear the warnings of -- @tparam LuaPlayer player the player to clear the warnings of
-- @tparam[opt='<server>'] string by_player_name the name of the player doing the action -- @tparam[opt='<server>'] string by_player_name the name of the player doing the action
-- @treturn boolean true if the warnings were cleared, nil for error -- @treturn boolean true if the warnings were cleared, nil for error
function Public.clear_temp_warnings(player,by_player_name) function Warnings.clear_temp_warnings(player,by_player_name)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local warnings = Public.user_temp_warnings[player.name] local warnings = Warnings.user_temp_warnings[player.name]
if not warnings then return end if not warnings then return end
by_player_name = by_player_name or '<server>' by_player_name = by_player_name or '<server>'
for _=1,#warnings do for _=1,#warnings do
event_emit(Public.player_temp_warning_removed,player,by_player_name) event_emit(Warnings.events.on_temp_warning_removed,player,by_player_name)
end end
Public.user_temp_warnings[player.name] = {} Warnings.user_temp_warnings[player.name] = {}
return true return true
end end
@@ -173,10 +175,10 @@ end
-- @tparam LuaPlayer player the player to get the warnings of -- @tparam LuaPlayer player the player to get the warnings of
-- @tparam[opt=false] table raw_table if true will return a of ticks when warnings were added (the global table) -- @tparam[opt=false] table raw_table if true will return a of ticks when warnings were added (the global table)
-- @treturn number the number of warnings which the player has, a table if raw_table is true -- @treturn number the number of warnings which the player has, a table if raw_table is true
function Public.get_temp_warnings(player,raw_table) function Warnings.get_temp_warnings(player,raw_table)
player = Game.get_player_from_any(player) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local warnings = Public.user_temp_warnings[player.name] or {} local warnings = Warnings.user_temp_warnings[player.name] or {}
if raw_table then if raw_table then
return warnings return warnings
else else
@@ -185,7 +187,7 @@ function Public.get_temp_warnings(player,raw_table)
end end
-- when a player gets a warning the actions in config are ran -- when a player gets a warning the actions in config are ran
Event.add(Public.player_warning_added,function(event) Event.add(Warnings.events.on_player_warned,function(event)
local action = config.actions[event.warning_count] local action = config.actions[event.warning_count]
if not action then return end if not action then return end
local player = Game.get_player_by_index(event.player_index) local player = Game.get_player_by_index(event.player_index)
@@ -205,10 +207,10 @@ Event.add(Public.player_warning_added,function(event)
end) end)
-- when a player gets a tempo warnings it is checked that it is not above the max -- when a player gets a tempo warnings it is checked that it is not above the max
Event.add(Public.player_temp_warning_added,function(event) Event.add(Warnings.events.on_temp_warning_added,function(event)
local player = Game.get_player_by_index(event.player_index) local player = Game.get_player_by_index(event.player_index)
if event.temp_warning_count > config.temp_warning_limit then if event.temp_warning_count > config.temp_warning_limit then
Public.add_warnings(event.player_index,event.by_player_name) Warnings.add_warnings(event.player_index,event.by_player_name)
local player_name_color = format_chat_player_name(player) local player_name_color = format_chat_player_name(player)
game.print{'warnings.script-warning-limit',player_name_color} game.print{'warnings.script-warning-limit',player_name_color}
else else
@@ -216,4 +218,4 @@ Event.add(Public.player_temp_warning_added,function(event)
end end
end) end)
return Public return Warnings

View File

@@ -56,5 +56,5 @@ local function role_update(event)
end end
end end
Event.add(Roles.player_role_assigned,role_update) Event.add(Roles.events.on_role_assigned,role_update)
Event.add(Roles.player_role_unassigned,role_update) Event.add(Roles.events.on_role_unassigned,role_update)

View File

@@ -378,7 +378,7 @@ end)
Event.on_nth_tick(1800,player_list 'update_all') Event.on_nth_tick(1800,player_list 'update_all')
Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') Event.add(defines.events.on_player_joined_game,player_list 'redraw_all')
Event.add(defines.events.on_player_left_game,player_list 'redraw_all') Event.add(defines.events.on_player_left_game,player_list 'redraw_all')
Event.add(Roles.player_role_assigned,player_list 'redraw_all') Event.add(Roles.events.on_role_assigned,player_list 'redraw_all')
Event.add(Roles.player_role_unassigned,player_list 'redraw_all') Event.add(Roles.events.on_role_unassigned,player_list 'redraw_all')
return player_list return player_list

View File

@@ -631,7 +631,7 @@ Event.on_nth_tick(150,function()
end) end)
--- Makes sure the right buttons are present when role changes --- Makes sure the right buttons are present when role changes
Event.add(Roles.player_role_assigned,rocket_info 'redraw') Event.add(Roles.events.on_role_assigned,rocket_info 'redraw')
Event.add(Roles.player_role_unassigned,rocket_info 'redraw') Event.add(Roles.events.on_role_unassigned,rocket_info 'redraw')
return rocket_info return rocket_info

View File

@@ -415,7 +415,7 @@ Store.register(task_store,function(value,task_id)
end) end)
--- Makess sure the right buttons are present when roles change --- Makess sure the right buttons are present when roles change
Event.add(Roles.player_role_assigned,task_list 'redraw') Event.add(Roles.events.on_role_assigned,task_list 'redraw')
Event.add(Roles.player_role_unassigned,task_list 'redraw') Event.add(Roles.events.on_role_unassigned,task_list 'redraw')
return task_list return task_list