Event scripting linked to the EDU
DO not read this lesson untill you have finished the other two or may have difficulty's in progressing and getting things working, at this point you should have the basics of Events and conditions, but Events and conditions does not just end with the campaign script other files can be tied in such as the export_descr_buildings.txt (EDB) for instance if i wanted to write a script allowed me to build a unit but i must be holding London i would go about it like this...
Code:
monitor_conditions not I_SettlementOwner London = england
and I_EventCounter holding_london == 1
set_event_counter holding_london 0
end_monitor
monitor_conditions I_SettlementOwner London = england
and I_EventCounter holding_london == 0
add_events
event counter holding_london
date 0
end_add_events
end_monitor
so lets start by opening a fresh copy of our campaign_script.txt and copy the about copy in.
this script monitors a condition called I_SettlementOwner and compares it to a faction testing if London is not owned by england
this sets our event counter holding_london to 0 once this is set to zero the unit "peasent" is no longer recruitable think of this as a switch to toggle the event.
Now to link the event to the EDB open your export_descr_buildings.txt
to link this you will need include the event counter using this line of code
Code:
and event_counter holding_london 1
this should be placed at the end of the units bracket.
place this line under the garrison_quarters
Code:
recruit_pool "Peasants" 1 0.5 4 0 requires factions { england, } and event_counter holding_london 1
and remove england from the code below
Code:
recruit_pool "Peasants" 1 0.7 6 0 requires factions { england, france, hre, denmark, spain, portugal, milan, venice, papal_states, Normans, Saxons, }
The campaign
The peasant unit is no longer available due to England losing London
Recapturing the settlement
England recaptures London and on the next turn the unit is available
Religion scripting( changing a Factions Religion during a campaign)
so this part of the lesson we are going to look at how to change a faction religion and i don't mean just changing one line of the descr_sm_factions.txt
Code:
monitor_event FactionTurnStart
add_events
event counter byzantium_conversion_accepted
event counter byzantium_conversion_declined
date 0
end_add_events
terminate_monitor
end_monitor
first thing to set up is an event counter this is acting as our yes or no this we be set up on a the first turn start once and never again hence the terminate_monitor.
Code:
monitor_event FactionTurnStart FactionType byzantium
if I_NumberOfSettlements byzantium < 10
historic_event byzantium_conversion true factions { byzantium, }
terminate_monitor
end_if
end_monitor
now we monitor Byzantium's turn start giving the condition of faction type inside this monitor we have an IF statement setup to check the amount of settlements the Byzantines have, and we check for less then 10 this is just a number i decided on you could chose any but this where convenient fro testing purposes, and as the more settlement this faction loses to its catholic neighbors the more likely the faction will convert to save them self's.
anyway inside this if statement we have the call to the historic_events file and creates a YES/NO event for the faction Byzantium notice the keyword true this is needed for the event to display.
Code:
monitor_conditions I_EventCounter byzantium_conversion_accepted = 1
set_religion byzantium catholic
retire_characters byzantium priest
change_population_religion byzantium catholic 75 orthodox
terminate_monitor
end_monitor
now to monitor what our player select yes or no if yes the counter called byzantium_conversion_accepted receives a value of 1 and triggers the condition this monitor handles the command to change the faction over
set_religion [target faction][target religion]
retire_characters [target faction] [label]
change_population_religion [target faction] [target religion] [amount] [religion]
also the following code is needed when setting up add_events place this into historic_events.txt or you will receive a ctd just before the campaign finishes loading.
Code:
{BYZANTIUM_CONVERSION_BODY} some conversion text here
{BYZANTIUM_CONVERSION_TITLE} Will the byzantines convert?
Check Religion before conversion
the add_events box for yes or no
Check Religion after conversion
and now the Byzantines can crusade
now with this working you can create and add a new unit into the game using the counter byzantium_conversion_accepted 1 in the EDB, Byzantines could have access to new units after converting think of this as an extra bonus.