Desync in MP - On player join

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Desync in MP - On player join

Post by TheSAguy »

Hi,

I've gotten some reports of Desync with my NE Expansion mod recently.
I don't play multi player can can't fix test this.

I suspect it's to do with the code that runs with: script.on_configuration_changed
This is what I have:

Code: Select all


function On_Change()
	
--- Expansion Initialization ----	
	if not global.Natural_Evolution_state then
		global.Natural_Evolution_state = "Peaceful"
	end
	if not global.Natural_Evolution_Timer then
		global.Natural_Evolution_Timer = 0
	end
	if not global.Peace_Timer then
		global.Peace_Timer = 0
	end
	if not global.Natural_Evolution_Counter then
		global.Natural_Evolution_Counter = 0
	end


	--- Harder End Game
	---- Rocket Silo Initialization ----	
	if not global.RocketSiloBuilt then
	  global.RocketSiloBuilt = 0
	end

	
	if not global.Total_Phase_Evo_Deduction then
          global.Total_Phase_Evo_Deduction = 0
        elseif global.Total_Phase_Evo_Deduction < 0 then
          global.Total_Phase_Evo_Deduction = 0
	end

	--- Settup Settings
	if not global.NE_Expansion then global.NE_Expansion = {} end
	if not global.NE_Expansion.Settings then global.NE_Expansion.Settings = {} end
	
	global.NE_Expansion.Settings.Harder_Endgame = settings.startup["NE_Harder_Endgame"].value
	global.NE_Expansion.Settings.No_Expansion = settings.startup["NE_No_Expansion"].value

	if #game.players == 1 then
		On_Change_Setup()
	end
	
end



function On_Change_Setup() 
		
	local enemy_expansion = game.map_settings.enemy_expansion
	local unit_group = game.map_settings.unit_group
	
	-- Below 5% evolution, no expansion
	if game.forces.enemy.evolution_factor > 0.05 and global.NE_Expansion.Settings.No_Expansion then
		enemy_expansion.enabled = true
	else
		enemy_expansion.enabled = false
	end
		
		
	---  Initial Expansion Values	
	if not global.enemy_expansion_G then
		global.enemy_expansion_G = false -- 
	end

	----
	if not global.max_expansion_distance_G then
		global.max_expansion_distance_G = enemy_expansion.max_expansion_distance -- Vanilla 7
	end

	if not global.friendly_base_influence_radius_G then
		global.friendly_base_influence_radius_G = 4 -- Vanilla 2
	end
	
	if not global.enemy_building_influence_radius_G then
		global.enemy_building_influence_radius_G = 4 -- Vanilla 2
	end
	
	if not global.settler_group_min_size_G then
		global.settler_group_min_size_G = enemy_expansion.settler_group_min_size -- Vanilla 5
	end
	
	if not global.settler_group_max_size_G then
		global.settler_group_max_size_G = enemy_expansion.settler_group_max_size -- Vanilla 20
	end

	----
	if not global.building_coefficient_G then
		global.building_coefficient_G = 0.15 -- vanilla 0.1
	end
	
	if not global.other_base_coefficient_G then
		global.other_base_coefficient_G = 3.0 -- vanilla 2.0
	end
	
	if not global.neighbouring_chunk_coefficient_G then
		global.neighbouring_chunk_coefficient_G = 0.625 -- vanilla 0.5
	end
	
	if not global.neighbouring_base_chunk_coefficient_G then
		global.neighbouring_base_chunk_coefficient_G = 0.5 -- vanilla 0.4	
	end
	
	if not global.min_group_radius_G then
		global.min_group_radius_G = 3 -- Vanilla 5		
	end	
	
	if not global.max_group_radius_G then
		global.max_group_radius_G = 20 -- Vanilla 30
	end

		
	enemy_expansion.max_expansion_distance = global.max_expansion_distance_G / 2	
	enemy_expansion.friendly_base_influence_radius = global.friendly_base_influence_radius_G	
	enemy_expansion.enemy_building_influence_radius = global.enemy_building_influence_radius_G	
	
	enemy_expansion.settler_group_min_size = global.settler_group_min_size_G / 2
	enemy_expansion.settler_group_max_size = global.settler_group_max_size_G / 2
	---
	enemy_expansion.building_coefficient = global.building_coefficient_G
	enemy_expansion.other_base_coefficient = global.other_base_coefficient_G
	enemy_expansion.neighbouring_chunk_coefficient = global.neighbouring_chunk_coefficient_G
	enemy_expansion.neighbouring_base_chunk_coefficient = global.neighbouring_base_chunk_coefficient_G
	---
	unit_group.max_group_radius = global.max_group_radius_G
	unit_group.min_group_radius = global.min_group_radius_G
		
end



I don't know if or all of On_Change() or On_Change_Setup() is strictly needed.

The idea was to make sure the settings I've altered are all carried over when something changes.

I recently added the player count check before On_Change_Setup() so it only fires for the first player, but that did not seem to fix all errors.

Code: Select all

	if #game.players == 1 then
		On_Change_Setup()
	end

Could someone possibly look at this and see what I messed up.
Complete Control file attached.
Thanks.
Attachments
control.lua
Control
(35.35 KiB) Downloaded 19 times

Post Reply

Return to “Modding help”