Modding Q&A [For Quick Questions and Answers]

Users who are viewing this thread

Status
Not open for further replies.
I want to iterate menu options using a try_for_range. For example, I want a menu option for every lord in a given faction, similar to the repeat_for_troops or repeat_for_factions for module_dialogs.

Annoyingly this can't be done with module_game_menus.py as far as I know. Could anyone tell me how I'd do the same thing with module_presentations, or if there are any examples I could use? I couldn't find any even after searching the entire file for try_for_range's.
 
jacobhinds said:
I want to iterate menu options using a try_for_range. For example, I want a menu option for every lord in a given faction, similar to the repeat_for_troops or repeat_for_factions for module_dialogs. Annoyingly this can't be done with module_game_menus.py as far as I know.

If your lords-factions aren't dynamic, you could use Python to code it 'lazily' e.g.:
Code:
#### export/import NPCs begin ####
  ("export_import_npcs", mnf_enable_hot_keys,
   "Please choose a character, then press the C key to view and export or import the chosen character history.^^You choose {reg0?{s0}:none}.",
   "none",
    [
      (assign, reg0, "$g_player_troop"),
      (str_store_troop_name, s0, "$g_player_troop"),
    ],
    [
      ("export_import_back",[],"Go back",
        [
          (assign, "$g_player_troop", "trp_player"),
          (set_player_troop, "$g_player_troop"),
          (jump_to_menu, "mnu_camp_action"),
        ]
      ),
    ]+[("export_import_npc"+str(x+1),
        [
          (store_add, ":dest_npc", "trp_npc1", x),
          (str_store_troop_name, s0, ":dest_npc"),
        ], "{s0}",
        [
          (store_add, ":dest_npc", "trp_npc1", x),
          (assign, "$g_player_troop", ":dest_npc"),
          (set_player_troop, "$g_player_troop"),
        ]) for x in range(0, 12)]+[  #Floris - for new companions; was 0, 8
      ("export_import_next",[],"Next page", [(jump_to_menu, "mnu_export_import_npcs_2")]),
    ]
  ),
but I'm guessing here this needs to by dynamic in game.

I know you don't use WSE or don't want to...but dynamic menu options are available via operations it adds:
Code:
menu_create_new      = 4800 #(menu_create_new, <destination>, <text>, [<mesh_name>], [<flags>], [<script_no>], [<script_param>]), #Creates a dynamic menu and stores its id into <destination>. [<script_no>] (-1 for no script) will be called with params 1 = menu_no, 2 = [<script_param>] when the operations block is executed
menu_add_item        = 4801 #(menu_add_item, <menu_no>, <text>, [<conditions_script_no>], [<consequences_script_no>], [<script_param>]), #Adds a new menu item to <menu_no>. [<conditions_script_no>] and [<consequences_script_no>] (-1 for no script) will be called with params 1 = <menu_no>, 2 = [<script_param>] when the conditions/consequences blocks are executed
menu_clear_items     = 4802 #(menu_clear_items, <menu_no>), #Removes all menu items from <menu_no>
menu_clear_generated = 4803 #(menu_clear_generated), #Removes all dynamic menus

jacobhinds said:
Could anyone tell me how I'd do the same thing with module_presentations, or if there are any examples I could use? I couldn't find any even after searching the entire file for try_for_range's.
I do a lot of dynamic/list like presentation overlays in the PBOD code, and Windyplains also has plenty of these types of displays, too, so perhaps something there could give you some ideas? (Temp dropbox link to the PBOD presentation file)
 
MadVader said:
You shouldn't just move try_ends without understanding. What happens when the castle is already entered and the block exits? What would be the jump point?

