Displaying Text and Giving Items - Single Player Scenario

Place to get help with not working mods / modding interface.
johnmegacycle
Inserter
Inserter
Posts: 22
Joined: Tue Jul 26, 2016 1:35 am
Contact:

Displaying Text and Giving Items - Single Player Scenario

Post by johnmegacycle »

I have a few scenarios that I had working nicely on 12.x and after updating to 14.x none of the commands that I had in control.lua work, understandably so. I've exhausted the search here and on google, but I can't find an entry level description on how to get some text to display when a player loads up the scenario. This would allow me to give some mission objectives and a direction of what the player should be doing.
I'm guessing something like this is close:

script.on_init(function()
game.show_message_dialog{text={"Intro Text 1"}, pointto = {type = "entity", entity = game.player.character}}
game.show_message_dialog{text={"Intro Text 2"}, pointto = {type = "entity", entity = game.player.character}}
game.show_message_dialog{text={"Intro Text 3"}, pointto = {type = "entity", entity = game.player.character}}
game.player.force.technologies["walls"].researched = true
game.player.force.technologies["military"].researched = true
game.player.force.technologies["automation"].researched = true
game.player.force.technologies["turrets"].researched = true end)

I'd also like to give the player a few items to start, but a chest next to the spawn kinda kills the story.
Thanks in advance.
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Displaying Text and Giving Items - Single Player Scenario

Post by daniel34 »

johnmegacycle wrote:pointto = {type = "entity", entity = game.player.character}
It's point_to, see here: http://lua-api.factorio.com/latest/LuaG ... age_dialog
quick links: log file | graphical issues | wiki
johnmegacycle
Inserter
Inserter
Posts: 22
Joined: Tue Jul 26, 2016 1:35 am
Contact:

Re: Displaying Text and Giving Items - Single Player Scenario

Post by johnmegacycle »

daniel34 wrote:
johnmegacycle wrote:pointto = {type = "entity", entity = game.player.character}
It's point_to, see here: http://lua-api.factorio.com/latest/LuaG ... age_dialog
Thanks, I'll give that a try later tonight.
I'm hoping the research is correct, but is there a list of what the lua equivalents are for research names to ensure I'm granting the right ones?
Also, would you happen to know where I can find the code to give the player items?
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Displaying Text and Giving Items - Single Player Scenario

Post by daniel34 »

johnmegacycle wrote:I'm hoping the research is correct, but is there a list of what the lua equivalents are for research names to ensure I'm granting the right ones?
Also, would you happen to know where I can find the code to give the player items?
You can find the actual names for technologies in your Factorio folder in data\base\prototypes\technology\technology.lua, or in data\base\locale\en\base.cfg in the [technology-name] section.

For the code to give the player items look in data\base\scenarios\freeplay\control.lua:

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
  local player = game.players[event.player_index]
  player.insert{name="iron-plate", count=8}
  player.insert{name="pistol", count=1}
  player.insert{name="firearm-magazine", count=10}
  player.insert{name="burner-mining-drill", count = 1}
  player.insert{name="stone-furnace", count = 1}
  player.force.chart(player.surface, {{player.position.x - 200, player.position.y - 200}, {player.position.x + 200, player.position.y + 200}})
  if (#game.players <= 1) then
    game.show_message_dialog{text = {"msg-intro"}}
  else
    player.print({"msg-intro"})
  end
end)
quick links: log file | graphical issues | wiki
johnmegacycle
Inserter
Inserter
Posts: 22
Joined: Tue Jul 26, 2016 1:35 am
Contact:

Re: Displaying Text and Giving Items - Single Player Scenario

Post by johnmegacycle »

daniel34 wrote:
johnmegacycle wrote:I'm hoping the research is correct, but is there a list of what the lua equivalents are for research names to ensure I'm granting the right ones?
Also, would you happen to know where I can find the code to give the player items?
You can find the actual names for technologies in your Factorio folder in data\base\prototypes\technology\technology.lua, or in data\base\locale\en\base.cfg in the [technology-name] section.

For the code to give the player items look in data\base\scenarios\freeplay\control.lua:

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
  local player = game.players[event.player_index]
  player.insert{name="iron-plate", count=8}
  player.insert{name="pistol", count=1}
  player.insert{name="firearm-magazine", count=10}
  player.insert{name="burner-mining-drill", count = 1}
  player.insert{name="stone-furnace", count = 1}
  player.force.chart(player.surface, {{player.position.x - 200, player.position.y - 200}, {player.position.x + 200, player.position.y + 200}})
  if (#game.players <= 1) then
    game.show_message_dialog{text = {"msg-intro"}}
  else
    player.print({"msg-intro"})
  end
end)
Oh my gosh (blush).
I should have thought of that, but it's early o'clock and I'm apparently as dense as the aliens at the moment...
Thanks so much again for your help.
Post Reply

Return to “Modding help”