initial events after game loaded

Place to get help with not working mods / modding interface.
Post Reply
palmic
Inserter
Inserter
Posts: 22
Joined: Fri Apr 21, 2017 2:44 pm
Contact:

initial events after game loaded

Post by palmic »

Hi,
before few days i started to create my first simple mod, but now when i want to change some settings, its still seems to keep old values saved in gamefile.
When i tried to debug it by game.print, or player.print, i found that none of these events are triggered after i load my game:

Code: Select all

local function on_player_respawned(event)
    local player = game.players[event.player_index]
    init_player(player)
    player.print("on_player_respawned")
end

local function on_player_created(event)
    local player = game.players[event.player_index]
    init_player(player)
    player.print("on_player_created")
end

local function on_player_joined_game(event)
    local player = game.players[event.player_index]
    init_player(player)
    player.print("on_player_joined_game")
end

local function on_player_armor_inventory_changed(event)
    -- game.print("on_player_armor_inventory_changed")
    local player = game.players[event.player_index]
    init_player(player)
end

local function on_research_finished(event)
    local players = event.research.force.players
    for i in pairs(players) do
        init_player(players[i])
    end
end

script.on_event(defines.events.on_player_respawned, on_player_respawned)
script.on_event(defines.events.on_player_joined_game, on_player_joined_game)
script.on_event(defines.events.on_player_armor_inventory_changed, on_player_armor_inventory_changed)
script.on_event(defines.events.on_research_finished, on_research_finished)
I always restart the game after any change of course

While my script changes seems to be loaded into game, only these events works (dumps newly added player.print calls):
  • on_player_armor_inventory_changed
  • on_research_finished
I want some event which is triggered always after both game loaded and new game created, but none of these events does that (player.print dumps are not logging anything ingame):
  • defines.events.on_player_respawned
  • defines.events.on_player_joined_game

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

Re: initial events after game loaded

Post by eradicator »

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.

palmic
Inserter
Inserter
Posts: 22
Joined: Fri Apr 21, 2017 2:44 pm
Contact:

Re: initial events after game loaded

Post by palmic »


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

Re: initial events after game loaded

Post by eradicator »

on_player_created *should* work for that though...

Anyway, if you want to be compatible with other mods that change player stuff you'll have to do relative changes instead of absolute ones, or the mods will overwrite each other. Though to not apply your own stuff twice you'd need to store your own modifiers in your global table. Which makes stuff quite a bit more complicated :p

Code: Select all

player.character.character_mining_speed_modifier =  player.character.character_mining_speed_modifier - 0.7
instead of

Code: Select all

player.character.character_mining_speed_modifier = -0.7
(Do negative modifiers actually work?)
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.

palmic
Inserter
Inserter
Posts: 22
Joined: Fri Apr 21, 2017 2:44 pm
Contact:

Re: initial events after game loaded

Post by palmic »

Understand, thank you very much.
But i dont want the mod to be relevant on current combination of other mods, because i dont know which values will be in that vars.
For me here, its better to be exact, or not updating at all i think..
But thanks again!

BTW: (Do negative modifiers actually work?)
- the values goes from -0.9 to 0.9 while -0.9 will stop progress at all from what i've seen at testing ;)

Post Reply

Return to “Modding help”