Here's how passage numbers as seen in the scene editor work, for reference.
MadVader said:
The order of menu options corresponds to passage numbers, so adding a new town menu option (or deleting an old one) will screw your passages. If you want to add new menus, place them after the menu options used for passages. If you want to disable an option, put (eq, 1, 0) in its condition block, but don't remove it.
Actually I always try something without understanding :grin: . That is the way I can understand, firstly trying.
I ve changed place of this try_end looking town_center, which is in the module_game_menus.py  so it works just like in the cities, in first time the jump point is "entry 1" but in second time ("when the castle is already entered") it is "entry 0". Although this is not problem for cities it is problem for castles because "entry 0" is outside the castle walls contrary to town centers.
As i could understand, This code:
Code:
 (try_begin),
             (eq, "$town_entered", 0),
             (assign, "$town_entered", 1),
             (set_jump_entry, 1), 
           (try_end),
makes (set_jump_entry, 1) work only when i go to the castle courtyard from the map therefore there is no jump entry for the otherways to go to the courtyard so the entries written on the passages can be free and work. But the problem is, it makes me spawn "entry 0" in second time(when the castle is already entered) and it is outside the courtyard. How can i make it "entry 1" for second time as well? If it is not possible or it is difficult, I am thinking of changing that we spawn at "entry 0" while besieging castle so I can move "entry 0" into the courtyards. But i dont know how i can change.
The other proplem is, when i tried to go to courtyard from prison I get mst_castle_visit trigger error and I couldt find this trigger on town_center mission to copy to castle_visit mission. Which one is this?
 
Is it possible to change the date after somethings happen ? should I just call the "game_get_date_text" when i want to change it ? Or if i change the ":cur_year" to global variable, then change the year whenever i want ?
 
HyperCharge said:
Is it possible to change the date after somethings happen ? should I just call the "game_get_date_text" when i want to change it ? Or if i change the ":cur_year" to global variable, then change the year whenever i want ?

Indeed. Modify game_get_date_text as you wish. Toss a global variable in for the "somethings happen" and have different parsing for that variable at 0 and that variable at 1.
 
I had a problem:
litdum said:
I dont know whether anyone noticed but the passages in the castle courts&prisons in Warband do not work correctly. when we go to a castle courtyard by using these passages we should spawn at "entry 2" when it is from the court to the courtyard, "entry 7" if it is from the prison to the courtyard. But we always spawn at "entry 1" when we use these passages. I ve checked them in edit mod. "Menu item no" and "Entry no" are correct. I want these passages to work correctly. But i know nearly nothing about passages. How can i make them correct?
I ve solved it by taking out (set_jump_entry, 1), from castle_inspect menu, now i can spawn at entry 2 when i get into courtyard by using the passage in the castle court. But when i use the passage in dungeon to go to the courtyard I get an error like this:

Why I get this error? and How can I solve it?
 
