When you assign player force upon creation, it works only form second player on

Place to get help with not working mods / modding interface.
Post Reply
Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

When you assign player force upon creation, it works only form second player on

Post by Rafiz »

In short - upon creating new multiplayer game (non-headless) this script :

Code: Select all

function on_player_created(event)
	local player = game.players[event.player_index]
	local newForce = createPlayerForce(player)
	game.print('1' .. player.force.name)
	game.print('2' .. newForce.name)
	player.force = newForce
	game.print('3' .. player.force.name)
	game.print('4' .. newForce.name)
	newForce.share_chart = true
	befriendRadarForce(newForce)
end
script.on_event(defines.events.on_player_created, on_player_created) 
causes this :
a) first player gets created
b) first player gets assigned to force named after him
c) right after game start I write command to check and first player isn't in his force (he is in 'player' force)
d) another player joins
e) he stays in force named after him
*) force named after first player exists. Probably player got assigned here, but game than moved him to 'player' force.

What I would expect : All players are affected equally by that script

I believe during map starting first player gets created and he is "force-less", only after that forces are being created and player is assigned to first one.
What could solve this : 1. Couldn't player be created after forces? (as I guess it would happen if I ran headless without pause when no-players)

Perhaps I have bad idea on how I do this stuff and by doing it some other way I would avoid that problem, but still, I believe it would be more "proper" if _on_player_created gave me possibility to assign new player properties.
Last edited by Rafiz on Sun Feb 07, 2021 11:00 pm, edited 3 times in total.

Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

Re: When you assign player force upon creation, it works only form second player on

Post by Rafiz »

Here is whole script :
https://pastebin.com/22Uj4xYz
* I wrote set_gloal / not set_global, but thakns to copy-pasting everything I can, this doesn't affect anything, function reference is same everywhere..

Output during game start is
1 player
2 rafiz force
3 rafiz force
4 rafiz force
, when I added 5, and 6 right at the end of this function it returned

5 rafiz force
6 rafiz force

too.


I know it's not right place to ask it ,but if anyone know solution so that "enemy" players can share chart, than this whole mod would be non-neccesary.

Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

Re: When you assign player force upon creation, it works only form second player on

Post by Rafiz »

I think what I will do is I will leave first player in 'player' force and start creating forces only from second player. It should have no downsides, and I should've anyway preserve "forces" as there are only 64 available, but still I think it might be considered bug / unwanted behavior.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: When you assign player force upon creation, it works only form second player on

Post by Rseding91 »

Thanks for the report however testing the exact code you gave me works correctly. When I create a new game the force is set to the new force and it stays there. Every joining player gets a new force as well and nobody ever leaves the force they were on.

That leads me to think you have some other mod installed that's messing with things or some other issue with a local script is causing your problem. Moving to modding help.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”