LuaPlayer.unlock_tips_and_tricks_item(name)
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
LuaPlayer.unlock_tips_and_tricks_item(name)
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
ScriptTipTrigger
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.
And...
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 = { ... }
}
}
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)
Re: LuaPlayer.unlock_tips_and_tricks_item(name)
I have found a workaround 
Create a fake technology.
Then configure a ResearchTechnologyTipTrigger:
Then control-time code can simply do:
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.

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 = {}
}}
Code: Select all
data:extend{{
type = "tips-and-tricks-item",
name = "script-triggered-tip",
trigger = {
type = "research",
technology = "tips-and-tricks-trigger"
},
-- ...
}}
Code: Select all
player.force.technologies['tips-and-tricks-trigger'].researched = true
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.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: LuaPlayer.unlock_tips_and_tricks_item(name)
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.