[REQ] - Troop Barracks : trigger needed

Users who are viewing this thread

DMcain

Veteran
Ok, here goes. I've added a castle/town improvement called 'Troop Barracks'. I've already figured out and made the changes to the module_game_menus.py, module_scripts.py and module_constants.py. I want the new trigger to do 2 things, once per week.
1) Train my garrison - weekly xp gain.
2) Recruit troops

Now, while playing I've noticed some REALLY large NPC garrisons (600+ in Curaw last time I visited with no lords present). I've found the 2 triggers that deal with these for the AI lords, but I have no clue on how to put in a check to see if the center is player owned AND has troop barracks. So, instead of putting in checks, I've decided to go with a new weekly trigger.

Here's the code for the AI garrison. I don't want mine to trigger every day, just weekly.
Code:
  #Hiring men with center wealths (once a day)
  (24,
   [
       (try_for_range, ":troop_no", kingdom_heroes_begin, kingdom_heroes_end),
         (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
         (ge, ":party_no", 1),
         (party_get_attached_to, ":cur_attached_party", ":party_no"),
         (is_between, ":cur_attached_party", centers_begin, centers_end),
         (party_slot_eq, ":cur_attached_party", slot_center_is_besieged_by, -1), #center not under siege
         (call_script, "script_hire_men_to_kingdom_hero_party", ":troop_no"), #Hiring men with current wealth
       (try_end),
       (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
         (neg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center does not belong to player.
         (party_slot_ge, ":center_no", slot_town_lord, 1), #center belongs to someone.
         (party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
         (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1), #center not under siege
         (assign, ":hiring_budget", ":cur_wealth"),
         (val_div, ":hiring_budget", 5),
         (gt, ":hiring_budget", reinforcement_cost),
         (call_script, "script_cf_reinforce_party", ":center_no"),
         (val_sub, ":cur_wealth", reinforcement_cost),
         (party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
       (try_end),
    ]),

And here's the bit for training the AI garrisons. This one is buried in another trigger so was kinda tricky to find.
Code:
       (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
         (store_random_in_range, ":rand", 0, 100),
         (lt, ":rand", 10),
         (party_get_slot, ":center_lord", ":center_no", slot_town_lord),
         (neq, ":center_lord", "trp_player"),
         (party_upgrade_with_xp, ":center_no", 3000),
       (try_end),

My goal is to make a new trigger, combining these 2.
1 - Check to see if center is player owned
2 - Check to see if center has troop barracks (slot_center_has_barracks)
3 - Give some xp to current garrison. I don't really care how they progress through the troop trees, but train the current garrison before we hire new guys.
4 - Hire more troops

So, I have no real knowledge of coding for M&B. I can do simple changes. But when it comes to something like this, I'm at a loss on how to accomplish it. So if any one would like to put this together for me, I would appreciate it.
 
Well this should be fairly straightforward since you already posted most of the needed code.. let's see.

Code:
(24*7, [ 
      (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
         (eg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center belongs to player.
         (eg|party_slot_eq, ":center_no", slot_center_has_barracks, 1), #center has barracks.
         (party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
         (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1), #center not under siege
         (party_upgrade_with_xp, ":center_no", 1000, 0), #add 1000 xp to the center and use to upgrade troops randomly
         (assign, ":hiring_budget", ":cur_wealth"),
         (val_div, ":hiring_budget", 5),
         (gt, ":hiring_budget", reinforcement_cost),
         (call_script, "script_cf_reinforce_party", ":center_no"),
         (val_sub, ":cur_wealth", reinforcement_cost),
         (party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
       (try_end),
 ],

And that should pretty much do it. You'll have to tinker with the xp amount, possibly. I've just used the one that's used in the other script. I've never used the party_upgrade_with_xp operation before, just noticed it in header_operations today but I guess if it works now, it should work this way too. The 0 is there to set the upgrade path to random but is possibly not needed.

The 24*7 is just an easy way to make it trigger once a week. The game reads it as 168, but it makes more sense to us (thanks to wickedshot for explaining that one to me the other day)

If you're setting the barracks slot to anything other than 1 in your scripts, you'll obviously need to eq it to that number instead, I just assumed you'd use 1

Actually, if you have such a limited knowledge of the module system I'm impressed you managed to get the barracks feature in there.. this is peanuts compared to that :smile:

Haven't compiled this, just wrote it in the post message window but I can spot no errors.

I guess she still has to put in the trigger for deducting troop wages from center wealth if Custow can get 600 troops crammed in there.. no way they're going to make enough money to afford that :smile:
 
Thanks much.  I'll plug that in and see what happens.

Heh, I know my way around the module system, I'm quite nosey and tend to poke around where I really have no business being :p. I've also modded other games before, so I'm not a complete noob. I'm just not familiar enough with python to write scripts from scratch.
 
heh and of course there was an error.. the end needs to read ]),

Missed out the closing bracket on the trigger.. for shame
 
heh, i figured that out myself, BUT:

Code:
Initializing...
Traceback (most recent call last):
  File "process_global_variables.py", line 7, in <module>
    from module_simple_triggers import *
  File "E:\M&B Module\module_simple_triggers.py", line 2623, in <module>
    (eg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center belongs to player.
NameError: name 'eg' is not defined
Exporting strings...
...
Exporting game menus data...
Traceback (most recent call last):
  File "process_simple_triggers.py", line 2, in <module>
    from module_simple_triggers import *
  File "E:\M&B Module\module_simple_triggers.py", line 2623, in <module>
    (eg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center belongs to player.
NameError: name 'eg' is not defined
exporting triggers...
exporting dialogs...
Checking global variable usages...

Apparently, it doesn't know what 'eg' is. Nor do I. maybe it supposed to be 'ge' ?
 
hahaha no that's just a bad typo and I missed it.. it's 3.30 am here :smile:

It's supposed to be eq

Guess I should've just compiled it quickly  :roll:

[edit] ah of course.. I was lazy and just removed the n from neq.. silly me

The whole bit needs to go, sorry.

It should just be party_slot_eq

the neg is there to say 'not party_slot_eq'

My bad
 
Code:
#Troop Barracks
(24*7,
  [(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
     (party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center belongs to player.
     (party_slot_eq, ":center_no", slot_center_has_barracks, 1), #center has barracks.
     (party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
     (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1), #center not under siege
     (party_upgrade_with_xp, ":center_no", 10000, 0), #add 10000 xp to the center and use to upgrade troops randomly
     (assign, ":hiring_budget", ":cur_wealth"),
     (val_div, ":hiring_budget", 5),
     (gt, ":hiring_budget", reinforcement_cost),
     (call_script, "script_cf_reinforce_party", ":center_no"),
     (val_sub, ":cur_wealth", reinforcement_cost),
     (party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
   (try_end),
  ]
),

Much thanks.  Works like a charm, though I had to make building the barracks it cheaper than dirt and boost the xp to some insane levels to test it.
I decided to go with 10k xp per week, since the AI gets 3k per day, I though that would be somewhat reasonable. Troops still progress faster when traveling with you, but at least you don't have a castle full of raw recruits if someone decides to beat on you.

now I'm at war with the nords and need to go kick some butt..  take care and god speed

 
Back
Top Bottom