Sorry this is so late guys, I have really had a tough time the last 2 weeks and my house is being destroyed by contractors after that monster hail storm.
This lesson focuses on the user interface, and how to detect when buttons have been pressed or scrolls have been opened or closed. You can then use this to give the player more control over the game. I use methods like this in several of my scripts, most notably my Banking script and my Hire Ancillaries script, but you can use them for anything. Although you can only use the Accept/Decline scroll in Kingdoms, you can still use other scrolls to set counters and and give the player yes/no choices by detecting which buttons they push. As your scripts get more complicated, you will probably be using historic_events yo give the player instructions and choices. However popping that event every time a player clicks TurnEnd gets annoying. Players will get tired of seeing the same message over and over and over. If we tie that to a button press that the player can call anytime he wants we will avoid some of that.
The first one I will demonstrate is steal_esc_key. We will use that function to pop a historic_event. I have used this a few times to give players instructions on how certain parts of a mod runs. For example if you tie a command to other buttons, you want a place the player can view instructions on how to use your script without having to look it up in your posts about your mod, or reading a manual. Once we write this script, all the player has to do to get instructions for other parts of your script is press the Esc key.
If you read the Docudemons, you will see the command for steal_esc_key, and you will notice that once the event has happened, it returns the Esc keys default function. This is done so that the player can use the Esc key to bring up the normal options such as Save and Exit. We have to keep this in mind and reset the key a maximum of once per turn. If we reset the Esc key every time someone presses it then we will remove the ability of the player to get to the normal function of the key, which we do not want to do. This script will show the instructions the first time the Esc key is pressed, the second time the Esc key is pressed the player will get the normal options scroll. The script looks like this:
Inside our historic event we can write instructions on how the other scroll/buttons are used.Code:monitor_event FactionTurnStart FactionIsLocal steal_esc_key on end_monitor monitor_event EscPressed historic_event instructions end_monitor
Now we will do something with the buttons inside the settlement scroll. If we have "Always show settlement details" enabled then there are 6 buttons we can use for custom scripting, and you can also detect when the tax rate is changed. The available buttons are:
Show Trade Summary - advanced_stats_show_trade_button
Set capital - advanced_stats_set_as_capital_button
Locate Settlement - garrison_info_zoom_to_button
Building Browser - building_browser_button
Ask Advisor - show_construction_advice_button OR show_recruitment_advice_button depending which tab is selected
Show Settlement Details - settlement_stats_button
For other buttons and scrolls check the UI Elements tab of the Ultimate Docudemons. I have written a script and historic_events for each of these buttons that will detect when they are pressed. Put this in your campaign_script and your historic_events file and run the game to make sure everything works and the events fire when you press the buttons.
historic_events;
Code:{INSTRUCTIONS_BODY}Instructions will go here. {INSTRUCTIONS_TITLE}Custom Script Instructions {SETTLEMENT_ZOOM_BODY}Settlement Zoom button pressed {SETTLEMENT_ZOOM_TITLE}Settlement Zoom {SHOW_TRADE_BODY}Show Trade stats button pressed {SHOW_TRADE_TITLE}Trade Stats Button {SET_CAPITAL_BODY}Set Capital button pressed {SET_CAPITAL_TITLE}Set Capital {BUILDING_BROWSER_BODY}Building Browser button pressed {BUILDING_BROWSER_TITLE}Building Browser {ASK_ADVISOR_BODY}Ask Advisor button pressed {ASK_ADVISOR_TITLE}Ask Advisor {SETTLEMENT_DETAILS_BODY}Show settlement details pressed {SETTLEMENT_DETAILS_TITLE}Settlement Details
And in campaign_script:
Code:monitor_event FactionTurnStart FactionIsLocal steal_esc_key on end_monitor monitor_event EscPressed historic_event instructions end_monitor monitor_event ButtonPressed ButtonPressed garrison_info_zoom_to_button historic_event settlement_zoom end_monitor monitor_event ButtonPressed ButtonPressed advanced_stats_show_trade_button historic_event show_trade end_monitor monitor_event ButtonPressed ButtonPressed advanced_stats_set_as_capital_button historic_event set_capital end_monitor monitor_event ButtonPressed ButtonPressed building_browser_button historic_event building_browser end_monitor monitor_event ButtonPressed ButtonPressed settlement_stats_button historic_event settlement_details end_monitor monitor_event ButtonPressed ButtonPressed show_construction_advice_button historic_event ask_advisor end_monitor
Now for the hard part, figuring out something to do with the buttons. This I will leave largely up to you, as there are so many options, but I will give you some ideas. You can use this to borrow money, for instance you can add_money when the Zoom to settlement button is pressed, and subtract money when building_browser button is pressed. To do something like this your script would look similar to this:
button pressed Zoom to settlement - add_money 20000
and I_CompareCounter money_borrowed = 0
set_counter money_borrowed 1
button pressed Building Browser
and I_CompareCounter money_borrowed = 1
add_money -20000
set_counter money_borrowed 0
This would allow the player to borrow money as long as he didnt already have outstanding debt, and allow him to repay the loan. Obviously I didnt fully flesh that out, but you should be able to figure out the rest from there.
Or you could use it to hire emergency troops, at an outrageous cost.
settlement under siege
button pressed Zoom to settlement
create_unit
add_money -5000
Or you could use a combination of buttons pressed in a specific order to do something like create a building. This would help prevent someone from doing something by accident.
monitor event SettlementSelected
set_counter stage 0
button pressed Zoom to settlement
set_counter stage 1
button pressed Building Browser
and I_CompareCounter stage = 1
set_counter stage 2
button pressed Settlement Stats Button
and I_CompareCounter stage = 2
create building MegaBuilding
Your task is figure out something cool to do with at least two buttons, and to have instructions on how the script runs tied to the Esc key. This is very open ended and limited only by your imagination and the scripting engine. You can use the buttons on the settlement scroll, or the buttons on the character scroll, or even the buttons on the strat map such as the Finances buttons or mini map zoom in/out buttons.