1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00

on_tick_schedule

This commit is contained in:
MewMew 2019-03-03 02:38:29 +01:00
parent 7ef17ace0f
commit 127a976468
3 changed files with 54 additions and 0 deletions

View File

@ -11,6 +11,7 @@ require "group"
require "player_list"
require "poll"
require "score"
require "on_tick_schedule"
---- enable modules here ----
--require "maps.tools.cheat_mode"

View File

@ -779,6 +779,27 @@ local function on_gui_click(event)
end
end
local particles = {"coal-particle", "copper-ore-particle", "iron-ore-particle", "stone-particle"}
local function create_fireworks_rocket(surface, position)
local particle = particles[math_random(1, #particles)]
local m = math_random(16, 36)
local m2 = m * 0.005
for i = 1, 100, 1 do
surface.create_entity({
name = particle,
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
})
end
if math_random(1,16) ~= 1 then return end
surface.create_entity({name = "explosion", position = position})
end
local function on_entity_died(event)
if not global.rocket_silo_destroyed then
if event.entity == global.rocket_silo["south"] or event.entity == global.rocket_silo["north"] then
@ -792,6 +813,20 @@ local function on_entity_died(event)
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/game_won", volume_modifier=1}
end
--fireworks
local radius = 128
for t = 1, 18000, 1 do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
for x = 1, 8, 1 do
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_fireworks_rocket,
args = {event.entity.surface, {x = radius - math_random(0, radius * 2),y = radius - math_random(0, radius * 2)}}
}
end
t = t + 1
end
refresh_gui()
end
end

18
on_tick_schedule.lua Normal file
View File

@ -0,0 +1,18 @@
local event = require 'utils.event'
local function on_tick()
if not global.on_tick_schedule[game.tick] then return end
for _, schedule in pairs(global.on_tick_schedule[game.tick]) do
schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4], schedule.args[5])
end
global.on_tick_schedule[game.tick] = nil
end
local function on_player_joined_game(event)
if not global.on_tick_schedule then global.on_tick_schedule = {} end
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_tick, on_tick)