Scripting Lesson 2
I would like to start this lesson with Difficulty scripting, first to recap over our first lesson. An Event is an instruction that is fired when a condition is meet, this it turn fires a command.
the basics of a script
at the the top of our script we are going to declare some counters, now remember what i said about counters Medieval II or any other TW game for that
matter does not allow us to define variables, so the best we have is a counter which are strings (a fancy word for characters) a string can be made up of letters or numbers.
so lets set our that counter up
type:
declare_counter difficulty
declare_counter difficulty_easy
declare_counter difficulty_medium
declare_counter difficulty_hard
declare_counter difficulty_very_hard
These will be set into the memory when the campaign as started, now with our counters we will need to set up an event, so lets type
monitor_event FactionTurnStart FactionIsLocal
and CampaignDifficulty = easy
set_event_counter difficulty_easy 1
set_event_counter difficulty_medium 0
set_event_counter difficulty_hard 0
set_event_counter difficulty_very_hard 0
terminate_monitor
end_monitor
so lets run thought what we have so far we have declared 5 counters, and we have an Event set to trigger on a factions turn start
but this is not just any faction the condition will wait for the local faction (human player) to take control, hence "FactionIsLocal" and the second
condition is that the game difficulty at the start of the campaign where set to easy.
if both of these conditions are to be true then our counters are set notice the keyword "set_event_counter" this is always follow by a declared counter.
difficulty_easy counter will be set to the value of one, the others to zero.
now we have our counter we can use this to influence how the game runs
If you need help on where to place the script it would go under Mointers
to do this we are going to expand our script some more we will add a new event with a condition of checking if the the local player is england
if the player is england this event will be fired and then a check is made by the IF statement. The IF will return true if the difficulty is set on easy
and in turn will increment the Kings purse with an extra 500 bigs ones so hows that!
monitor_event FactionTurnStart FactionIsLocal
and CampaignDifficulty = easy
set_event_counter difficulty_easy 1
set_event_counter difficulty_medium 0
set_event_counter difficulty_hard 0
set_event_counter difficulty_very_hard 0
terminate_monitor
end_monitor
monitor_event FactionTurnStart FactionIsLocal
and FactionType england
if I_CompareCounter difficulty_easy = 1
increment_kings_purse england 500
end_if
terminate_monitor
end_monitor
another thing to noticed here here is the terminate moniter why is this here? well we only want the script to fire once in the game
if you did remove this on every turn of england would receive a bonus of 500! now we cannot have that can we =D
End_monitor as expalined before tells the game this moniter as finished and is awaiting for the next one to be triggered.
this what your campaign script should look like now.
if you have any questions at this point please ask!
spawn Characters and armies
I now attempt to explain and show you how to spawn an army, the syntax is faction type <faction> and <character description> which
describes the units which are to be spawned much like in the desrc_strat.
spawn_army <faction> <character description>
spawn_army
faction england
character Edward Cracker, named character, age 25, x 73, y 28
traits GoodCommander 2
unit NE Bodyguard exp 1 armour 0 weapon_lvl 0
end
the X, Y are the coordinates of where the army will be spawned its perfectly illegal to spawn an army into the ocean, so don't worry to much about conditions if you want to find the coordinates on the map bring up the console window and type in show_cursorstat and press
enter.
a note spawning generals here will no be placed into a family tree its not possible in case anybody where wondering...
now to put the theory into practice will write an event which will spawn the AI some reinforcements when a settlement is captured
start with the usual monitor_event and the condition is settlementName < settlement> is Paris and the second
condition the human player must be england.
monitor_event GeneralCaptureSettlement SettlementName Paris
and FactionType england
spawn_army
faction france
character Godfrey Mauvoisin, named character, age 35, x 99, y 124
traits GoodCommander 2
unit NE Bodyguard exp 1 armour 0 weapon_lvl 0
end
terminate_monitor
end_monitor
Faction debt money scripts
This weeks assignment
Basic:
The Assignment task is to spawn an army anywhere on the map and then increment that factions Kings purse to support the newly spawned army.
Advanced:
based on the basic question modifily your existing code to give more units if the game is set to easy or hard.
I.E
if the game is set to easy spawn 5 units if the game is set to normal spawn 3 units, if the game is set to hard 1 unit. The best scripts will be placed into the TWC-U gallery.
if you need help getting started pm me.