mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Fixed Existing Lua Check Errors
This commit is contained in:
@@ -9,15 +9,15 @@
|
||||
|
||||
-- This will move 'MrBiter' to the jail role and remove all other roles from them
|
||||
-- the player name and reason are only so they can be included in the event for user feedback
|
||||
Jail.jail_player('MrBiter','Cooldude2606','Likes biters too much')
|
||||
Jail.jail_player('MrBiter', 'Cooldude2606', 'Likes biters too much')
|
||||
|
||||
-- This will give 'MrBiter' all his roles back and remove him from jail
|
||||
-- again as above the player name is only used in the event for user feedback
|
||||
Jail.unjail_player('MrBiter','Cooldude2606')
|
||||
Jail.unjail_player('MrBiter', 'Cooldude2606')
|
||||
|
||||
-- Temp ban works the same as jail but will store the reason and move the players items to spawn
|
||||
-- this is meant to be used as a more permiment jail but not as strong as a ban
|
||||
Jail.temp_ban_player('MrBiter','Cooldude2606','Likes biters too much')
|
||||
Jail.temp_ban_player('MrBiter', 'Cooldude2606', 'Likes biters too much')
|
||||
]]
|
||||
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
@@ -65,7 +65,7 @@ local temp_bans = Jail.temp_bans
|
||||
Global.register({
|
||||
old_roles = old_roles,
|
||||
temp_bans = temp_bans
|
||||
},function(tbl)
|
||||
}, function(tbl)
|
||||
Jail.old_roles = tbl.old_roles
|
||||
Jail.temp_bans = tbl.temp_bans
|
||||
old_roles = Jail.old_roles
|
||||
@@ -77,8 +77,8 @@ end)
|
||||
-- @tparam LuaPlayer player the player who is being acted on
|
||||
-- @tparam string by_player_name the player who is doing the action
|
||||
-- @tparam string reason the reason for the action (jail and tempban only)
|
||||
local function event_emit(event,player,by_player_name,reason)
|
||||
script.raise_event(event,{
|
||||
local function event_emit(event, player, by_player_name, reason)
|
||||
script.raise_event(event, {
|
||||
name=event,
|
||||
tick=game.tick,
|
||||
player_index=player.index,
|
||||
@@ -95,7 +95,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to check if they are in jail
|
||||
-- @treturn boolean whether the player is currently in jail
|
||||
function Jail.is_jailed(player)
|
||||
return has_role(player,'Jail')
|
||||
return has_role(player, 'Jail')
|
||||
end
|
||||
|
||||
--- Moves a player to jail and removes all other roles
|
||||
@@ -103,14 +103,14 @@ end
|
||||
-- @tparam string by_player_name the name of the player who is doing the jailing
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being jailed
|
||||
-- @treturn boolean wheather the user was jailed successfully
|
||||
function Jail.jail_player(player,by_player_name,reason)
|
||||
function Jail.jail_player(player, by_player_name, reason)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
|
||||
reason = reason or 'Non given.'
|
||||
|
||||
if has_role(player,'Jail') then return end
|
||||
if has_role(player, 'Jail') then return end
|
||||
local roles = get_roles(player)
|
||||
old_roles[player.name] = roles
|
||||
|
||||
@@ -126,12 +126,12 @@ end
|
||||
-- @tparam LuaPlayer player the player that will be unjailed
|
||||
-- @tparam string by_player_name the name of the player that is doing the unjail
|
||||
-- @treturn boolean whether the player was unjailed successfully
|
||||
function Jail.unjail_player(player,by_player_name)
|
||||
function Jail.unjail_player(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
|
||||
if not has_role(player,'Jail') then return end
|
||||
if not has_role(player, 'Jail') then return end
|
||||
local roles = old_roles[player.name] or {}
|
||||
|
||||
assign_roles(player, roles, by_player_name, nil, true)
|
||||
@@ -160,7 +160,7 @@ end
|
||||
-- @tparam string by_player_name the name of the player who is doing the temp ban
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being temp banned
|
||||
-- @treturn boolean whether the player was successfully temp banned
|
||||
function Jail.temp_ban_player(player,by_player_name,reason)
|
||||
function Jail.temp_ban_player(player, by_player_name, reason)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
@@ -168,9 +168,9 @@ function Jail.temp_ban_player(player,by_player_name,reason)
|
||||
reason = reason or 'Non given.'
|
||||
|
||||
if temp_bans[player.name] then return end
|
||||
temp_bans[player.name] = {reason,by_player_name}
|
||||
temp_bans[player.name] = {reason, by_player_name}
|
||||
|
||||
if not has_role(player,'Jail') then
|
||||
if not has_role(player, 'Jail') then
|
||||
local roles = get_roles(player)
|
||||
old_roles[player.name] = roles
|
||||
|
||||
@@ -182,7 +182,7 @@ function Jail.temp_ban_player(player,by_player_name,reason)
|
||||
move_items(inv.get_contents())
|
||||
inv.clear()
|
||||
|
||||
event_emit(Jail.events.on_player_temp_banned,player,by_player_name,reason)
|
||||
event_emit(Jail.events.on_player_temp_banned, player, by_player_name, reason)
|
||||
|
||||
return true
|
||||
end
|
||||
@@ -191,7 +191,7 @@ end
|
||||
-- @tparam LuaPlayer player the player who is being removed from temp ban
|
||||
-- @tparam string by_player_name the name of the player who is doing the untemp ban
|
||||
-- @treturn boolean whether the player was successfully removed
|
||||
function Jail.untemp_ban_player(player,by_player_name)
|
||||
function Jail.untemp_ban_player(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
@@ -199,14 +199,14 @@ function Jail.untemp_ban_player(player,by_player_name)
|
||||
if not temp_bans[player.name] then return end
|
||||
temp_bans[player.name] = nil
|
||||
|
||||
if has_role(player,'Jail') then
|
||||
if has_role(player, 'Jail') then
|
||||
local roles = old_roles[player.name]
|
||||
|
||||
assign_roles(player, roles, by_player_name, nil, true)
|
||||
unassign_roles(player, 'Jail', by_player_name, nil, true)
|
||||
end
|
||||
|
||||
event_emit(Jail.events.on_player_untemp_banned,player,by_player_name)
|
||||
event_emit(Jail.events.on_player_untemp_banned, player, by_player_name)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -14,21 +14,21 @@
|
||||
|
||||
-- The get production function is used to get production, consumion and net
|
||||
-- it may be used for any item and with any precision level, use total for total
|
||||
Production.get_production(game.forces.player,'iron-plate',defines.flow_precision_index.one_minute)
|
||||
Production.get_production(game.forces.player, 'iron-plate', defines.flow_precision_index.one_minute)
|
||||
|
||||
-- The fluctuations works by compearing recent production with the average over time
|
||||
-- again any precision may be used, apart from one_thousand_hours as there would be no valid average
|
||||
Production.get_fluctuations(game.forces.player,'iron-plate',defines.flow_precision_index.one_minute)
|
||||
Production.get_fluctuations(game.forces.player, 'iron-plate', defines.flow_precision_index.one_minute)
|
||||
|
||||
-- ETA is calculated based on what function you use but all share a similar method
|
||||
-- for production eta it will take current production average given by the precision
|
||||
-- and work out how many ticks it will require to make the required amount (1000 by default)
|
||||
Production.get_production_eta(game.forces.player,'iron-plate',defines.flow_precision_index.one_minute,250000)
|
||||
Production.get_production_eta(game.forces.player, 'iron-plate', defines.flow_precision_index.one_minute, 250000)
|
||||
|
||||
-- Both get_color and format_number are helper functions to help format production stats
|
||||
-- get_color will return green,orange,red,or grey based on the active_value
|
||||
-- the passive_value is used when active_value is 0 and can only return orange,red,or grey
|
||||
Production.get_color(clamp,active_value,passive_value)
|
||||
-- get_color will return green, orange, red, or grey based on the active_value
|
||||
-- the passive_value is used when active_value is 0 and can only return orange, red, or grey
|
||||
Production.get_color(clamp, active_value, passive_value)
|
||||
|
||||
]]
|
||||
|
||||
@@ -47,13 +47,13 @@ local Production = {}
|
||||
-- @treturn[1] defines.flow_precision_index the next precision value
|
||||
-- @treturn[1] number the multiplicive difference between the values
|
||||
function Production.precision_up(precision)
|
||||
if precision == precision_index.one_second then return precision_index.one_minute,60
|
||||
elseif precision == precision_index.one_minute then return precision_index.ten_minutes,10
|
||||
elseif precision == precision_index.ten_minutes then return precision_index.one_hour,6
|
||||
elseif precision == precision_index.one_hour then return precision_index.ten_hours,10
|
||||
elseif precision == precision_index.ten_hours then return precision_index.fifty_hours,5
|
||||
elseif precision == precision_index.fifty_hours then return precision_index.two_hundred_fifty_hours,5
|
||||
elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.one_thousand_hours,4
|
||||
if precision == precision_index.one_second then return precision_index.one_minute, 60
|
||||
elseif precision == precision_index.one_minute then return precision_index.ten_minutes, 10
|
||||
elseif precision == precision_index.ten_minutes then return precision_index.one_hour, 6
|
||||
elseif precision == precision_index.one_hour then return precision_index.ten_hours, 10
|
||||
elseif precision == precision_index.ten_hours then return precision_index.fifty_hours, 5
|
||||
elseif precision == precision_index.fifty_hours then return precision_index.two_hundred_fifty_hours, 5
|
||||
elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.one_thousand_hours, 4
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,13 +62,13 @@ end
|
||||
-- @treturn[1] defines.flow_precision_index the next precision value
|
||||
-- @treturn[1] number the multiplicive difference between the values
|
||||
function Production.precision_down(precision)
|
||||
if precision == precision_index.one_minute then return precision_index.one_second,60
|
||||
elseif precision == precision_index.ten_minutes then return precision_index.one_minute,10
|
||||
elseif precision == precision_index.one_hour then return precision_index.ten_minutes,6
|
||||
elseif precision == precision_index.ten_hours then return precision_index.one_hour,10
|
||||
elseif precision == precision_index.fifty_hours then return precision_index.ten_hours,5
|
||||
elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.fifty_hours,5
|
||||
elseif precision == precision_index.one_thousand_hours then return precision_index.two_hundred_fifty_hours,4
|
||||
if precision == precision_index.one_minute then return precision_index.one_second, 60
|
||||
elseif precision == precision_index.ten_minutes then return precision_index.one_minute, 10
|
||||
elseif precision == precision_index.one_hour then return precision_index.ten_minutes, 6
|
||||
elseif precision == precision_index.ten_hours then return precision_index.one_hour, 10
|
||||
elseif precision == precision_index.fifty_hours then return precision_index.ten_hours, 5
|
||||
elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.fifty_hours, 5
|
||||
elseif precision == precision_index.one_thousand_hours then return precision_index.two_hundred_fifty_hours, 4
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,7 +95,7 @@ end
|
||||
-- @tparam LuaForce force the force to get the data for
|
||||
-- @tparam string item_name the name of the item that you want the data about
|
||||
-- @treturn table contains total made, used and net
|
||||
function Production.get_production_total(force,item_name)
|
||||
function Production.get_production_total(force, item_name)
|
||||
local stats = force.item_production_statistics
|
||||
local made = stats.get_input_count(item_name) or 0
|
||||
local used = stats.get_output_count(item_name) or 0
|
||||
@@ -113,10 +113,10 @@ end
|
||||
-- @tparam string item_name the name of the item that you want the data about
|
||||
-- @tparam defines.flow_precision_index precision the precision that you want the data given to
|
||||
-- @treturn table contains made, used and net
|
||||
function Production.get_production(force,item_name,precision)
|
||||
function Production.get_production(force, item_name, precision)
|
||||
local stats = force.item_production_statistics.get_flow_count
|
||||
local made = stats{name=item_name,input=true,precision_index=precision} or 0
|
||||
local used = stats{name=item_name,input=false,precision_index=precision} or 0
|
||||
local made = stats{name=item_name, input=true, precision_index=precision} or 0
|
||||
local used = stats{name=item_name, input=false, precision_index=precision} or 0
|
||||
|
||||
return {
|
||||
made=made,
|
||||
@@ -131,10 +131,10 @@ end
|
||||
-- @tparam string item_name the name of the item that you want the data about
|
||||
-- @tparam defines.flow_precision_index precision the precision that you want the data given to
|
||||
-- @treturn table contains made, used and net
|
||||
function Production.get_fluctuations(force,item_name,precision)
|
||||
function Production.get_fluctuations(force, item_name, precision)
|
||||
local percision_up = Production.precision_up(precision)
|
||||
local current = Production.get_production(force,item_name,precision)
|
||||
local previous = Production.get_production(force,item_name,percision_up)
|
||||
local current = Production.get_production(force, item_name, precision)
|
||||
local previous = Production.get_production(force, item_name, percision_up)
|
||||
|
||||
return {
|
||||
made=(current.made/previous.made)-1,
|
||||
@@ -150,10 +150,10 @@ end
|
||||
-- @tparam defines.flow_precision_index precision the precision that you want the data given to
|
||||
-- @tparam[opt=1000] number required the number of items that are required to be made
|
||||
-- @treturn number the number of ticks required to produce this ammount of items
|
||||
function Production.get_production_eta(force,item_name,precision,required)
|
||||
function Production.get_production_eta(force, item_name, precision, required)
|
||||
required = required or 1000
|
||||
local ticks = Production.precision_ticks(precision)
|
||||
local production = Production.get_production(force,item_name,precision)
|
||||
local production = Production.get_production(force, item_name, precision)
|
||||
return production.made == 0 and -1 or ticks*required/production.made
|
||||
end
|
||||
|
||||
@@ -163,10 +163,10 @@ end
|
||||
-- @tparam defines.flow_precision_index precision the precision that you want the data given to
|
||||
-- @tparam[opt=1000] number required the number of items that are required to be consumed
|
||||
-- @treturn number the number of ticks required to consume this ammount of items
|
||||
function Production.get_consumsion_eta(force,item_name,precision,required)
|
||||
function Production.get_consumsion_eta(force, item_name, precision, required)
|
||||
required = required or 1000
|
||||
local ticks = Production.precision_ticks(precision)
|
||||
local production = Production.get_production(force,item_name,precision)
|
||||
local production = Production.get_production(force, item_name, precision)
|
||||
return production.used == 0 and -1 or ticks*required/production.used
|
||||
end
|
||||
|
||||
@@ -176,10 +176,10 @@ end
|
||||
-- @tparam defines.flow_precision_index precision the precision that you want the data given to
|
||||
-- @tparam[opt=1000] number required the number of items that are required to be made but not used
|
||||
-- @treturn number the number of ticks required to produce, but not use, this ammount of items
|
||||
function Production.get_net_eta(force,item_name,precision,required)
|
||||
function Production.get_net_eta(force, item_name, precision, required)
|
||||
required = required or 1000
|
||||
local ticks = Production.precision_ticks(precision)
|
||||
local production = Production.get_production(force,item_name,precision)
|
||||
local production = Production.get_production(force, item_name, precision)
|
||||
return production.net == 0 and -1 or ticks*required/production.net
|
||||
end
|
||||
|
||||
@@ -191,8 +191,8 @@ end
|
||||
-- @tparam number clamp value which seperates the different colours
|
||||
-- @tparam number active_value first value tested, tested against clamp
|
||||
-- @tparam number passive_value second value tested, tested against 0
|
||||
-- @treturn table contains r,g,b keys
|
||||
function Production.get_color(clamp,active_value,passive_value)
|
||||
-- @treturn table contains r, g,b keys
|
||||
function Production.get_color(clamp, active_value, passive_value)
|
||||
if active_value > clamp then
|
||||
return Colors.light_green
|
||||
elseif active_value < -clamp then
|
||||
@@ -213,19 +213,19 @@ end
|
||||
-- @treturn[1] string the sign for the number
|
||||
-- @treturn[1] string the surfix for any unit used
|
||||
function Production.format_number(value)
|
||||
local rtn = format_number(math.round(value,1),true)
|
||||
local rtn = format_number(math.round(value, 1), true)
|
||||
local surfix = rtn:sub(-1)
|
||||
|
||||
if value > 0 then
|
||||
rtn = '+'..rtn
|
||||
elseif value == 0 and rtn:sub(1,1) == '-' then
|
||||
elseif value == 0 and rtn:sub(1, 1) == '-' then
|
||||
rtn = rtn:sub(2)
|
||||
end
|
||||
|
||||
if not tonumber(surfix) then
|
||||
return surfix,rtn:sub(1,-2)
|
||||
return surfix, rtn:sub(1, -2)
|
||||
else
|
||||
return '',rtn
|
||||
return '', rtn
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
-- This will place a report on "MrBiter" (must be a valid player) the report will have been made
|
||||
-- by "Cooldude2606" (must be the player name) with the reason 'Liking biters too much' this can be
|
||||
-- seen by using Reports.get_report.
|
||||
Reports.report_player('MrBiter','Cooldude2606','Liking biters too much') -- true
|
||||
Reports.report_player('MrBiter', 'Cooldude2606', 'Liking biters too much') -- true
|
||||
|
||||
-- The other get methods can be used to get all the reports on a player or to test if a player is reported.
|
||||
Reports.get_report('MrBiter','Cooldude2606') -- 'Liking biters too much'
|
||||
Reports.get_report('MrBiter', 'Cooldude2606') -- 'Liking biters too much'
|
||||
|
||||
-- This will remove the warning on 'MrBiter' (must be a valid player) which was made by 'Cooldude2606'.
|
||||
Reports.remove_report('MrBiter','Cooldude2606') -- true
|
||||
Reports.remove_report('MrBiter', 'Cooldude2606') -- true
|
||||
|
||||
-- This will remove all the report that have been made against 'MrBiter'. Note that the remove event will
|
||||
-- be triggered once per report issused.
|
||||
@@ -48,7 +48,7 @@ local Reports = {
|
||||
}
|
||||
|
||||
local user_reports = Reports.user_reports
|
||||
Global.register(user_reports,function(tbl)
|
||||
Global.register(user_reports, function(tbl)
|
||||
Reports.user_reports = tbl
|
||||
user_reports = Reports.user_reports
|
||||
end)
|
||||
@@ -71,7 +71,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to get the report for
|
||||
-- @tparam string by_player_name the name of the player who made the report
|
||||
-- @treturn ?string|nil string is the reason that the player was reported, if the player is not reported
|
||||
function Reports.get_report(player,by_player_name)
|
||||
function Reports.get_report(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
@@ -84,7 +84,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to check if reported
|
||||
-- @tparam[opt] string by_player_name when given will check if reported by this player
|
||||
-- @treturn boolean if the player has been reported
|
||||
function Reports.is_reported(player,by_player_name)
|
||||
function Reports.is_reported(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
|
||||
@@ -100,15 +100,15 @@ end
|
||||
-- @tparam LuaPlayer player the player to count the reports for
|
||||
-- @tparam[opt] function custom_count when given this function will be used to count the reports
|
||||
-- @treturn number the number of reports that the user has
|
||||
function Reports.count_reports(player,custom_count)
|
||||
function Reports.count_reports(player, custom_count)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
|
||||
local reports = user_reports[player.name] or {}
|
||||
if custom_count then
|
||||
local ctn = 0
|
||||
for by_player_name,reason in pairs(reports) do
|
||||
ctn = ctn + custom_count(player,by_player_name,reason)
|
||||
for by_player_name, reason in pairs(reports) do
|
||||
ctn = ctn + custom_count(player, by_player_name, reason)
|
||||
end
|
||||
return ctn
|
||||
else
|
||||
@@ -125,7 +125,7 @@ end
|
||||
-- @tparam string by_player_name the name of the player that is making the report
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being reported
|
||||
-- @treturn boolean whether the report was added successfully
|
||||
function Reports.report_player(player,by_player_name,reason)
|
||||
function Reports.report_player(player, by_player_name, reason)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
local player_name = player.name
|
||||
@@ -144,7 +144,7 @@ function Reports.report_player(player,by_player_name,reason)
|
||||
reports[by_player_name] = reason
|
||||
end
|
||||
|
||||
script.raise_event(Reports.events.on_player_reported,{
|
||||
script.raise_event(Reports.events.on_player_reported, {
|
||||
name = Reports.events.on_player_reported,
|
||||
tick = game.tick,
|
||||
player_index = player.index,
|
||||
@@ -159,8 +159,8 @@ end
|
||||
-- @tparam LuaPlayer player the player who is having the report removed from them
|
||||
-- @tparam string reported_by_name the player who had the report
|
||||
-- @tparam string removed_by_name the player who is clearing the report
|
||||
local function report_removed_event(player,reported_by_name,removed_by_name)
|
||||
script.raise_event(Reports.events.on_report_removed,{
|
||||
local function report_removed_event(player, reported_by_name, removed_by_name)
|
||||
script.raise_event(Reports.events.on_report_removed, {
|
||||
name = Reports.events.on_report_removed,
|
||||
tick = game.tick,
|
||||
player_index = player.index,
|
||||
@@ -174,7 +174,7 @@ end
|
||||
-- @tparam string reported_by_name the name of the player that made the report
|
||||
-- @tparam string removed_by_name the name of the player who removed the report
|
||||
-- @treturn boolean whether the report was removed successfully
|
||||
function Reports.remove_report(player,reported_by_name,removed_by_name)
|
||||
function Reports.remove_report(player, reported_by_name, removed_by_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
|
||||
@@ -188,7 +188,7 @@ function Reports.remove_report(player,reported_by_name,removed_by_name)
|
||||
return false
|
||||
end
|
||||
|
||||
report_removed_event(player,reported_by_name,removed_by_name)
|
||||
report_removed_event(player, reported_by_name, removed_by_name)
|
||||
|
||||
reports[reported_by_name] = nil
|
||||
return true
|
||||
@@ -198,7 +198,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to remove the reports from
|
||||
-- @tparam string removed_by_name the name of the player who removed the report
|
||||
-- @treturn boolean whether the reports were removed successfully
|
||||
function Reports.remove_all(player,removed_by_name)
|
||||
function Reports.remove_all(player, removed_by_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
|
||||
@@ -207,8 +207,8 @@ function Reports.remove_all(player,removed_by_name)
|
||||
return false
|
||||
end
|
||||
|
||||
for reported_by_name,_ in pairs(reports) do
|
||||
report_removed_event(player,reported_by_name,removed_by_name)
|
||||
for reported_by_name, _ in pairs(reports) do
|
||||
report_removed_event(player, reported_by_name, removed_by_name)
|
||||
end
|
||||
|
||||
user_reports[player.name] = nil
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
Rockets.get_silos('player')
|
||||
|
||||
-- You can get the launch time for a rocket, meaning what game tick the 50th rocket was launched
|
||||
Rockets.get_rocket_time('player',50)
|
||||
Rockets.get_rocket_time('player', 50)
|
||||
|
||||
-- The rolling average will work out the time to launch one rocket based on the last X rockets
|
||||
Rockets.get_rolling_average('player',10)
|
||||
Rockets.get_rolling_average('player', 10)
|
||||
|
||||
]]
|
||||
|
||||
@@ -30,7 +30,7 @@ local Global = require 'utils.global' --- @dep utils.global
|
||||
local config = require 'config.gui.rockets' --- @dep config.rockets
|
||||
|
||||
local largest_rolling_avg = 0
|
||||
for _,avg_over in pairs(config.stats.rolling_avg) do
|
||||
for _, avg_over in pairs(config.stats.rolling_avg) do
|
||||
if avg_over > largest_rolling_avg then
|
||||
largest_rolling_avg = avg_over
|
||||
end
|
||||
@@ -49,7 +49,7 @@ Global.register({
|
||||
rocket_times = rocket_times,
|
||||
rocket_stats = rocket_stats,
|
||||
rocket_silos = rocket_silos
|
||||
},function(tbl)
|
||||
}, function(tbl)
|
||||
Rockets.times = tbl.rocket_times
|
||||
Rockets.stats = tbl.rocket_stats
|
||||
Rockets.silos = tbl.rocket_silos
|
||||
@@ -94,9 +94,9 @@ end
|
||||
-- @treturn table an array of silo data that all belong to this force
|
||||
function Rockets.get_silos(force_name)
|
||||
local rtn = {}
|
||||
for _,silo_data in pairs(rocket_silos) do
|
||||
for _, silo_data in pairs(rocket_silos) do
|
||||
if silo_data.force == force_name then
|
||||
table.insert(rtn,silo_data)
|
||||
table.insert(rtn, silo_data)
|
||||
end
|
||||
end
|
||||
return rtn
|
||||
@@ -106,7 +106,7 @@ end
|
||||
-- @tparam string force_name the name of the force to get the count for
|
||||
-- @tparam number rocket_number the number of the rocket to get the launch time for
|
||||
-- @treturn number the game tick that the rocket was lanuched on
|
||||
function Rockets.get_rocket_time(force_name,rocket_number)
|
||||
function Rockets.get_rocket_time(force_name, rocket_number)
|
||||
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
|
||||
end
|
||||
|
||||
@@ -122,7 +122,7 @@ end
|
||||
-- @treturn number the total number of rockets launched this game
|
||||
function Rockets.get_game_rocket_count()
|
||||
local rtn = 0
|
||||
for _,force in pairs(game.forces) do
|
||||
for _, force in pairs(game.forces) do
|
||||
rtn = rtn + force.rockets_launched
|
||||
end
|
||||
return rtn
|
||||
@@ -132,7 +132,7 @@ end
|
||||
-- @tparam string force_name the name of the force to get the average for
|
||||
-- @tparam number count the distance to get the rolling average over
|
||||
-- @treturn number the number of ticks required to launch one rocket
|
||||
function Rockets.get_rolling_average(force_name,count)
|
||||
function Rockets.get_rolling_average(force_name, count)
|
||||
local force = game.forces[force_name]
|
||||
local rocket_count = force.rockets_launched
|
||||
if rocket_count == 0 then return 0 end
|
||||
@@ -146,7 +146,7 @@ function Rockets.get_rolling_average(force_name,count)
|
||||
end
|
||||
|
||||
--- Event used to update the stats and the hui when a rocket is launched
|
||||
Event.add(defines.events.on_rocket_launched,function(event)
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
local entity = event.rocket_silo
|
||||
local silo_data = Rockets.get_silo_data(entity)
|
||||
local force = event.rocket_silo.force
|
||||
@@ -177,7 +177,7 @@ Event.add(defines.events.on_rocket_launched,function(event)
|
||||
rocket_times[force_name][rockets_launched] = event.tick
|
||||
|
||||
local remove_rocket = rockets_launched-largest_rolling_avg
|
||||
if remove_rocket > 0 and not table.contains(config.milestones,remove_rocket) then
|
||||
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
|
||||
rocket_times[force_name][remove_rocket] = nil
|
||||
end
|
||||
|
||||
@@ -186,7 +186,7 @@ Event.add(defines.events.on_rocket_launched,function(event)
|
||||
end)
|
||||
|
||||
--- When a launch is reiggered it will await reset
|
||||
Event.add(defines.events.on_rocket_launch_ordered,function(event)
|
||||
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
||||
local entity = event.rocket_silo
|
||||
local silo_data = Rockets.get_silo_data(entity)
|
||||
silo_data.awaiting_reset = true
|
||||
@@ -212,7 +212,7 @@ local function on_built(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_built_entity,on_built)
|
||||
Event.add(defines.events.on_robot_built_entity,on_built)
|
||||
Event.add(defines.events.on_built_entity, on_built)
|
||||
Event.add(defines.events.on_robot_built_entity, on_built)
|
||||
|
||||
return Rockets
|
||||
@@ -4,9 +4,9 @@
|
||||
@alias Tasks
|
||||
|
||||
@usage-- Making and then editing a new task
|
||||
local task_id = Tasks.add_task(game.player.force.name,nil,game.player.name)
|
||||
local task_id = Tasks.add_task(game.player.force.name, nil, game.player.name)
|
||||
|
||||
Tasks.update_task(task_id,'We need more iron!',game.player.name)
|
||||
Tasks.update_task(task_id, 'We need more iron!', game.player.name)
|
||||
|
||||
]]
|
||||
|
||||
@@ -18,7 +18,7 @@ local Tasks = {}
|
||||
|
||||
-- Global lookup table for force name to task ids
|
||||
local force_tasks = {}
|
||||
Global.register(force_tasks,function(tbl)
|
||||
Global.register(force_tasks, function(tbl)
|
||||
force_tasks = tbl
|
||||
end)
|
||||
|
||||
@@ -38,10 +38,10 @@ Tasks.store = task_store
|
||||
@treturn string the uid of the task which was created
|
||||
|
||||
@usage-- Adding a new task for your force
|
||||
local task_id = Tasks.add_task(game.player.force.name,nil,game.player.name)
|
||||
local task_id = Tasks.add_task(game.player.force.name, nil, game.player.name)
|
||||
|
||||
]]
|
||||
function Tasks.add_task(force_name,task_number,player_name,task_message)
|
||||
function Tasks.add_task(force_name, task_number, player_name, task_message)
|
||||
-- Get a new task id
|
||||
local task_id = tostring(Token.uid())
|
||||
task_message = task_message or 'New Task'
|
||||
@@ -55,9 +55,9 @@ function Tasks.add_task(force_name,task_number,player_name,task_message)
|
||||
|
||||
-- Insert the task id into the forces tasks
|
||||
if task_number then
|
||||
table.insert(tasks,task_number,task_id)
|
||||
table.insert(tasks, task_number, task_id)
|
||||
else
|
||||
table.insert(tasks,task_id)
|
||||
table.insert(tasks, task_id)
|
||||
end
|
||||
|
||||
-- Create the editing table
|
||||
@@ -67,7 +67,7 @@ function Tasks.add_task(force_name,task_number,player_name,task_message)
|
||||
end
|
||||
|
||||
-- Add the new task to the store
|
||||
Store.set(task_store,task_id,{
|
||||
Store.set(task_store, task_id, {
|
||||
task_id = task_id,
|
||||
force_name = force_name,
|
||||
message = task_message,
|
||||
@@ -87,10 +87,10 @@ Tasks.remove_task(task_id)
|
||||
|
||||
]]
|
||||
function Tasks.remove_task(task_id)
|
||||
local task = Store.get(task_store,task_id)
|
||||
local task = Store.get(task_store, task_id)
|
||||
local force_name = task.force_name
|
||||
table.remove_element(force_tasks[force_name],task_id)
|
||||
Store.clear(task_store,task_id)
|
||||
table.remove_element(force_tasks[force_name], task_id)
|
||||
Store.clear(task_store, task_id)
|
||||
end
|
||||
|
||||
--[[-- Update the message and last edited information for a task
|
||||
@@ -99,11 +99,11 @@ end
|
||||
@tparam[opt='server'] string player_name the name of the player who made the edit
|
||||
|
||||
@usage-- Updating the message for on a task
|
||||
Task.update_task(task_id,'We need more iron!',game.player.name)
|
||||
Task.update_task(task_id, 'We need more iron!', game.player.name)
|
||||
|
||||
]]
|
||||
function Tasks.update_task(task_id,new_message,player_name)
|
||||
Store.update(task_store,task_id,function(task)
|
||||
function Tasks.update_task(task_id, new_message, player_name)
|
||||
Store.update(task_store, task_id, function(task)
|
||||
task.last_edit_name = player_name or '<server>'
|
||||
task.last_edit_time = game.tick
|
||||
task.message = new_message
|
||||
@@ -116,11 +116,11 @@ end
|
||||
@tparam boolean state the new state to set editing to
|
||||
|
||||
@usage-- Setting your editing state to true
|
||||
Tasks.set_editing(task_id,game.player.name,true)
|
||||
Tasks.set_editing(task_id, game.player.name, true)
|
||||
|
||||
]]
|
||||
function Tasks.set_editing(task_id,player_name,state)
|
||||
Store.update(task_store,task_id,function(task)
|
||||
function Tasks.set_editing(task_id, player_name, state)
|
||||
Store.update(task_store, task_id, function(task)
|
||||
task.curently_editing[player_name] = state
|
||||
end)
|
||||
end
|
||||
@@ -135,7 +135,7 @@ end)
|
||||
|
||||
]]
|
||||
function Tasks.on_update(handler)
|
||||
Store.watch(task_store,handler)
|
||||
Store.watch(task_store, handler)
|
||||
end
|
||||
|
||||
--- Getters.
|
||||
@@ -151,7 +151,7 @@ local task = Tasks.get_task(task_id)
|
||||
|
||||
]]
|
||||
function Tasks.get_task(task_id)
|
||||
return Store.get(task_store,task_id)
|
||||
return Store.get(task_store, task_id)
|
||||
end
|
||||
|
||||
--[[-- Gets all the task ids that a force has
|
||||
@@ -172,11 +172,11 @@ end
|
||||
@treturn boolean weather the player is currently editing this task
|
||||
|
||||
@usage-- Check if a player is editing a task or not
|
||||
local editing = Tasks.get_editing(task_id,game.player.name)
|
||||
local editing = Tasks.get_editing(task_id, game.player.name)
|
||||
|
||||
]]
|
||||
function Tasks.get_editing(task_id,player_name)
|
||||
local task = Store.get(task_store,task_id)
|
||||
function Tasks.get_editing(task_id, player_name)
|
||||
local task = Store.get(task_store, task_id)
|
||||
return task.curently_editing[player_name]
|
||||
end
|
||||
|
||||
|
||||
@@ -8,17 +8,17 @@
|
||||
local Warnings = require 'modules.control.warnings' --- @dep modules.control.warnings
|
||||
|
||||
-- This will add a warning to the player
|
||||
Warnings.add_warning('MrBiter','Cooldude2606','Killed too many biters')
|
||||
Warnings.add_warning('MrBiter', 'Cooldude2606', 'Killed too many biters')
|
||||
|
||||
-- This will remove a warning from a player, second name is just who is doing the action
|
||||
Warnings.remove_warning('MrBiter','Cooldude2606')
|
||||
Warnings.remove_warning('MrBiter', 'Cooldude2606')
|
||||
|
||||
-- Script warning as similar to normal warning but are designed to have no effect for a short amount of time
|
||||
-- this is so it can be used for greifer protection without being too agressive
|
||||
Warnings.add_script_warning('MrBiter','Killed too many biters')
|
||||
Warnings.add_script_warning('MrBiter', 'Killed too many biters')
|
||||
|
||||
-- Both normal and script warnings can also be cleared, this will remove all warnings
|
||||
Warnings.clear_warnings('MrBiter','Cooldude2606')
|
||||
Warnings.clear_warnings('MrBiter', 'Cooldude2606')
|
||||
]]
|
||||
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
@@ -65,7 +65,7 @@ local user_script_warnings = Warnings.user_script_warnings
|
||||
Global.register({
|
||||
user_warnings = user_warnings,
|
||||
user_script_warnings = user_script_warnings
|
||||
},function(tbl)
|
||||
}, function(tbl)
|
||||
Warnings.user_warnings = tbl.user_warnings
|
||||
Warnings.user_script_warnings = tbl.user_script_warnings
|
||||
user_warnings = Warnings.user_warnings
|
||||
@@ -92,7 +92,7 @@ end
|
||||
-- @tparam string by_player_name the name of the player who is doing the action
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being warned
|
||||
-- @treturn number the number of warnings that the player has
|
||||
function Warnings.add_warning(player,by_player_name,reason)
|
||||
function Warnings.add_warning(player, by_player_name, reason)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
@@ -105,7 +105,7 @@ function Warnings.add_warning(player,by_player_name,reason)
|
||||
user_warnings[player.name] = warnings
|
||||
end
|
||||
|
||||
table.insert(warnings,{
|
||||
table.insert(warnings, {
|
||||
tick = game.tick,
|
||||
by_player_name = by_player_name,
|
||||
reason = reason
|
||||
@@ -113,7 +113,7 @@ function Warnings.add_warning(player,by_player_name,reason)
|
||||
|
||||
local warning_count = #warnings
|
||||
|
||||
script.raise_event(Warnings.events.on_warning_added,{
|
||||
script.raise_event(Warnings.events.on_warning_added, {
|
||||
name = Warnings.events.on_warning_added,
|
||||
tick = game.tick,
|
||||
player_index = player.index,
|
||||
@@ -126,11 +126,11 @@ function Warnings.add_warning(player,by_player_name,reason)
|
||||
if action then
|
||||
local _type = type(action)
|
||||
if _type == 'function' then
|
||||
action(player,by_player_name,warning_count)
|
||||
action(player, by_player_name, warning_count)
|
||||
elseif _type == 'table' then
|
||||
local current = table.deepcopy(action)
|
||||
table.insert(current,2,by_player_name)
|
||||
table.insert(current,3,warning_count)
|
||||
table.insert(current, 2,by_player_name)
|
||||
table.insert(current, 3,warning_count)
|
||||
player.print(current)
|
||||
elseif type(action) == 'string' then
|
||||
player.print(action)
|
||||
@@ -145,8 +145,8 @@ end
|
||||
-- @tparam string warning_by_name the name of the player who made the warning
|
||||
-- @tparam string removed_by_name the name of the player who is doing the action
|
||||
-- @tparam number warning_count the number of warnings that the player how has
|
||||
local function warning_removed_event(player,warning_by_name,removed_by_name,warning_count)
|
||||
script.raise_event(Warnings.events.on_warning_removed,{
|
||||
local function warning_removed_event(player, warning_by_name, removed_by_name, warning_count)
|
||||
script.raise_event(Warnings.events.on_warning_removed, {
|
||||
name = Warnings.events.on_warning_removed,
|
||||
tick = game.tick,
|
||||
player_index = player.index,
|
||||
@@ -160,7 +160,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to remove a warning from
|
||||
-- @tparam string by_player_name the name of the player who is doing the action
|
||||
-- @treturn number the number of warnings that the player has
|
||||
function Warnings.remove_warning(player,by_player_name)
|
||||
function Warnings.remove_warning(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
@@ -168,9 +168,9 @@ function Warnings.remove_warning(player,by_player_name)
|
||||
local warnings = user_warnings[player.name]
|
||||
if not warnings then return end
|
||||
|
||||
local warning = table.remove(warnings,1)
|
||||
local warning = table.remove(warnings, 1)
|
||||
|
||||
warning_removed_event(player,warning.by_player_name,by_player_name,#warnings)
|
||||
warning_removed_event(player, warning.by_player_name, by_player_name, #warnings)
|
||||
|
||||
return #warnings
|
||||
end
|
||||
@@ -179,7 +179,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to clear the warnings from
|
||||
-- @tparam string by_player_name the name of the player who is doing the action
|
||||
-- @treturn boolean true when warnings were cleared succesfully
|
||||
function Warnings.clear_warnings(player,by_player_name)
|
||||
function Warnings.clear_warnings(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
@@ -188,8 +188,8 @@ function Warnings.clear_warnings(player,by_player_name)
|
||||
if not warnings then return end
|
||||
|
||||
local warning_count = #warnings
|
||||
for n,warning in pairs(warnings) do
|
||||
warning_removed_event(player,warning.by_player_name,by_player_name,warning_count-n)
|
||||
for n, warning in pairs(warnings) do
|
||||
warning_removed_event(player, warning.by_player_name, by_player_name, warning_count-n)
|
||||
end
|
||||
|
||||
user_warnings[player.name] = nil
|
||||
@@ -215,7 +215,7 @@ end
|
||||
-- @tparam LuaPlayer player the player to add a script warning to
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being warned
|
||||
-- @treturn number the number of script warnings that the player has
|
||||
function Warnings.add_script_warning(player,reason)
|
||||
function Warnings.add_script_warning(player, reason)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
|
||||
@@ -227,14 +227,14 @@ function Warnings.add_script_warning(player,reason)
|
||||
user_script_warnings[player.name] = warnings
|
||||
end
|
||||
|
||||
table.insert(warnings,{
|
||||
table.insert(warnings, {
|
||||
tick = game.tick,
|
||||
reason = reason
|
||||
})
|
||||
|
||||
local warning_count = #warnings
|
||||
|
||||
script.raise_event(Warnings.events.on_script_warning_added,{
|
||||
script.raise_event(Warnings.events.on_script_warning_added, {
|
||||
name = Warnings.events.on_script_warning_added,
|
||||
tick = game.tick,
|
||||
player_index = player.index,
|
||||
@@ -243,7 +243,7 @@ function Warnings.add_script_warning(player,reason)
|
||||
})
|
||||
|
||||
if warning_count > config.script_warning_limit then
|
||||
Warnings.add_warning(player,'<server>',reason)
|
||||
Warnings.add_warning(player, '<server>', reason)
|
||||
end
|
||||
|
||||
return warning_count
|
||||
@@ -252,8 +252,8 @@ end
|
||||
--- Script warning removed event tigger due to it being looped in clear script warnings
|
||||
-- @tparam LuaPlayer player the player who is having a script warning removed
|
||||
-- @tparam number warning_count the number of warning that the player has
|
||||
local function script_warning_removed_event(player,warning_count)
|
||||
script.raise_event(Warnings.events.on_script_warning_removed,{
|
||||
local function script_warning_removed_event(player, warning_count)
|
||||
script.raise_event(Warnings.events.on_script_warning_removed, {
|
||||
name = Warnings.events.on_script_warning_removed,
|
||||
tick = game.tick,
|
||||
player_index = player.index,
|
||||
@@ -271,7 +271,7 @@ function Warnings.remove_script_warning(player)
|
||||
local warnings = user_script_warnings[player.name]
|
||||
if not warnings then return end
|
||||
|
||||
table.remove(warnings,1)
|
||||
table.remove(warnings, 1)
|
||||
|
||||
script_warning_removed_event(player)
|
||||
|
||||
@@ -288,8 +288,8 @@ function Warnings.clear_script_warnings(player)
|
||||
if not warnings then return end
|
||||
|
||||
local warning_count = #warnings
|
||||
for n,_ in pairs(warnings) do
|
||||
script_warning_removed_event(player,warning_count-n)
|
||||
for n, _ in pairs(warnings) do
|
||||
script_warning_removed_event(player, warning_count-n)
|
||||
end
|
||||
|
||||
user_script_warnings[player.name] = nil
|
||||
@@ -298,11 +298,11 @@ end
|
||||
|
||||
-- script warnings are removed after a certain amount of time to make them even more lienient
|
||||
local script_warning_cool_down = config.script_warning_cool_down*3600
|
||||
Event.on_nth_tick(script_warning_cool_down/4,function()
|
||||
Event.on_nth_tick(script_warning_cool_down/4, function()
|
||||
local cutoff = game.tick - script_warning_cool_down
|
||||
for player_name,script_warnings in pairs(user_script_warnings) do
|
||||
for player_name, script_warnings in pairs(user_script_warnings) do
|
||||
if #script_warnings > 0 then
|
||||
for _,warning in pairs(script_warnings) do
|
||||
for _, warning in pairs(script_warnings) do
|
||||
if warning.tick < cutoff then
|
||||
Warnings.remove_script_warning(player_name)
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
@usage-- Making a new spawn warp
|
||||
local player = game.player
|
||||
local force = player.force
|
||||
local spawn_id = Warps.add_warp(force.name,player.surface,player.position,player.name,'Spawn')
|
||||
local spawn_id = Warps.add_warp(force.name, player.surface, player.position, player.name, 'Spawn')
|
||||
|
||||
Warps.set_spawn_warp(spawn_id, force)
|
||||
Warps.make_warp_tag(spawn_id)
|
||||
@@ -14,7 +14,7 @@ Warps.make_warp_tag(spawn_id)
|
||||
@usage-- Making a new warp with a warp area
|
||||
local player = game.player
|
||||
local force = player.force
|
||||
local warp_id = Warps.add_warp(force.name,player.surface,player.position,player.name)
|
||||
local warp_id = Warps.add_warp(force.name, player.surface, player.position, player.name)
|
||||
|
||||
Warps.make_warp_area(warp_id)
|
||||
Warps.make_warp_tag(warp_id)
|
||||
@@ -30,7 +30,7 @@ local Warps = {}
|
||||
|
||||
-- Global lookup table for force name to task ids
|
||||
local force_warps = {}
|
||||
Global.register(force_warps,function(tbl)
|
||||
Global.register(force_warps, function(tbl)
|
||||
force_warps = tbl
|
||||
end)
|
||||
|
||||
@@ -39,7 +39,7 @@ local warp_store = Store.register()
|
||||
Warps.store = warp_store
|
||||
|
||||
-- When a warp is updated change its chat tag and resort the warp order
|
||||
Store.watch(warp_store,function(warp,warp_id)
|
||||
Store.watch(warp_store, function(warp, warp_id)
|
||||
if warp then
|
||||
-- Update the map chart tag if there is one
|
||||
if warp.tag then
|
||||
@@ -55,8 +55,8 @@ Store.watch(warp_store,function(warp,warp_id)
|
||||
local spawn_id = warp_ids.spawn
|
||||
|
||||
local warp_names = {}
|
||||
for _,next_warp_id in pairs(warp_ids) do
|
||||
local next_warp = Store.get(warp_store,next_warp_id)
|
||||
for _, next_warp_id in pairs(warp_ids) do
|
||||
local next_warp = Store.get(warp_store, next_warp_id)
|
||||
if next_warp_id ~= spawn_id then
|
||||
warp_names[next_warp.name..next_warp_id] = next_warp_id
|
||||
end
|
||||
@@ -64,7 +64,7 @@ Store.watch(warp_store,function(warp,warp_id)
|
||||
|
||||
-- Sort the warp names in alphabetical order
|
||||
local new_warp_ids = table.get_values(table.keysort(warp_names))
|
||||
table.insert(new_warp_ids,1,spawn_id)
|
||||
table.insert(new_warp_ids, 1,spawn_id)
|
||||
new_warp_ids.spawn = spawn_id
|
||||
force_warps[force_name] = new_warp_ids
|
||||
end
|
||||
@@ -83,7 +83,7 @@ local tag_added = Warps.make_warp_tag(warp_id)
|
||||
|
||||
]]
|
||||
function Warps.make_warp_tag(warp_id)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
local name = warp.name
|
||||
local icon = warp.icon
|
||||
|
||||
@@ -91,7 +91,7 @@ function Warps.make_warp_tag(warp_id)
|
||||
local tag = warp.tag
|
||||
if tag and tag.valid then
|
||||
tag.text = 'Warp: '..name
|
||||
tag.icon = {type='item',name=icon}
|
||||
tag.icon = {type='item', name=icon}
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -100,10 +100,10 @@ function Warps.make_warp_tag(warp_id)
|
||||
local surface = warp.surface
|
||||
local position = warp.position
|
||||
|
||||
tag = force.add_chart_tag(surface,{
|
||||
position = {position.x+0.5,position.y+0.5},
|
||||
tag = force.add_chart_tag(surface, {
|
||||
position = {position.x+0.5, position.y+0.5},
|
||||
text = 'Warp: '..name,
|
||||
icon = {type='item',name=icon}
|
||||
icon = {type='item', name=icon}
|
||||
})
|
||||
|
||||
-- Add the tag to this warp, store.update not needed as we dont want it to trigger
|
||||
@@ -120,7 +120,7 @@ local removed = Warps.remove_warp_tag(warp_id)
|
||||
|
||||
]]
|
||||
function Warps.remove_warp_tag(warp_id)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
|
||||
-- Check there is a tag to remove
|
||||
local tag = warp.tag
|
||||
@@ -144,7 +144,7 @@ Warps.make_warp_area(warp_id)
|
||||
|
||||
]]
|
||||
function Warps.make_warp_area(warp_id)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
local surface = warp.surface
|
||||
local position = warp.position
|
||||
local posx = position.x
|
||||
@@ -164,7 +164,7 @@ function Warps.make_warp_area(warp_id)
|
||||
for y = -radius, radius do
|
||||
local y2 = y^2
|
||||
if x2+y2 < radius2 then
|
||||
table.insert(base_tiles,{name=base_tile,position={x+posx,y+posy}})
|
||||
table.insert(base_tiles, {name=base_tile, position={x+posx, y+posy}})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -172,16 +172,16 @@ function Warps.make_warp_area(warp_id)
|
||||
|
||||
-- Add a tile patern ontop of the base
|
||||
local tiles = {}
|
||||
for _,pos in pairs(config.tiles) do
|
||||
table.insert(tiles,{name=base_tile,position={pos[1]+posx,pos[2]+posy}})
|
||||
for _, pos in pairs(config.tiles) do
|
||||
table.insert(tiles, {name=base_tile, position={pos[1]+posx, pos[2]+posy}})
|
||||
end
|
||||
surface.set_tiles(tiles)
|
||||
|
||||
-- Add entities to the warp structure
|
||||
for _,entity in pairs(config.entities) do
|
||||
for _, entity in pairs(config.entities) do
|
||||
entity = surface.create_entity{
|
||||
name=entity[1],
|
||||
position={entity[2]+posx,entity[3]+posy},
|
||||
position={entity[2]+posx, entity[3]+posy},
|
||||
force='neutral'
|
||||
}
|
||||
entity.destructible = false
|
||||
@@ -199,7 +199,7 @@ Warps.remove_warp_area(warp_id)
|
||||
|
||||
]]
|
||||
function Warps.remove_warp_area(warp_id)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
local position = warp.position
|
||||
local surface = warp.surface
|
||||
local radius = config.standard_proximity_radius
|
||||
@@ -216,7 +216,7 @@ function Warps.remove_warp_area(warp_id)
|
||||
for y = -radius, radius do
|
||||
local y2 = y^2
|
||||
if x2+y2 < radius2 then
|
||||
table.insert(tiles,{name=base_tile,position={x+position.x,y+position.y}})
|
||||
table.insert(tiles, {name=base_tile, position={x+position.x, y+position.y}})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -226,11 +226,11 @@ function Warps.remove_warp_area(warp_id)
|
||||
local entities = surface.find_entities_filtered{
|
||||
force='neutral',
|
||||
area={
|
||||
{position.x-radius,position.y-radius},
|
||||
{position.x+radius,position.y+radius}
|
||||
{position.x-radius, position.y-radius},
|
||||
{position.x+radius, position.y+radius}
|
||||
}
|
||||
}
|
||||
for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end
|
||||
for _, entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end
|
||||
end
|
||||
|
||||
--[[-- Set a warp to be the spawn point for a force, force must own this warp
|
||||
@@ -238,12 +238,12 @@ end
|
||||
@tparam LuaForce force the force that you want to set the spawn for
|
||||
|
||||
@usage-- Set your forces spawn to a warp
|
||||
Warps.set_spawn_warp(warp_id,game.player.force)
|
||||
Warps.set_spawn_warp(warp_id, game.player.force)
|
||||
|
||||
]]
|
||||
function Warps.set_spawn_warp(warp_id,force)
|
||||
function Warps.set_spawn_warp(warp_id, force)
|
||||
-- Check the force owns this warp
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
if warp.force_name ~= force.name then return end
|
||||
|
||||
-- Set this warp as the spawn
|
||||
@@ -263,11 +263,11 @@ end
|
||||
@tparam LuaPlayer player the player to teleport to the warp
|
||||
|
||||
@usage-- Teleport yourself to a warp point
|
||||
Warps.teleport_player(warp_id,game.player)
|
||||
Warps.teleport_player(warp_id, game.player)
|
||||
|
||||
]]
|
||||
function Warps.teleport_player(warp_id,player)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
function Warps.teleport_player(warp_id, player)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
local surface = warp.surface
|
||||
local position = {
|
||||
x=warp.position.x+0.5,
|
||||
@@ -275,9 +275,9 @@ function Warps.teleport_player(warp_id,player)
|
||||
}
|
||||
|
||||
-- Teleport the player
|
||||
local goto_position = surface.find_non_colliding_position('character',position,32,1)
|
||||
local goto_position = surface.find_non_colliding_position('character', position, 32, 1)
|
||||
if player.driving then player.driving = false end
|
||||
player.teleport(goto_position,surface)
|
||||
player.teleport(goto_position, surface)
|
||||
end
|
||||
|
||||
--- Setters.
|
||||
@@ -294,10 +294,10 @@ end
|
||||
|
||||
@usage-- Adding a new warp for your force at your position
|
||||
local player = game.player
|
||||
local warp_id = Warps.add_warp(player.force.name,player.surface,player.position,player.name)
|
||||
local warp_id = Warps.add_warp(player.force.name, player.surface, player.position, player.name)
|
||||
|
||||
]]
|
||||
function Warps.add_warp(force_name,surface,position,player_name,warp_name)
|
||||
function Warps.add_warp(force_name, surface, position, player_name, warp_name)
|
||||
-- Get new warp id
|
||||
local warp_id = tostring(Token.uid())
|
||||
warp_name = warp_name or 'New warp'
|
||||
@@ -310,7 +310,7 @@ function Warps.add_warp(force_name,surface,position,player_name,warp_name)
|
||||
end
|
||||
|
||||
-- Insert the warp id into the force warps
|
||||
table.insert(warp_ids,warp_id)
|
||||
table.insert(warp_ids, warp_id)
|
||||
|
||||
-- Create the editing table
|
||||
local editing = {}
|
||||
@@ -319,7 +319,7 @@ function Warps.add_warp(force_name,surface,position,player_name,warp_name)
|
||||
end
|
||||
|
||||
-- Add the new warp to the store
|
||||
Store.set(warp_store,warp_id,{
|
||||
Store.set(warp_store, warp_id, {
|
||||
warp_id = warp_id,
|
||||
force_name = force_name,
|
||||
name = warp_name,
|
||||
@@ -345,12 +345,12 @@ Warps.remove_warp(warp_id)
|
||||
|
||||
]]
|
||||
function Warps.remove_warp(warp_id)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
local force_name = warp.force_name
|
||||
Warps.remove_warp_tag(warp_id)
|
||||
Warps.remove_warp_area(warp_id)
|
||||
Store.clear(warp_store,warp_id)
|
||||
table.remove_element(force_warps[force_name],warp_id)
|
||||
Store.clear(warp_store, warp_id)
|
||||
table.remove_element(force_warps[force_name], warp_id)
|
||||
end
|
||||
|
||||
--[[-- Update the name and icon for a warp
|
||||
@@ -360,11 +360,11 @@ end
|
||||
@tparam[opt='server'] string player_name the name of the player that made the edit
|
||||
|
||||
@usage-- Changing the name and icon for a warp
|
||||
Warps.update_warp(warp_id,'My Warp','iron-plate',game.player.name)
|
||||
Warps.update_warp(warp_id, 'My Warp', 'iron-plate', game.player.name)
|
||||
|
||||
]]
|
||||
function Warps.update_warp(warp_id,new_name,new_icon,player_name)
|
||||
Store.update(warp_store,warp_id,function(warp)
|
||||
function Warps.update_warp(warp_id, new_name, new_icon, player_name)
|
||||
Store.update(warp_store, warp_id, function(warp)
|
||||
warp.last_edit_name = player_name or '<server>'
|
||||
warp.last_edit_time = game.tick
|
||||
warp.old_name = warp.name
|
||||
@@ -379,11 +379,11 @@ end
|
||||
@tparam boolean state the new state to set editing to
|
||||
|
||||
@usage-- Setting your editing state to true
|
||||
Warps.set_editing(warp_id,game.player.name,true)
|
||||
Warps.set_editing(warp_id, game.player.name, true)
|
||||
|
||||
]]
|
||||
function Warps.set_editing(warp_id,player_name,state)
|
||||
Store.update(warp_store,warp_id,function(warp)
|
||||
function Warps.set_editing(warp_id, player_name, state)
|
||||
Store.update(warp_store, warp_id, function(warp)
|
||||
warp.currently_editing[player_name] = state
|
||||
end)
|
||||
end
|
||||
@@ -398,7 +398,7 @@ end)
|
||||
|
||||
]]
|
||||
function Warps.on_update(handler)
|
||||
Store.watch(warp_store,handler)
|
||||
Store.watch(warp_store, handler)
|
||||
end
|
||||
|
||||
--- Getters.
|
||||
@@ -414,7 +414,7 @@ local warp = Warps.get_warp(warp_id)
|
||||
|
||||
]]
|
||||
function Warps.get_warp(warp_id)
|
||||
return Store.get(warp_store,warp_id)
|
||||
return Store.get(warp_store, warp_id)
|
||||
end
|
||||
|
||||
--[[-- Gets all the warp ids that a force has
|
||||
@@ -448,11 +448,11 @@ end
|
||||
@treturn boolean weather the player is currently editing this warp
|
||||
|
||||
@usage-- Check if a player is editing a warp or not
|
||||
local editing = Warps.get_editing(warp_id,game.player.name)
|
||||
local editing = Warps.get_editing(warp_id, game.player.name)
|
||||
|
||||
]]
|
||||
function Warps.get_editing(warp_id,player_name)
|
||||
local warp = Store.get(warp_store,warp_id)
|
||||
function Warps.get_editing(warp_id, player_name)
|
||||
local warp = Store.get(warp_store, warp_id)
|
||||
return warp.currently_editing[player_name]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user