z_mirror/Krastorio2

git clone https://git.raiguard.me/z_mirror/Krastorio2

Caleb HeuerFix space age warning showing without space age enabled722847a5

trunk
1.2 KiB42 linesraw
1-- Show a warning ten seconds after the game starts and whenever a player joins the game.
2-- Modders: This warning can be disabled in the data stage using the prototypes.libraries.space-age-warning API.
3
4local warning_enabled = prototypes.mod_data["kr-space-age-warning"].data.enabled --[[@as boolean]]
5local warning_time = (60 * 10)
6local warning_cutoff = warning_time + 5
7
8--- @param player LuaPlayer
9local function print_warning(player)
10  if not warning_enabled then
11    return
12  end
13  player.print({ "message.kr-space-age-warning-title" })
14  player.print({ "message.kr-space-age-warning-description" })
15end
16
17--- @param e NthTickEventData
18local function on_check_show_warning(e)
19  if not script.active_mods["space-age"] then
20    return
21  end
22  local mod_added_tick = storage.mod_added_tick or 0
23  local mod_lifetime_ticks = e.tick - mod_added_tick
24  if mod_lifetime_ticks > 0 and mod_lifetime_ticks < warning_cutoff then
25    for _, player in pairs(game.players) do
26      print_warning(player)
27    end
28  end
29end
30
31--- @class kr.space_age_warning: event_handler
32local space_age_warning = {}
33
34function space_age_warning.on_init()
35  storage.mod_added_tick = game.tick
36end
37
38space_age_warning.on_nth_tick = {
39  [warning_time] = on_check_show_warning,
40}
41
42return space_age_warning