OOS Error after using setHasTech

It happened again with pCity.setOccupationTimer(). Here's the working code. I figured I'll keep updating this with instances where the basic function doesn't sync in case anyone in the future searches for them.

Code:
	def onCityAcquiredAndKept(self, argsList):
		'City Acquired and Kept'
		iOwner,pCity = argsList
##############################################
##     Benevolent Unrest Halving Start      ##
##############################################
		pPlayer = gc.getPlayer(pCity.getOwner())
		iPlayer = pCity.getOwner()
		iCity = pCity.getID()
		if pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_BENEVOLENT")):
			iUnrest = pCity.getOccupationTimer()
			iUnrestNew = iUnrest / 2
			CyMessageControl().sendModNetMessage(2, iPlayer, iCity, iUnrestNew, 0)
			iUnrestDifference = iUnrest - iUnrestNew
			sCityName = pCity.getName()
			iX = pCity.getX()
			iY = pCity.getY()
			CyInterface().addMessage(iPlayer,False,15,"Moderate factions in %s acknowledge your benevolence and pledge to reduce civil unrest by %s turns." % (sCityName, str(iUnrestDifference)),'',0,'Art/Interface/Buttons/General/ping.dds',ColorTypes(gc.getInfoTypeForString("COLOR_WHITE")), iX, iY, True,True)
##############################################
##     Benevolent Unrest Halving End        ##
##############################################
		CvUtil.pyPrint('City Acquired and Kept Event: %s' %(pCity.getName()))

Code:
	def onModNetMessage(self, argsList):
		'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
		
		iData1, iData2, iData3, iData4, iData5 = argsList

		if iData1 == 2:
			# change city's unrest #pCity.setOccupationTimer(iUnrestNew) #CyMessageControl().sendModNetMessage(2, iPlayer, iCity, iUnrestNew, 0)
			pPlayer = gc.getPlayer(iData2)	
			city = pPlayer.getCity(iData3)
			city.setOccupationTimer(iData4)		
		
		print("Modder's net message!")
		
		CvUtil.pyPrint( 'onModNetMessage' )
 
Wouldn't it make sense to set up a git server to host all the changes? Alternatively figure out if there is an "official" one you can join/fork.

Now you solved 3 OOS issues and it's possible more would come. Asking everybody to look through this thread would likely be a task, which is too demanding for quite a lot of people.

Possible bug: shouldn't the message be displayed in onModNetMessage rather than onCityAcquiredAndKept? While it may not matter much, it does remove the risk that the message fails to be displayed for the player it is intended for.

Also suiting for this thread: DLL network sync takes place in CvMessageControl.cpp and CvMessageData.cpp. Here you can make new package formats and not be restricted to just 5 ints. Using a savegame like coding format, you can transmit whatever you like, seemingly without limitations. This is where you go if you say need to send 8 ints or strings or anything else not fitting into the vanilla package system. The power to define the variables comes at a price though. Coding complexity is a bit higher than just using a predefined format.
 
Back
Top Bottom