Thanks. The problem is about these(i guess)
agent_get_horse                        = 1714 # (agent_get_horse,<destination>,<agent_id>),
agent_get_team                        = 1770  # (agent_get_team  ,<destination>, <agent_id>),
and these entries in LINE: 8 and LINE: 9 in castle_visit mission:
    "castle_visit",0,-1,
    "Castle visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons|af_override_head,0,1,pilgrim_disguise),
    (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise), #for doors
    (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
(9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1[]),  (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(13,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(14,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,  ],
I ve changed them to these:
    (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),   
    (8,mtef_visitor_source,af_override_horse,0,1,[]),
(9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(13,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(14,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
and the problem's been solved.
 
Those lines you bolded were definitively not the problem and you should return them to their original form.

You identified the appropriate mission, however the script error you posted was for trigger 13's consequence lines 8 and 9. The lines you bolded are not part of any trigger, but of the mission template's set up. After the setup, you'll find the large block, started with an open [ that lists all of the triggers of this format:

(X, X, X, [conditions], [consequences]),

You need to find the 14th trigger in that list (counting starts with 0) and the second block of operations in that trigger and look at the agent ID being passed in the 9th and 10th lines (which as you have identified will be using the agent_get_horse and agent_get_team operations). It appears that you are missing a check that the agent ID being passed is a legitimate agent (something like agent_is_active and/or agent_is_alive should do the trick).
 
Caba`drin said:
Those lines you bolded were definitively not the problem and you should return them to their original form.

You identified the appropriate mission, however the script error you posted was for trigger 13's consequence lines 8 and 9. The lines you bolded are not part of any trigger, but of the mission template's set up. After the setup, you'll find the large block, started with an open [ that lists all of the triggers of this format:

(X, X, X, [conditions], [consequences]),

You need to find the 14th trigger in that list (counting starts with 0) and the second block of operations in that trigger and look at the agent ID being passed in the 9th and 10th lines (which as you have identified will be using the agent_get_horse and agent_get_team operations). It appears that you are missing a check that the agent ID being passed is a legitimate agent (something like agent_is_active and/or agent_is_alive should do the trick).
I dont know how but changing the lines I bolded works for now, most likely by chance. I think probably after i changed mtef_visitor_source in "entry 7" to mtef_scene_source it has been solved.
But I ve looked at the trigger you guided(the 14h trigger in castle_visit mission) and it was your trigger, the first trigger in your bodyguard trigger(I had added it before), which is:
from header_skills import *
bodyguard_triggers = [
(ti_after_mission_start, 0, ti_once, [(neq, "$g_mt_mode", tcm_disguised)], #condition for not sneaking in; to exclude prison-breaks, etc change to (eq, "$g_mt_mode", tcm_default")
  [
    #Get number of bodyguards
    (store_skill_level, ":leadership", skl_leadership, "trp_player"),
    (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
    (val_div, ":leadership", 3),
    (val_div, ":renown", 400),
    (store_add, ":max_guards", ":renown", ":leadership"),
    (val_min, ":max_guards", 4),
 
    (ge, ":max_guards", 1),

    #Get player info
    (get_player_agent_no, ":player"),
    (agent_get_team, ":playerteam", ":player"),                                                                                                #LINE:8(9th)
    (agent_get_horse, ":use_horse", ":player"), #If the player spawns with a horse, the bodyguard will too.  #LINE:9(10th)

    #Prepare Scene/Mission Template
    (assign, ":entry_point", 0),
    (assign, ":mission_tpl", 0),
    (try_begin),       
        (party_slot_eq, "$current_town", slot_party_type, spt_village),
        (assign, ":entry_point", 11), #Village Elder's Entry
        (assign, ":mission_tpl", "mt_village_center"),
    (else_try),
        (this_or_next|eq, "$talk_context", tc_prison_break),
        (this_or_next|eq, "$talk_context", tc_escape),
        (eq, "$talk_context", tc_town_talk),
        (assign, ":entry_point", 24), #Prison Guard's Entry
        (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, spt_castle),
            (assign, ":mission_tpl", "mt_castle_visit"),
        (else_try),
            (assign, ":mission_tpl", "mt_town_center"),
        (try_end),
    (else_try),
        (eq, "$talk_context", tc_tavern_talk),
        (assign, ":entry_point", 17), #First NPC Tavern Entry
    (try_end),
    (try_begin),
        (neq, "$talk_context", tc_tavern_talk),
        (gt, ":use_horse", 0),
        (mission_tpl_entry_set_override_flags, ":mission_tpl", ":entry_point", 0),
    (try_end),
    (store_current_scene, ":cur_scene"),
    (modify_visitors_at_site, ":cur_scene"), 
 
    #Find and Spawn Bodyguards
    (assign, ":bodyguard_count", 0), 
    (party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
    (try_for_range, ":i", 0, ":num_of_stacks"),
        (party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
        (neq, ":troop_id", "trp_player"),
        (troop_is_hero, ":troop_id"),
        (neg|troop_is_wounded, ":troop_id"),
        (val_add, ":bodyguard_count", 1),
               
        (try_begin), #For prison-breaks
            (this_or_next|eq, "$talk_context", tc_escape),
            (eq, "$talk_context", tc_prison_break),     
            (troop_set_slot, ":troop_id", slot_troop_will_join_prison_break, 1),
        (try_end),

        (add_visitors_to_current_scene, ":entry_point", ":troop_id", 1),

        (eq, ":bodyguard_count", ":max_guards"),
        (assign, ":num_of_stacks", 0), #Break Loop     
    (try_end), #Stack Loop
    (gt, ":bodyguard_count", 0), #If bodyguards spawned...
    (set_show_messages, 0), 
    (team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
    (set_show_messages, 1), 
  ]),
I couldnt understand why these agents pose a problem about "mtef_visitor_source" but Despite that, managed to solve the problem by chance.
 
You need to find the 14th trigger in that list (counting starts with 0) and the second block of operations in that trigger and look at the agent ID being passed in the 9th and 10th lines (which as you have identified will be using the agent_get_horse and agent_get_team operations).
This is great learning material.
So in the castle_visit template, are these the conditions:
Code:
[(0,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons|af_override_head,0,1,pilgrim_disguise),
     (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise), 
     (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise), #for doors
     (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
     (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
     (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
     (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
And this is the first trigger:
Code:
 (ti_on_agent_spawn, 0, 0, [],
      [
        (store_trigger_param_1, ":agent_no"),
        (call_script, "script_init_town_agent", ":agent_no"),
        (get_player_agent_no, ":player_agent"),
        (try_begin),
          (neq, ":player_agent", ":agent_no"),
          (agent_set_team, ":agent_no", 7),
        (try_end),
        
        (try_begin),
          (this_or_next|eq, "$talk_context", tc_escape),
          (eq, "$talk_context", tc_prison_break),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (troop_get_slot, ":will_join_prison_break", ":troop_no", slot_troop_will_join_prison_break),
          (eq, ":will_join_prison_break", 1),
          (agent_set_team, ":agent_no", 0),
          (agent_ai_set_aggressiveness, ":agent_no", 5),
          (troop_set_slot, ":troop_no", slot_troop_will_join_prison_break, 0),

          (try_begin),
            (troop_slot_eq, ":troop_no", slot_troop_mission_participation, mp_prison_break_stand_back),
            (agent_get_position, pos1, ":agent_no"),                        
            (agent_set_scripted_destination, ":agent_no", pos1),
          (try_end),
        (try_end),
There are only 11 (or 10 with a 0 start) in Brytenwalda so I can't line things up.

I came here to ask (before starting a thread):
What factors are built-into the game that control party speed?
I have a thread on the Forge that shows how I'm creating an elaborate script for map speed outcomes.
However, I don't want to add excess baggage to the system.
It appear that weight, horses and party size are already included in the internal calculations.
What about horse-riding skill? Pathfinding skill?
Other unusual factors like party health status?
 
Is tf_hero hardcoded? Meaning anyone with the tf_hero flag set should not die in battles?

Im having issues where peoople have reported companions and the player permanently dieing in battles.
 
gdwitt said:
You need to find the 14th trigger in that list (counting starts with 0) and the second block of operations in that trigger and look at the agent ID being passed in the 9th and 10th lines (which as you have identified will be using the agent_get_horse and agent_get_team operations).
This is great learning material.
So in the castle_visit template, are these the conditions:
Code:
[(0,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons|af_override_head,0,1,pilgrim_disguise),
     (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise), 
     (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise), #for doors
     (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
     (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
     (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
     (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
     (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
And this is the first trigger:
Code:
 (ti_on_agent_spawn, 0, 0, [],
      [
        (store_trigger_param_1, ":agent_no"),
        (call_script, "script_init_town_agent", ":agent_no"),
        (get_player_agent_no, ":player_agent"),
        (try_begin),
          (neq, ":player_agent", ":agent_no"),
          (agent_set_team, ":agent_no", 7),
        (try_end),
        
        (try_begin),
          (this_or_next|eq, "$talk_context", tc_escape),
          (eq, "$talk_context", tc_prison_break),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (troop_get_slot, ":will_join_prison_break", ":troop_no", slot_troop_will_join_prison_break),
          (eq, ":will_join_prison_break", 1),
          (agent_set_team, ":agent_no", 0),
          (agent_ai_set_aggressiveness, ":agent_no", 5),
          (troop_set_slot, ":troop_no", slot_troop_will_join_prison_break, 0),

          (try_begin),
            (troop_slot_eq, ":troop_no", slot_troop_mission_participation, mp_prison_break_stand_back),
            (agent_get_position, pos1, ":agent_no"),                        
            (agent_set_scripted_destination, ":agent_no", pos1),
          (try_end),
        (try_end),
just additionally,
Yes its exactly great learnig material but I think the point we should carefull about is, in some templates there are triggers as a thread(just a line), for example:
        common_shield_bash,  #1th(0)
        dplmc_horse_speed,  #2nd(1)
      (ti_on_agent_spawn, 0, 0, [],  #3th(2)
      [       
        (store_trigger_param_1, ":agent_no"),
        (call_script, "script_init_town_agent", ":agent_no"),
        (get_player_agent_no, ":player_agent"),
        (try_begin),
        (neq, ":player_agent", ":agent_no"),
          (agent_set_team, ":agent_no", 7),
        (try_end),
       
        (try_begin),
          (this_or_next|eq, "$talk_context", tc_escape),
          (eq, "$talk_context", tc_prison_break),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (troop_get_slot, ":will_join_prison_break", ":troop_no", slot_troop_will_join_prison_break),
          (eq, ":will_join_prison_break", 1),
          (agent_set_team, ":agent_no", 0),
          (agent_ai_set_aggressiveness, ":agent_no", 5),
          (troop_set_slot, ":troop_no", slot_troop_will_join_prison_break, 0),

          (try_begin),
            (troop_slot_eq, ":troop_no", slot_troop_mission_participation, mp_prison_break_stand_back),
            (agent_get_position, pos1, ":agent_no"),                       
            (agent_set_scripted_destination, ":agent_no", pos1),
          (try_end),
        (try_end),
      ]),
or it may be added at the end of the template like Caba`drin's bodyguard triggers:
...
...
...
        (finish_mission, 0),
      ]),
    ]+ bodyguard_triggers, #14th & 15th & 16th(13, 14, 15)
  ),
We should count them as well.
 
Is it possible to have game load several different terrains? I had this idea for a Sci-Fi mod where you had a main map set in space, and one for a planet. Is that possible ?

To clarify, is it possible to have multiple terrains be loaded?
 
Bithon said:
Is it possible to have game load several different terrains? I had this idea for a Sci-Fi mod where you had a main map set in space, and one for a planet. Is that possible ?

To clarify, is it possible to have multiple terrains be loaded?

well you could check this mod for space part https://youtu.be/Fff2I_SLlO0?t=5m25s
 
produno said:
Is tf_hero hardcoded? Meaning anyone with the tf_hero flag set should not die in battles?

Im having issues where peoople have reported companions and the player permanently dieing in battles.
Don't use tf_allways_fall_dead. Personally I thought it was hilarious trying to keep companions alive in Expanded Gameplay with those flags.
 
MitchellD said:
How can I get a script to run when the player returns to the map after a battle? I notice there's a ti_on_switch_to_map but I haven't figured out how to get it to work.
ti_on_switch_to_map may not be what you're looking for, I guess this trigger is used for presentations/character screen you access from the map, rather than after battle.

Have you tried finding the game menu/presentation that loads after a battle, showing the casualties and allowing you to take prisoners? If you find where that's called, you can also call your script there, most likely.
 
Status
Not open for further replies.
Back
Top Bottom