Trigger event only in a scenario

wotan321

Emperor
Joined
Oct 25, 2001
Messages
1,228
Location
NC, USA
I'm enjoying a mod with a couple scenarios. I want to add events that occur in a particular scenario, but not in general games. Is there a python way to do that, or something in the EventTrigger xml file?

Any help is appreciated.
 
A slightly convoluted approach that will definitely work:
- find something that is unique for the scenario (e.g. player 0 is America, or the (0, 0) tile is grassland etc.)
- write a Python function in Python/EntryPoints/CvRandomEventInterface.py that checks for the above, now you have a function that "knows" which scenario it is
- in XML/Events/CIV4EventTriggerInfos.xml, put the name of the function in the <PythonCanDo> tag. The game will use the function to check if the event can trigger. If the function only returns True if it is the desired scenario, then the event can only trigger in that scenario.

I don't think there is an easier way to do this.

For example, I have this event:
Code:
<EventTriggerInfo>
    <Type>EVENTTRIGGER_REFORMATION</Type>
    <WorldNewsTexts/>
    <TriggerTexts>
    <TriggerText>
    <Text>TXT_KEY_EVENT_TRIGGER_REFORMATION</Text>
    <Era>NONE</Era>
    </TriggerText>
    </TriggerTexts>
    <bSinglePlayer>0</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/>
    <iNumBuildings>0</iNumBuildings>
    <iNumBuildingsGlobal>0</iNumBuildingsGlobal>
    <iNumPlotsRequired>0</iNumPlotsRequired>
    <bOwnPlot>0</bOwnPlot>
    <iPlotType>-1</iPlotType>
    <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_REFORMATION_1</Event>
        <Event>EVENT_REFORMATION_2</Event>
        <Event>EVENT_REFORMATION_3</Event>
    </Events>
    <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>canTriggerReformation</PythonCanDo>
    <PythonCanDoCity/>
    <PythonCanDoUnit/>
    <PythonCallback/>
</EventTriggerInfo>

Which triggers the Protestant reformation, which requires a civ to have a city with Catholic religion, I defined the canTriggerReformation function in CvRandomEventInterface.py:

Code:
def canTriggerReformation(argsList):
    kTriggeredData = argsList[0]
    iPlayer = kTriggeredData.ePlayer

    if utils.getScenario() == i1700AD: return False

    if utils.getHumanID() != iPlayer: return False

    bCatholicCity = False
    for city in PyHelpers.PyPlayer(iPlayer).getCityList():
        if city.GetCy().isHasReligion(iCatholicism):
        bCatholicCity = True
        break

    if not bCatholicCity: return False

    if gc.getGame().isReligionFounded(iProtestantism):
        if gc.getGame().getReligionGameTurnFounded(iProtestantism)+2 < gc.getGame().getGameTurn():
            return False

    return gc.getGame().isReligionFounded(iProtestantism)
 
Last edited:
I didn't know about this method, it returns the full path to your script or scenario file in all lower case. Assuming your scenario is called Wotan321, you could do:

Code:
if gc.getMap().getMapScriptName().endswith("wotan321.civbeyondswordwbsave"): ...

I suggest starting the scenario and bringing up the Python console (shift + ~) to test it.
 
That does the trick, it works just fine.

In the Civ4EventTriggerInfos.xml file for the event, I add a <PythonCanDo>canTriggerHelp02</PythonCanDo>

Then in the python\EntryPoints\CVRandomEventInterface.py I add:

Code:
def canTriggerHelp02(argsList):
    kTriggeredData = argsList[0]
    player = gc.getPlayer(kTriggeredData.ePlayer)
        
    if (player.isAlive() and player.isHuman() and gc.getMap().getMapScriptName().endswith("wotan321.CivBeyondSwordWBSave")):
        return true
    return false

where wotan321.CivBeyondSwordWBSave is the name of the scenario.
 
Great!
 
Back
Top Bottom