Results 1 to 3 of 3

Thread: Implementing a script which prevents player to lay siege without a general

  1. #1

    Icon5 Implementing a script which prevents player to lay siege without a general

    I created the following script in data/world/maps/campaign/imperial_campaign/playerSiegeWithGeneralsOnly.txt

    Code:
    script
    
    
    monitor_event ScrollOpened ScrollOpened seige_scroll
    and I_AgentSelected general
        disable_cursor
        select_ui_element siege_end_button
        simulate_mouse_click lclick_down
        simulate_mouse_click lclick_up
        enable_cursor
    end_monitor
    
    
    end_script
    In descr.strat.txt, I appended the following at the bottom:

    Code:
    ...script
    playerSiegeWithGeneralsOnly.txt
    It should work but it does not: When I take any faction and send an army without a general to a siege, I can besiege it as always. Instead, this script should automatically click abort siege when there is no general in my besieging army.

    This is the scriptling_log.txt output when I test this feature - it shows no error message

    Code:
    (playersiegewithgeneralsonly.txt) (SCOPE) Entering new scope, end token is end_script
    (playersiegewithgeneralsonly.txt::3) (CREATE) Creating token monitor_event
    (playersiegewithgeneralsonly.txt) (SCOPE) Entering new scope, end token is end_monitor
    (playersiegewithgeneralsonly.txt::5) (CREATE) Creating token disable_cursor
    (playersiegewithgeneralsonly.txt::6) (CREATE) Creating token select_ui_element
    (playersiegewithgeneralsonly.txt::7) (CREATE) Creating token simulate_mouse_click
    (playersiegewithgeneralsonly.txt::8) (CREATE) Creating token simulate_mouse_click
    (playersiegewithgeneralsonly.txt::9) (CREATE) Creating token enable_cursor
    (playersiegewithgeneralsonly.txt) (SCOPE) Got end token end_monitor, exiting scope
    (playersiegewithgeneralsonly.txt) (SCOPE) Got end token end_script, exiting scope
    CPU: AMD Ryzen 5 5600X 4,6 Ghz AM4 | GPU: 2x NVIDIA GeForce RTX 3060Ti Gainward Ghost OC 8GB GDRR6 | RAM: Corsair Vengeance RGB PRO DDR4 3600 Mhz C18 16 GB | SSD: PNY XLR8 CS3030 4TB M.2 NVMe 3 GB/s | PSU: be quiet! Straight Power 11 Platinum 550 Watt | MB: Asus ROG Strix B550-F Gaming WiFi | Case: be quiet! Silent Base 801 Silver


    Long: New York Stock Exchange: MO, XOM, AAL, AMZN, FB, MSFT, GOOGL, AMD, CRM | Wiener Börse: POST, BG, ADKO, UBS | London Stock Exchange: BP, BATS | Hong Kong Stock Exchange: 3988, 601318 | Euronext Paris: ORA, FP | Bolsa de Madrid: ELE | Coinbase: BTC
    Short: -

  2. #2

    Default Re: Implementing a script which prevents player to lay siege without a general

    Ok I managed to bring this sort-of to work but the player can still attack a city with a non-general-army when it has no walls or the army has onagers/ballistae:

    imperial_campaign/playerSiegeWithGeneralsOnly.txt

    Code:
    script
    declare_counter dummy_f 
    declare_counter dummy_r
    monitor_event ScrollOpened ScrollOpened seige_scroll
    and I_AgentSelected general
        select_ui_element siege_end_button
        simulate_mouse_click lclick_down
        simulate_mouse_click lclick_up
        message_prompt
            {
            flag_counter dummy_f
            result_counter dummy_r
            title 489C337C215FE8600B1CC0568AEDD583B3991911_TITLE
            body 489C337C215FE8600B1CC0568AEDD583B3991911_BODY
            image adoption
            }
        
    end_monitor
    end_script
    text/expanded_bi.txt

    Code:
    ...
    {489C337C215FE8600B1CC0568AEDD583B3991911_TITLE}Siege aborted
    {489C337C215FE8600B1CC0568AEDD583B3991911_BODY}Your besieging army ended the siege due to a lack of competence and logistics involved in the operation. You need to come back with a general leading your troops.
    imperial_campaign/descr_strat.txt

    Code:
    ...
    script
    playerSiegeWithGeneralsOnly.txt
    However it works only if the besieging army with no general has no siege units like onagers or ballistae. Because it actually can launch an attack in the first time the player opens the siege scroll for that siege. Without an onager or ballista, you cannot attack of course.
    The moment you re-open that siege scroll (for example next turn when you built ladders or rams and want to attack), the siege is aborted and the player gets a message that siege is only possible with general in your army.

    Any idea how to make it work so that armies without a general get siege aborted immediately after start and not when you show siege scroll a 2nd time?
    CPU: AMD Ryzen 5 5600X 4,6 Ghz AM4 | GPU: 2x NVIDIA GeForce RTX 3060Ti Gainward Ghost OC 8GB GDRR6 | RAM: Corsair Vengeance RGB PRO DDR4 3600 Mhz C18 16 GB | SSD: PNY XLR8 CS3030 4TB M.2 NVMe 3 GB/s | PSU: be quiet! Straight Power 11 Platinum 550 Watt | MB: Asus ROG Strix B550-F Gaming WiFi | Case: be quiet! Silent Base 801 Silver


    Long: New York Stock Exchange: MO, XOM, AAL, AMZN, FB, MSFT, GOOGL, AMD, CRM | Wiener Börse: POST, BG, ADKO, UBS | London Stock Exchange: BP, BATS | Hong Kong Stock Exchange: 3988, 601318 | Euronext Paris: ORA, FP | Bolsa de Madrid: ELE | Coinbase: BTC
    Short: -

  3. #3

    Default Re: Implementing a script which prevents player to lay siege without a general

    Now with a much better version, which works even if your army has a general with onagers and ballistae. Use that:

    Code:
    script
    
    declare_counter dummy_r
    declare_counter dummy_f
    declare_counter  LastSelectedArmyHasGeneral 0
    declare_counter  SiegeScrollOpen 0
    
    
    monitor_event CharacterSelected
        if I_AgentSelected family
            set_counter LastSelectedArmyHasGeneral 1
        end_if
        if I_AgentSelected general
            set_counter LastSelectedArmyHasGeneral 0
        end_if
    end_monitor
    monitor_event ScrollClosed ScrollClosed seige_scroll
        set_counter SiegeScrollOpen 0
    end_monitor
    monitor_event ScrollOpened ScrollOpened seige_scroll
        set_counter SiegeScrollOpen 1
    end_monitor
    
    
    monitor_event ScrollOpened ScrollOpened seige_scroll
        if I_CompareCounter LastSelectedArmyHasGeneral = 0
            and I_CompareCounter SiegeScrollOpen = 1
            ui_flash_start siege_end_button circle
        select_ui_element siege_end_button
        simulate_mouse_click lclick_down
        simulate_mouse_click lclick_up
        message_prompt
            {
            flag_counter dummy_f
            result_counter dummy_r
            title 0CAED7883C615CDBC83E0B2C0B5272D9CABC39B8_TITLE
            body 0CAED7883C615CDBC83E0B2C0B5272D9CABC39B8_BODY
            image adoption
            }
        end_if
    end_monitor
    
    
    end_script
    You have to use counters (custom variables) for every state you check the condition. Do not check if a scroll is opened directly, check that and write the result in a counter and then for your conditions, use the counter instead.
    CPU: AMD Ryzen 5 5600X 4,6 Ghz AM4 | GPU: 2x NVIDIA GeForce RTX 3060Ti Gainward Ghost OC 8GB GDRR6 | RAM: Corsair Vengeance RGB PRO DDR4 3600 Mhz C18 16 GB | SSD: PNY XLR8 CS3030 4TB M.2 NVMe 3 GB/s | PSU: be quiet! Straight Power 11 Platinum 550 Watt | MB: Asus ROG Strix B550-F Gaming WiFi | Case: be quiet! Silent Base 801 Silver


    Long: New York Stock Exchange: MO, XOM, AAL, AMZN, FB, MSFT, GOOGL, AMD, CRM | Wiener Börse: POST, BG, ADKO, UBS | London Stock Exchange: BP, BATS | Hong Kong Stock Exchange: 3988, 601318 | Euronext Paris: ORA, FP | Bolsa de Madrid: ELE | Coinbase: BTC
    Short: -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •