mirror of
https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git
synced 2024-12-04 09:43:00 +02:00
Saving work on custom events.
This commit is contained in:
parent
ec109a2c3b
commit
d4b26d93ac
27
control.lua
27
control.lua
@ -115,6 +115,33 @@ end)
|
||||
-- log(serpent.block(event))
|
||||
-- end)
|
||||
|
||||
----------------------------------------
|
||||
-- CUSTOM OARC Events (shown here for demo and logging purposes)
|
||||
----------------------------------------
|
||||
script.on_event("oarc-mod-on-spawn-created", function(event)
|
||||
log("Custom event oarc-mod-on-spawn-created")
|
||||
log(serpent.block(event))
|
||||
end)
|
||||
|
||||
script.on_event("oarc-mod-on-spawn-remove-request", function(event)
|
||||
log("Custom event oarc-mod-on-spawn-remove-request")
|
||||
log(serpent.block(event))
|
||||
end)
|
||||
|
||||
script.on_event("oarc-mod-on-player-reset", function(event)
|
||||
log("Custom event oarc-mod-on-player-reset")
|
||||
log(serpent.block(event))
|
||||
if (game.players[event.player_index]) then
|
||||
log("Player is still valid: " .. game.players[event.player_index].name)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event("oarc-mod-on-player-spawned", function(event)
|
||||
log("Custom event oarc-mod-on-player-spawned")
|
||||
log(serpent.block(event))
|
||||
log("Player spawned: " .. game.players[event.player_index].name)
|
||||
end)
|
||||
|
||||
----------------------------------------
|
||||
-- Shared chat, so you don't have to type /s
|
||||
-- But you do lose your player colors across forces.
|
||||
|
34
data.lua
34
data.lua
@ -21,8 +21,40 @@ data:extend({
|
||||
width = 40,
|
||||
height = 40
|
||||
},
|
||||
oarc_linked_chest, oarc_linked_power
|
||||
oarc_linked_chest, oarc_linked_power,
|
||||
})
|
||||
|
||||
data:extend({
|
||||
-- A spawn area was created (and is finished generating)
|
||||
{
|
||||
type = "custom-event",
|
||||
name = "oarc-mod-on-spawn-created",
|
||||
-- Provides a data table called spawn_data
|
||||
},
|
||||
|
||||
-- A spawn area was REQUESTED to be removed. (Not that it has been removed already.)
|
||||
{
|
||||
type = "custom-event",
|
||||
name = "oarc-mod-on-spawn-remove-request",
|
||||
-- Provides a data table called spawn_data
|
||||
},
|
||||
|
||||
-- A player was reset (also called when a player is removed)
|
||||
-- If you want just player removed, use native on_player_removed and/or on_pre_player_removed
|
||||
{
|
||||
type = "custom-event",
|
||||
name = "oarc-mod-on-player-reset",
|
||||
-- Provides a player_index
|
||||
},
|
||||
|
||||
-- A player was spawned (sent to a new spawn OR joined a shared spawn)
|
||||
{
|
||||
type = "custom-event",
|
||||
name = "oarc-mod-on-player-spawned",
|
||||
-- Provides a player_index
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Make coins not hidden
|
||||
data.raw["item"]["coin"].hidden = false
|
@ -490,6 +490,7 @@ function SpawnCtrlTabGuiClick(event)
|
||||
local joining_player = game.players[join_queue_player_choice]
|
||||
SetPlayerRespawn(joining_player.name, primary_spawn.surface_name, primary_spawn.position, true)
|
||||
SendPlayerToSpawn(primary_spawn.surface_name, joining_player)
|
||||
script.raise_event("oarc-mod-on-player-spawned", {player_index = joining_player.index})
|
||||
GivePlayerStarterItems(joining_player)
|
||||
table.insert(storage.unique_spawns[primary_spawn.surface_name][player.name].joiners, joining_player.name)
|
||||
joining_player.force = game.players[player.name].force
|
||||
|
@ -496,16 +496,24 @@ function SendPlayerToNewSpawnAndCreateIt(delayed_spawn)
|
||||
ChartArea(player.force, delayed_spawn.position, math.ceil(storage.ocfg.spawn_general.spawn_radius_tiles / CHUNK_SIZE),
|
||||
player.surface)
|
||||
|
||||
-- Remove waiting dialog
|
||||
if (player.gui.screen.wait_for_spawn_dialog ~= nil) then
|
||||
player.gui.screen.wait_for_spawn_dialog.destroy()
|
||||
end
|
||||
|
||||
-- Create crash site if configured
|
||||
if (ocfg.surfaces_config[delayed_spawn.surface].starting_items.crashed_ship) then
|
||||
crash_site.create_crash_site(game.surfaces[delayed_spawn.surface],
|
||||
{ x = delayed_spawn.position.x + 15, y = delayed_spawn.position.y - 25 },
|
||||
ocfg.surfaces_config[delayed_spawn.surface].starting_items.crashed_ship_resources,
|
||||
ocfg.surfaces_config[delayed_spawn.surface].starting_items.crashed_ship_wreakage)
|
||||
end
|
||||
|
||||
-- Trigger the event that the spawn was created.
|
||||
script.raise_event("oarc-mod-on-spawn-created", {spawn_data = delayed_spawn})
|
||||
|
||||
-- Trigger the event that player was spawned too.
|
||||
script.raise_event("oarc-mod-on-player-spawned", {player_index = player.index})
|
||||
end
|
||||
|
||||
---Displays some welcoming text at the spawn point on the ground. Fades out over time.
|
||||
@ -781,6 +789,9 @@ function RemoveOrResetPlayer(player, remove_player)
|
||||
game.merge_forces(player_old_force, "neutral")
|
||||
end
|
||||
|
||||
-- Trigger the event that the player was reset.
|
||||
script.raise_event("oarc-mod-on-player-reset", {player_index = player.index})
|
||||
|
||||
-- Remove the character completely
|
||||
if (remove_player and not player.connected) then
|
||||
game.remove_offline_players({ player })
|
||||
@ -884,6 +895,8 @@ function UniqueSpawnCleanupRemove(player_name)
|
||||
local clear_radius = storage.ocfg.gameplay.minimum_distance_to_existing_chunks - 2 -- Bring in a bit for safety.
|
||||
RegrowthMarkAreaForRemoval(primary_spawn.surface_name, spawn_position, clear_radius)
|
||||
TriggerCleanup()
|
||||
-- Trigger event
|
||||
script.raise_event("oarc-mod-on-spawn-remove-request", {spawn_data = primary_spawn})
|
||||
end
|
||||
|
||||
storage.unique_spawns[primary_spawn.surface_name][player_name] = nil
|
||||
|
Loading…
Reference in New Issue
Block a user