How to make enemies join battle?

Users who are viewing this thread

Yeah, it's me... Again!

I'm wondering how I should do to let enemies group up against me in battle.
Basicly, I'm trying to convert this TML Tweak into the MS.

I know what part of code I should change, but not WHAT to change.
Here's the code:

Code:
# script_let_nearby_parties_join_current_battle
  # Input: arg1 = besiege_mode, arg2 = dont_add_friends
  # Output: none
  ("let_nearby_parties_join_current_battle",
    [
      (store_script_param, ":besiege_mode", 1),
      (store_script_param, ":dont_add_friends", 2),
      (assign, ":join_distance", 5),
      (try_begin),
        (is_currently_night),
        (assign, ":join_distance", 3),
      (try_end),
      (try_for_parties, ":party_no"),
        (party_get_battle_opponent, ":opponent",":party_no"),
        (lt, ":opponent", 0), #party is not itself involved in a battle
        (party_get_attached_to, ":attached_to",":party_no"),
        (lt, ":attached_to", 0), #party is not attached to another party
        (get_party_ai_behavior, ":behavior", ":party_no"),
        (neq, ":behavior", ai_bhvr_in_town),

      
        (store_distance_to_party_from_party, ":distance", ":party_no", "p_main_party"),
        (lt, ":distance", ":join_distance"),

        (store_faction_of_party, ":faction_no", ":party_no"),
        (store_faction_of_party, ":enemy_faction", "$g_enemy_party"),
        (try_begin),
          (eq, ":faction_no", "fac_player_supporters_faction"),
          (assign, ":reln_with_player", 100),
        (else_try),
          (store_relation, ":reln_with_player", ":faction_no", "fac_player_supporters_faction"),
        (try_end),
        (try_begin),
          (eq, ":faction_no", ":enemy_faction"),
          (assign, ":reln_with_enemy", 100),
        (else_try),
          (store_relation, ":reln_with_enemy", ":faction_no", ":enemy_faction"),
        (try_end),

        (assign, ":enemy_side", 1),
        (try_begin),
          (neq, "$g_enemy_party", "$g_encountered_party"),
          (assign, ":enemy_side", 2),
        (try_end),

        (try_begin),
          (eq, ":besiege_mode", 0),
          (lt, ":reln_with_player", 0),
          (gt, ":reln_with_enemy", 0),
          (party_get_slot, ":party_type", ":party_no"),
          (eq, ":party_type", spt_kingdom_hero_party),
          (get_party_ai_behavior, ":ai_bhvr", ":party_no"),
          (neq, ":ai_bhvr", ai_bhvr_avoid_party),
          (party_quick_attach_to_current_battle, ":party_no", ":enemy_side"), #attach as enemy
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_enemy"),
        (else_try),
          (eq, ":dont_add_friends", 0),
          (gt, ":reln_with_player", 0),
          (lt, ":reln_with_enemy", 0),
          (assign, ":do_join", 1),
          (try_begin),
            (eq, ":besiege_mode", 1),
            (assign, ":do_join", 0),
            (eq, ":faction_no", "$players_kingdom"),
            (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
            (assign, ":do_join", 1),
          (try_end),
          (eq, ":do_join", 1),
          (party_get_slot, ":party_type", ":party_no"),
          (eq, ":party_type", spt_kingdom_hero_party),
          (party_stack_get_troop_id, ":leader", ":party_no", 0),
   #       (troop_get_slot, ":player_relation", ":leader", slot_troop_player_relation),
          (call_script, "script_troop_get_player_relation", ":leader"),
          (assign, ":player_relation", reg0),
          (ge, ":player_relation", 0),
          (party_quick_attach_to_current_battle, ":party_no", 0), #attach as friend
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_friend"),
        (try_end),
      (try_end),
  ]),


SOLVED!
Solution said:
Thanks Berserker and Keedo for the code.


Search for:
let_nearby_parties_join_current_battle

in Scripts.py and paste the lines marked in red:
(try_begin),
          (eq, ":besiege_mode", 0),
          (lt, ":reln_with_player", 0),
          (gt, ":reln_with_enemy", 0),
          (party_get_slot, ":party_type", ":party_no"),
          #(eq, ":party_type", spt_kingdom_hero_party),
          (neg|is_between,":party_no",spawn_points_begin, spawn_points_end),
          (neq, ":party_type", spt_town),
          (neq, ":party_type", spt_castle),
          (neq, ":party_type", spt_kingdom_caravan),
          (get_party_ai_behavior, ":ai_bhvr", ":party_no"),
          (neq, ":ai_bhvr", ai_bhvr_avoid_party),
          (party_quick_attach_to_current_battle, ":party_no", ":enemy_side"), #attach as enemy
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_enemy"),
        (else_try),
          (eq, ":dont_add_friends", 0),
          (gt, ":reln_with_player", 0),
          (lt, ":reln_with_enemy", 0),
          (assign, ":do_join", 1),
          (try_begin),
            (eq, ":besiege_mode", 1),
            (assign, ":do_join", 0),
            (eq, ":faction_no", "$players_kingdom"),
            (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
            (assign, ":do_join", 1),
          (try_end),
          (eq, ":do_join", 1),
          (party_get_slot, ":party_type", ":party_no"),
          #(eq, ":party_type", spt_kingdom_hero_party),
          (neg|is_between,":party_no",spawn_points_begin, spawn_points_end),
          (neq, ":party_type", spt_town),
          (neq, ":party_type", spt_castle),
          (neq, ":party_type", spt_kingdom_caravan),
          (party_stack_get_troop_id, ":leader", ":party_no", 0),
  #      (troop_get_slot, ":player_relation", ":leader", slot_troop_player_relation),
          (call_script, "script_troop_get_player_relation", ":leader"),
          (assign, ":player_relation", reg0),
          (ge, ":player_relation", 0),
          (party_quick_attach_to_current_battle, ":party_no", 0), #attach as friend
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_friend"),
        (try_end),
      (try_end),
  ]),
 
