LuaPlayer.unlock_tips_and_tricks_item(name)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

LuaPlayer.unlock_tips_and_tricks_item(name)

Post by eradicator »

Similar to LuaPlayer.unlock_achievement(), set_shortcut_available(), etc. I'd like to be able to manually trigger a tips&tricks item. Probably also needs a new TipTrigger "lua"?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

ScriptTipTrigger

Post by PFQNiet »

I could suggest a whole range of new TipTrigger types, like MineEntityTipTrigger, DamageTakenTipTrigger, and many more, as it seems like the existing set of triggers were specifically made for whatever the default tips and tricks need and don't yet offer much flexibility.

But even with a wider range of triggers, I can easily imagine a Scenario or overhaul mod benefiting from triggering tips in response to an arbitrary event. So that's what I'm suggesting.

ScriptTipTrigger takes an arbitrary name, and an associated function like LuaPlayer#complete_tip_trigger() that can be called with the name to resolve that tip trigger. This would allow it to be used in combination with other triggers.

Code: Select all

data:extend{
  {
    type = "tips-and-tricks-item",
    name = "dont-die-silly",
    trigger = {
      type = "sequence",
      triggers = {
        {
          type = "script",
          name = "player-died"
        },
        {
          type = "time-elapsed",
          ticks = 600
        }
      }
    }, -- trigger 10 seconds after the script trigger resolves
    simulation = { ... }
  }
}
And...

Code: Select all

script.on_event(defines.events.on_player_died, function(event)
  local player = game.players[event.player_index]
  -- Provide "useful" information about how not to die
  player.complete_tip_trigger("player-died")
end)

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: LuaPlayer.unlock_tips_and_tricks_item(name)

Post by PFQNiet »

I have found a workaround :D

Create a fake technology.

Code: Select all

data:extend{{
  type = "technology",
  name = "tips-and-tricks-trigger",
  icon = "__core__/graphics.empty.png",
  icon_size = 1,
  hidden = true,
  unit = {
    count = 1,
    time = 1,
    ingredients = {}
  },
  prerequisites = {},
  effects = {}
}}
Then configure a ResearchTechnologyTipTrigger:

Code: Select all

data:extend{{
  type = "tips-and-tricks-item",
  name = "script-triggered-tip",
  trigger = {
    type = "research",
    technology = "tips-and-tricks-trigger"
  },
  -- ...
}}
Then control-time code can simply do:

Code: Select all

player.force.technologies['tips-and-tricks-trigger'].researched = true
This will unlock the Tip/Trick when the script says so, on a per-force basis.

If per-player is needed, you have to get a bit more creative, but it may be possible with a CraftItemTipTrigger, and the script can put a 1-frame fake recipe to craft a dummy item, which is then removed from the player's inventory... But then you have awkwardness if the player's inventory is full, so might not work out overall. Per-force is fine for my needs anyway, and the "fake research" works for me.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: LuaPlayer.unlock_tips_and_tricks_item(name)

Post by eradicator »

PFQNiet wrote:
Fri Jul 09, 2021 5:12 pm
Hm, I hadn't thought of abusing the other trigger types like that. Thanks for the idea!
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding interface requests”