Fierabras
Emperor
- Joined
- Dec 26, 2006
- Messages
- 1,120
Introduction:
While playing around with BTS Events, I wondered if it was possible to make non-random timed events. After some experimentation I found that it was indeed possible. In this tutorial I will show an example of how it can be achieved.
Explanation:
As I see it (and correct me if I'm wrong) there are 2 tags in the event trigger that determine the randomness of an event being triggered:
<iPercentGamesActive>
<iWeight>
The first determines the percentage that an event is included in a game and the second sets the change of the event occurring in the game. By setting these to the following, I made them non-random.
This means the event is always included (100%) and is always triggered (-1), providing all the requirements are met.
By setting the <bRecurring> tag to 1, the event will be triggered more than once.
The problem now is, that when the requirements are met, the event will trigger each turn. This is where some Python is needed to add a new requirement that isn't possible with the available XML tags.
Let's say you want the event to occur each 10 turns. In the XML for each event trigger there is a tag named <PythonCanDo>. It's this tag you can use to hook in a Python function. In the example below I used:
This function called 'canTriggerZeusSpawn' does not exist yet, so you have to add it to CvRandomEventInterface.py
(create a folder Assets/Python/EntryPoints in your mod and copy the default BTS file CvRandomEventInterface.py to that folder)
The function reads as follows:
For the mathematically challenged
, this uses the modulus operator:
18 % 10 = 8
19 % 10 = 9
20 % 10 = 0
21 % 10 = 1
etc.
So, this function will return true every tenth turn and this return value let's the trigger know the event gets fired.
Example:
Some people might remember the Statue of Zeus from CIV3 that gave free units at certain intervals. With the help of what I have explained above, I have recreated this functionality.
First, set the event trigger's requirement:
This means the event gets triggered for the civ that owns the Statue of Zeus world wonder (only 1 in the game).
Second, set the event
Pretty self-explanatory, but notice that it uses UNITCLASS and not UNIT, which means that civs who have a UU that replaces the axeman, will get 4 of those UU's. For example: if the Greek own the Statue of Zeus, the event will gift 4 phalanxes ("Madness!? This is Sparta!")
Below is a screenshot of all of this in action:

I have added this example as an attachment.
While playing around with BTS Events, I wondered if it was possible to make non-random timed events. After some experimentation I found that it was indeed possible. In this tutorial I will show an example of how it can be achieved.
Explanation:
As I see it (and correct me if I'm wrong) there are 2 tags in the event trigger that determine the randomness of an event being triggered:
<iPercentGamesActive>
<iWeight>
The first determines the percentage that an event is included in a game and the second sets the change of the event occurring in the game. By setting these to the following, I made them non-random.
Code:
<iPercentGamesActive>100</iPercentGamesActive>
<iWeight>-1</iWeight>
This means the event is always included (100%) and is always triggered (-1), providing all the requirements are met.
By setting the <bRecurring> tag to 1, the event will be triggered more than once.
Code:
<bRecurring>1</bRecurring>
The problem now is, that when the requirements are met, the event will trigger each turn. This is where some Python is needed to add a new requirement that isn't possible with the available XML tags.
Let's say you want the event to occur each 10 turns. In the XML for each event trigger there is a tag named <PythonCanDo>. It's this tag you can use to hook in a Python function. In the example below I used:
Code:
<PythonCanDo>canTriggerZeusSpawn</PythonCanDo>
This function called 'canTriggerZeusSpawn' does not exist yet, so you have to add it to CvRandomEventInterface.py
(create a folder Assets/Python/EntryPoints in your mod and copy the default BTS file CvRandomEventInterface.py to that folder)
The function reads as follows:
Code:
def canTriggerZeusSpawn(argsList):
kTriggeredData = argsList[0]
turn = kTriggeredData.iTurn
if (turn % 10 == 0):
return true
return false
For the mathematically challenged

18 % 10 = 8
19 % 10 = 9
20 % 10 = 0
21 % 10 = 1
etc.
So, this function will return true every tenth turn and this return value let's the trigger know the event gets fired.
Example:
Some people might remember the Statue of Zeus from CIV3 that gave free units at certain intervals. With the help of what I have explained above, I have recreated this functionality.
First, set the event trigger's requirement:
Code:
<BuildingsRequired>
<BuildingClass>BUILDINGCLASS_STATUE_OF_ZEUS</BuildingClass>
</BuildingsRequired>
<iNumBuildings>1</iNumBuildings>
This means the event gets triggered for the civ that owns the Statue of Zeus world wonder (only 1 in the game).
Second, set the event
Code:
<UnitClass>UNITCLASS_AXEMAN</UnitClass>
<iNumFreeUnits>4</iNumFreeUnits>
Pretty self-explanatory, but notice that it uses UNITCLASS and not UNIT, which means that civs who have a UU that replaces the axeman, will get 4 of those UU's. For example: if the Greek own the Statue of Zeus, the event will gift 4 phalanxes ("Madness!? This is Sparta!")
Below is a screenshot of all of this in action:

I have added this example as an attachment.