Hmm well looking through that code it seems that there is a check to make sure that it is a kingdom hero party that joins.
If you were to comment out the glowing part from the enemy join script on both the friend tuple and the enemy tuple(the code I posted is the enemy tuple.  Then any party would join.
(try_begin),
          (eq, ":besiege_mode", 0),
          (lt, ":reln_with_player", 0),
          (gt, ":reln_with_enemy", 0),
          (party_get_slot, ":party_type", ":party_no"),
          (eq, ":party_type", spt_kingdom_hero_party),
          (get_party_ai_behavior, ":ai_bhvr", ":party_no"),
          (neq, ":ai_bhvr", ai_bhvr_avoid_party),
          (party_quick_attach_to_current_battle, ":party_no", ":enemy_side"), #attach as enemy
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_enemy"),
I think that this would make castles join against you too.  So you would probably want a check to make sure the party joining was not a castle or town.
 
Don't forget the spawn points as well. The ones in the NE mod would sometimes join the battle with or against you.
 
How do you define the spawn points.  You need a line of code like (neq, "p_spawn_points"  But I'm not sure what to call them.  the command slot_party_type will work to do a check if its a castle or town.

Maybe a try_for_range command would work to check if the nearby party is a spawn point.  The spawn points are defined in module constants.
 
Thanks for your replies.

And that's true. I didn't think of the spawnpoints and castles.
Castles however wouldn't bother me if they joined the battle. It'll make the player more careful when he engage battle.

But if I were to make it so that the spawnpoints wouldn't join, wouldn't I have to make a "try" block?
Is there something to check if it's a spawn point?

Will (neq, ":party_type", spawn_point) work?
Or should there be a try_for_range?
 
Would it be possible to have them join by faction they belong to? That way one could make it so sea raiders only help sea raiders and forest bandits only help forest bandits.
 
FrisianDude said:
Would it be possible to have them join by faction they belong to? That way one could make it so sea raiders only help sea raiders and forest bandits only help forest bandits.

I think all bandits are of the same faction...  Maybe if the faction is bandits, only let parties of the same name join.
 
Mountain Bandits, Forest Bandits, and Outlaws are all separate factions, but sea raiders and steppe bandits are part of the Outlaws faction.
 
NaglFaar said:
Thanks for your replies.

And that's true. I didn't think of the spawnpoints and castles.
Castles however wouldn't bother me if they joined the battle. It'll make the player more careful when he engage battle.

But if I were to make it so that the spawnpoints wouldn't join, wouldn't I have to make a "try" block?
Is there something to check if it's a spawn point?

Will (neq, ":party_type", spawn_point) work?
Or should there be a try_for_range?
I looked for a party type spawn_point type identifier in module_constants but I couldn't find one.  They only seem to exist for kingdom parties, towns, castles, and caravans.

Ha just found the easiest way to define if the party is a spawn point.
spawn_points_begin = "p_zendar"
spawn_points_end = "p_spawn_points_end"
This is already defined in the constants.  So maybe not equal to party type spawn_point would work.
or(neg|is_between,spawn_points_begin, spawn_points_end),  If you threw that in the code that would probably make them not join. 
 
(try_begin),
          (eq, ":besiege_mode", 0),
          (lt, ":reln_with_player", 0),
          (gt, ":reln_with_enemy", 0),
          (party_get_slot, ":party_type", ":party_no"),
          (eq, ":party_type", spt_kingdom_hero_party),
          (neg|is_between,spawn_points_begin, spawn_points_end),
          (get_party_ai_behavior, ":ai_bhvr", ":party_no"),
          (neq, ":ai_bhvr", ai_bhvr_avoid_party),
          (party_quick_attach_to_current_battle, ":party_no", ":enemy_side"), #attach as enemy
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_enemy"),

So this would work?
Or have I put it in the wrong place?
 
You still need to remove the (eq, ":party_type", spt_kingdom_hero_party).  But the check for spawn point is in the right place.
I figure the code should look like this.

(try_begin),
          (eq, ":besiege_mode", 0),
          (lt, ":reln_with_player", 0),
          (gt, ":reln_with_enemy", 0),
          (party_get_slot, ":party_type", ":party_no"),
          #(eq, ":party_type", spt_kingdom_hero_party),
          (neg|is_between,spawn_points_begin, spawn_points_end),
          (get_party_ai_behavior, ":ai_bhvr", ":party_no"),
          (neq, ":ai_bhvr", ai_bhvr_avoid_party),
          (party_quick_attach_to_current_battle, ":party_no", ":enemy_side"), #attach as enemy
          (str_store_party_name, s1, ":party_no"),
          (display_message, "str_s1_joined_battle_enemy"),

Now any party can join(even castles or towns if thats what you want).  If you don't want those to join(or caravans add these line respectively:
(neq, ":party_type", spt_town),
(neq, ":party_type", spt_castle),
(neq, ":party_type", spt_caravan),

I figure that should work yea.  I might include this in my mod too.  It makes the character more careful about when and where he picks a fight.

EDIT: Spt_caravan is commented out at the moment in module_constants.  So you would have to reenable that to use the check for caravans. 








 
*bows so deep I smack my head on my knees*

Thanks alot.
I'm just fiddeling sometimes with a module I hardly use, just to get acquainted with it.
Another experience and some further understanding of the module is acquired.
 
No problem I hadn't looked at this paticular set of code yet either.  I just added it to my module as well which is cool.  I always added that tweak from TML.  So by bringing up the problem you helped me as well.  Enabling TML's tweaks in python is a great way to learn the system from my experience.  When I first started with python at the beginning of the year it looked like a bunch of random numbers and symbols to me.  It feels great to start seeing it as a language.
 
Haha, I know what you mean. Same here. As for now I'm experimenting with the MS with the small knowledge I have.

Anyway, I tried it all out and it works fine.
But I'll maybe exclude the caravans from joining. It doesn't make much sense that they should join battle.
I'll just have to remember to un-comment it in constants.py

Also, the battles all of a sudden became massive. And the mixture of troops that appear now is just great.
 
Sorry for dubble posting but I just have 1 final question.

There is a local variable that isn't used. Does anyone know which one?
I encountered it when I commented out this line:

#(eq, ":party_type", spt_kingdom_hero_party),
 
Well, if you commented out: (eq, ":party_type", spt_kingdom_hero_party),
And didn't use ":party_type" in any other checks, then the line above it: (party_get_slot, ":party_type", ":party_no"),
would be storing a local variable (":party_type") that never gets used.
 
Hmm got me there.  I guess you could comment out the line that defines ":party_type" earlier on in the script.
(party_get_slot, ":party_type", ":party_no"), is this line needed for anything now? 
Although as long as you put one of the three optional exceptions the script should run fine.
 
Thanks guys. It did the job just commenting that line out.
I know the local variable doesn't affect anything, but it's nice to get it out of the way.


-Edit-
I think we have a problem here. I just (accidentally) engaged a sea raider party.
The spawn point joined the battle. I just can't figure out why.
 
Hmm well the only thing I can think of is that the check for spawn points doesn't mention ":party_type".  That variable must be necessary.  I'll have to take another look at the script.
 
The problem is the way the is_between line was written. It needs to use the following format:
(is_between,<value>,<lower_bound>,<upper_bound>),

EDIT: So, it should look like this: (neg|is_between, ":party_no", spawn_points_begin, spawn_points_end),
 
Back
Top Bottom