How can I find the loading player's index?
Posted: Fri Jan 26, 2018 9:57 pm
I have a scenario in which I want to run some per-player remote calls on load (to change some default event responses when the scenario's running), but to provide backup implementations in case the mod's not present:
I know why not to change game state in on_load, I use an on_tick dance not shown here for clarity. The problem I'm facing is, I want to issue that remote call for the player loading the scenario map, but I don't see how to find the player index of the player loading the map.
For multiplayer I could do it in on_player_joined_game, but trying it says that doesn't fire in singleplayer (side note, if it did, I wouldn't need the on_tick dance, ooh ooh and if on_player_left_game fired at the end that'd help with benchmarks too!).
Maybe some concrete details would help understand, perhaps there's an entirely different way to do what I want I haven't figured out?
The mod hooks the decon planner to provide an `iod` command allowing you to run arbitrary commands on selected entities, e.g. `/iod e.direction=2` and wave an inserter-selecting decon planner, all the selected inserters now point left. I'm adding an optional/per-player cheat facility like creative mode's, that instabuilds and instakills.
The scenario works fine without the mod, but I want it to provide the instakill/instabuild there too, and I want it to be the default. The way I'm going about it is to have the scenario control enable it remotely if the mod's there, or supply the hooks itself if it's not. If I could get the player index of the player loading the map, it'd be easy. I suspect I could do it by setting things up in on_init and tracking changes via a global updated by `on_configuration_changed`, but eww.
It looks like having on_player_{joined,left}_game fire even in single player would solve this, could I get that if there's not a better way to do what I want already?
Code: Select all
on('load',function()
if remote.interfaces.BenchmarkProduction.insta then
remote.call('BenchmarkProduction','insta', /* need to pass the player index here */)
else
do the bare-scenario stuff here
end
end)
For multiplayer I could do it in on_player_joined_game, but trying it says that doesn't fire in singleplayer (side note, if it did, I wouldn't need the on_tick dance, ooh ooh and if on_player_left_game fired at the end that'd help with benchmarks too!).
Maybe some concrete details would help understand, perhaps there's an entirely different way to do what I want I haven't figured out?
The mod hooks the decon planner to provide an `iod` command allowing you to run arbitrary commands on selected entities, e.g. `/iod e.direction=2` and wave an inserter-selecting decon planner, all the selected inserters now point left. I'm adding an optional/per-player cheat facility like creative mode's, that instabuilds and instakills.
The scenario works fine without the mod, but I want it to provide the instakill/instabuild there too, and I want it to be the default. The way I'm going about it is to have the scenario control enable it remotely if the mod's there, or supply the hooks itself if it's not. If I could get the player index of the player loading the map, it'd be easy. I suspect I could do it by setting things up in on_init and tracking changes via a global updated by `on_configuration_changed`, but eww.
It looks like having on_player_{joined,left}_game fire even in single player would solve this, could I get that if there's not a better way to do what I want already?