on_cutscene_start and on_cutscene_end events

Post Reply
User avatar
Wiwiweb
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Sat May 08, 2021 2:36 am
Contact:

on_cutscene_start and on_cutscene_end events

Post by Wiwiweb »

What?
I would like 2 new events: `on_cutscene_start` and `on_cutscene_end`, which trigger when anything starts/ends a cutscene.
Why?
When leaving or returning to Space Exploration's navigation satellite view, we need to save/restore the player's inventory.
When a cutscene happens while someone is in satellite view, we have no way to know that they have just left that view, and we cannot save their inventory.
In addition, `on_cutscene_end` would be convenient to restore that inventory. (At the moment this is possible in a hacky way by checking for the player's controller 1 tick after`on_cutscene_cancelled` and `on_cutscene_waypoint_reached`, but a proper way to detect the end of a cutscene would be best.)

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: on_cutscene_start and on_cutscene_end events

Post by Pi-C »

Wiwiweb wrote:
Fri Apr 21, 2023 1:51 am
… a proper way to detect the end of a cutscene would be best.
on_cutscene_cancelled will also trigger when a cutscene ends naturally, without player intervention. Add this to your mod:

Code: Select all

script.on_event(defines.events.on_cutscene_cancelled, function(event)
	log("Cutscene ended: "..serpent.block(event))
end)
Start a new freeplay game, wait until the cutscene has finished of its own. Grep your log file for "Cutscene ended:", and you'll find the event data.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Wiwiweb
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Sat May 08, 2021 2:36 am
Contact:

Re: on_cutscene_start and on_cutscene_end events

Post by Wiwiweb »

That doesn't seem to be true, or maybe not in all cases? This is the result from clicking the "Activate" button on Krastorio 2's intergalactic transmitter (Using this mod: https://mods.factorio.com/mod/0-event-trace - muted the on_player_position_changed and on_entity_damaged events for clarity)
Screenshot 2023-04-22 174821.png
Screenshot 2023-04-22 174821.png (101.26 KiB) Viewed 997 times
Save file included if you want to try and reproduce. Regardless, I'm mostly interested in on_cutscene_starts, since I already have the hacky way of detecting the end on a cutscene :)
Attachments
cutscene test.zip
(1.3 MiB) Downloaded 50 times

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: on_cutscene_start and on_cutscene_end events

Post by Pi-C »

Wiwiweb wrote:
Sun Apr 23, 2023 12:53 am
That doesn't seem to be true, or maybe not in all cases?
Sorry, it seems you're right. According to the API description, on_cutscene_cancelled is raised when a cutscene is cancelled by the player or by script. In miniMAXIme, I must delay initializing players until the cutscene is cancelled or ends because the player won't have a character before that. However, looking in data/base/scenarios/freeplay.lua, I've found that the event is raised once the first waypoint of the cutscene has been reached by player.exit_cutscene():

Code: Select all

local on_cutscene_waypoint_reached = function(event)
  if not global.crash_site_cutscene_active then return end
  if not crash_site.is_crash_site_cutscene(event) then return end

  local player = game.get_player(event.player_index)

  player.exit_cutscene()

  if not global.skip_intro then
    if game.is_multiplayer() then
      player.print(global.custom_intro_message or {"msg-intro"})
    else
      game.show_message_dialog{text = global.custom_intro_message or {"msg-intro"}}
    end
  end
end
Thus, my assumption that on_cutscene_cancelled will also be triggered when the cutscene ends naturally seemed to be right for the vanilla cutscene (it really isn't as there is another waypoint after player.exit_cutscreen() has been called), but isn't guaranteed to work with cutscenes added by other mods.

I agree now that it would be nice to have on_cutscene_end. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: on_cutscene_start and on_cutscene_end events

Post by raiguard »

This was added in 1.1.82, but I forgot to put it in the changelog.

Code: Select all

Scripting:
  - Added on_cutscene_started, on_cutscene_finished
on_cutscene_finished will only be raised if a cutscene ends naturally. If you need to detect whenever a cutscene ends at all, you need to hook both on_cutscene_finished and on_cutscene_cancelled.
Don't forget, you're here forever.

Post Reply

Return to “Implemented mod requests”