Historical events coding help

Ok, this is basically what Python is for. You hook the trigger up with a Python script returning a True/False (boolean) value, which you get with CyPlayer.isAlive(). The CyPlayer object you of course get with CyGlobalContext.getPlayer() where you supply the PlayerType of the Afghans as the parameter.
 
Would it look like this or close?

Spoiler :
def canTriggerResup(argsList):
kTriggeredData = argsList[0]
player = gc.getPlayer(kTriggeredData.ePlayer)
turn = kTriggeredData.iTurn
isAlive = CyGlobalContext.getPlayer()

if (player.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_SOVIET")):

if (turn == 26):
return true
return false

if (CyPlayer.isAlive() == gc.getInfoTypeForString("CIVILIZATION_MUJAHADEEN")):
return false
return true

return false
 
No, not quite. :p Actually, not at all.

If you tell me what the kTriggeredData.ePlayer value corresponds to, I could get this done for you. Is it the PlayerType of the Soviets or the PlayerType of the Afghans?

Also, ALWAYS use the
Code:
 tags when posting code. Otherwise it means nothing, basically. Because the indentation is what determines the flow of the script.
 
KtriggeredData.ePlayer goes with the Soviets. The event triggers for and affects the Soviet player. The indentation might be off:

Code:
def canTriggerResup(argsList):
kTriggeredData = argsList[0]
player = gc.getPlayer(kTriggeredData.ePlayer)
turn = kTriggeredData.iTurn
isAlive = CyGlobalContext.getPlayer()

       if (player.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_SOVIET")):

       if (turn == 26):
           return true
       return false

       if (CyPlayer.isAlive() == gc.getInfoTypeForString("CIVILIZATION_MUJAHADEEN") ):
       return false
return true

return false
 
And what is the PlayerType of the Afghans? Look in the WBS file for the player number (those start with zero for the first player).

Anyway, this is probably what it should look like:
Code:
	def canTriggerResup(argsList):
		kTriggeredData = argsList[0]
		if kTriggeredData.iTurn == 26:
			return gc.getPlayer([COLOR="Red"]iMujahedin[/COLOR]).isAlive()
		return False
Now, replace iMujahedin with the PlayerType of the Afghans.

I'm guessing that you don't even need to bother with the game turn condition here. Isn't there a pre-existing trigger for game turn that you can enable from the XML?

The code you posted is, of course, nonsensical. You're clearly just guessing. You would never be able to "figure it out" without actually knowing programming.
 
Well the player is 15=Afghans.

Code:
def canTriggerResup(argsList):
		kTriggeredData = argsList[0]
		if kTriggeredData.iTurn == 26:
			return gc.getPlayer(15).isAlive()
		return False

XML won't let you specify which turn or civ to make the trigger though. I was just guessing. I was thinking the code might look like this then:

Code:
def canTriggerResup(argsList):
		kTriggeredData = argsList[0]
                          player = gc.getPlayer(kTriggeredData.ePlayer)
		if kTriggeredData.iTurn == 26:
			return gc.getPlayer(15).isAlive()
		return False

                          if (player.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_SOVIET")):         
                          return false
 
No, that still makes no sense, at all. Sorry.

If you enable Python exceptions and error pop-ups in the .ini file you would see how your code would simply not work. In fact, it would make your mod fail to initialize.

Also know that indentation isn't for show - it actually determines flow. In CvRandomEventsInterface.py each level of indentation equals one tab - nothing more and nothing less. The first level is zero indentation (which I messed up in my previous sample code). And you can't mix blank spaces and tabs.

So what you need is probably something along these lines:
Code:
def canTriggerResup(argsList):
	kTriggeredData = argsList[0]
	if kTriggeredData.iTurn == 26 and kTriggeredData.ePlayer == [COLOR="Red"]iSoviets[/COLOR]:
		return gc.getPlayer(15).isAlive()
	return False
You, of course, substute iSoviets with the proper PlayerType.

And finally, the above isn't the only way to express the exact same logic. Its just one way to make it work.

By the way, could you post the XML entry for the trigger in question?
 
Here is the Trigger XML Code. I actually provided the wrong python event, but everything else is the same except the turn number and the name of the Python event, so it is not so big of a deal.

Spoiler :
Code:
                                     <EventTriggerInfo>
			<Type>EVENTTRIGGER_SVT</Type>
			<WorldNewsTexts>
				<Text>TXT_KEY_EVENTTRIGGER_SVT</Text>
			</WorldNewsTexts>
			<TriggerTexts>
				<TriggerText>
					<Text>TXT_KEY_EVENT_TRIGGER_SVT</Text>
					<Era>NONE</Era>
				</TriggerText>
			</TriggerTexts>
			<bSinglePlayer>1</bSinglePlayer>
			<iPercentGamesActive>100</iPercentGamesActive>
			<iWeight>-1</iWeight>
			<bProbabilityUnitMultiply>0</bProbabilityUnitMultiply>
			<bProbabilityBuildingMultiply>0</bProbabilityBuildingMultiply>
			<Civic>NONE</Civic>
			<iMinTreasury>0</iMinTreasury>
			<iMinPopulation>0</iMinPopulation>
			<iMaxPopulation>0</iMaxPopulation>
			<iMinMapLandmass>0</iMinMapLandmass>
			<iMinOurLandmass>0</iMinOurLandmass>
			<iMaxOurLandmass>-1</iMaxOurLandmass>
			<MinDifficulty>NONE</MinDifficulty>
			<iAngry>0</iAngry>
			<iUnhealthy>0</iUnhealthy>
			<UnitsRequired/>
			<iNumUnits>0</iNumUnits>
			<iNumUnitsGlobal>0</iNumUnitsGlobal>
			<iUnitDamagedWeight>0</iUnitDamagedWeight>
			<iUnitDistanceWeight>0</iUnitDistanceWeight>
			<iUnitExperienceWeight>0</iUnitExperienceWeight>
			<bUnitsOnPlot>0</bUnitsOnPlot>
			<BuildingsRequired>
			</BuildingsRequired>
			<iNumBuildings>0</iNumBuildings>
			<iNumBuildingsGlobal>0</iNumBuildingsGlobal>
			<iNumPlotsRequired>0</iNumPlotsRequired>
			<bOwnPlot>0</bOwnPlot>
			<iPlotType>-1</iPlotType>
			<FeaturesRequired>
			</FeaturesRequired>
			<TerrainsRequired/>
			<ImprovementsRequired/>
			<BonusesRequired/>
			<RoutesRequired/>
			<ReligionsRequired/>
			<iNumReligions>0</iNumReligions>
			<CorporationsRequired/>
			<iNumCorporations>0</iNumCorporations>
			<bPickReligion>0</bPickReligion>
			<bStateReligion>0</bStateReligion>
			<bHolyCity>0</bHolyCity>
			<bPickCorporation>0</bPickCorporation>
			<bHeadquarters>0</bHeadquarters>
			<Events>
				<Event>EVENT_SVT</Event>
			</Events>
			<PrereqEvents>
				<Event>EVENT_OPCY</Event>
			</PrereqEvents>
			<bPrereqEventPlot>0</bPrereqEventPlot>
			<OrPreReqs/>
			<AndPreReqs/>
			<ObsoleteTechs/>
			<bRecurring>0</bRecurring>
			<bTeam>0</bTeam>
			<bGlobal>0</bGlobal>
			<bPickPlayer>0</bPickPlayer>
			<bOtherPlayerWar>0</bOtherPlayerWar>
			<bOtherPlayerHasReligion>0</bOtherPlayerHasReligion>
			<bOtherPlayerHasOtherReligion>0</bOtherPlayerHasOtherReligion>
			<bOtherPlayerAI>0</bOtherPlayerAI>
			<iOtherPlayerShareBorders>0</iOtherPlayerShareBorders>
			<OtherPlayerHasTech>NONE</OtherPlayerHasTech>
			<bPickCity>0</bPickCity>
			<bPickOtherPlayerCity>0</bPickOtherPlayerCity>
			<bShowPlot>0</bShowPlot>
			<iCityFoodWeight>0</iCityFoodWeight>
			<PythonCanDo>canTriggerSvt</PythonCanDo>
			<PythonCanDoCity/>
			<PythonCanDoUnit/>
			<PythonCallback/>
		            </EventTriggerInfo>

I'll try out the code and see what happens.<----Update. Worked like a charm in game. Thanks so much!!
 
Ok, now we're both learning! :goodjob:
 
IIRC you also needed an event that caused a player to declare war on another at a set date. I pointed out that there are some tricks involved, and one such thing to consider is War Plans and WarPlanTypes. Another thing to consider is that "Civs" don't declare war on anyone - not even players. Its actually a team thing.

What I would like to suggest, is actually that you don't utilize the Random Events Interface on this particular effect. Instead, you could add some code directly into CvEventManager and spare yourself all the aggravation of having to deal with setting up the XML.

Find the definition for the onBeginGameTurn() method and add the highlighted code:
Code:
	def onBeginGameTurn(self, argsList):
		'Called at the beginning of the end of each turn'
		iGameTurn = argsList[0]

[B]		if iGameTurn == 0:
			gc.getTeam(gc.getPlayer([COLOR="Red"]iIraq[/COLOR]).getTeam()).AI_setWarPlan(gc.getPlayer([COLOR="Red"]iIran[/COLOR]).getTeam(), [COLOR="Red"]iWarPlanPrepare[/COLOR])
		elif iGameTurn == [COLOR="Red"]iWarTurn[/COLOR]:
			gc.getTeam(gc.getPlayer([COLOR="Red"]iIraq[/COLOR]).getTeam()).declareWar(gc.getPlayer([COLOR="Red"]iIran[/COLOR]).getTeam(), True, [COLOR="Red"]iWarPlanExecute[/COLOR])[/B]

		CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
Now, the red variable names either need to be defined as integer values - or replaced with integer values. (Simply referring to names that haven't been defined will cause the Python to throw an exception.) I suggest using WARPLAN_PREPARING_TOTAL (3) for iWarPlanPrepare and WARPLAN_TOTAL (3) for iWarPlanExecute, but its your scenario and your design.

The above script could of course be refined in any number of ways, but this would probably be the bare basics of what you need.
 
I also noticed this warplanes code in the WWII in the Pacific, but it didn't make any sense to me then. Thanks for the information and your help once again. XML events can help you declare war, but you can only narrow it down vaguely based on touching borders and religion I believe.
 
XML events can help you declare war, but you can only narrow it down vaguely based on touching borders and religion I believe.
Yeah? But then it would surely be possible to simply create a game turn based Python callback.
 
Top Bottom