Help: Assigning troops to a non-default class?

Users who are viewing this thread

Scarf Ace

Sergeant Knight at Arms
Hi, I essentially want to make specific troops be assigned to a the number 4 key by default.
Is this possible? Can I rename that class somehow?
 
As for the name of the class, you can rename it in the interface files, IIRC, but not in Module System.  IDK whether this is now editable via MS, I did it the old-fashioned way.
 
xenoargh said:
You may assign them to group 4, yes, either through troop_set_class or agent_set_division.
I'm really new to the whole module system thing, could you please explain it some more?
Thanks for the answer.
 
If you are talking just when you are playing, you do both through the Party Screen.

By code, and if you want it to apply always and to all parties, I'd recommend using troop_set_class somewhere outside of mission templates, for two reasons: first, troop_set_class will not affect agents already spawned within a mission template, and second, agent_set_division is a buggy/temperamental operation and agents whose divisions are changed dynamically with that operation will revert to their troop-class-based division any time that base division is given an order.

In order to maintain divisions changed by agent_set_division, you need to set an agent slot for each agent you change divisions and then use another trigger to check that slot and change the division back periodically.

Also, if we are talking through code, use (class_set_name, <sub_class>, <string_id>), to rename the class.



And a final, related note to remember: any time you adjust the division/class of a troop either in the party screen or by code, that class-assignment will apply to ALL agents based on that troop template, regardless of whether or not they belong to the player's party. This could cause problems with any more advanced AIs expecting agents to be in the three basic divisions, or certain types of troops to be in their basic division.
 
So lets say I would like for groups to be ordered like this:
1. Infantry
2. Archers
3. Calvary
4. R. Calvery
5. Firearms

Where can I set that so the player can change that later if they wanted? I'm sure it would be in a area where troops are defined those groups in the beginning.
 
Well, you'd have to do something like:

(troop_set_class, "trp_my_nifty_guy", 4),

To set a given troop to class 4.  Suggestion; do it as a script called during script_game_start in module_scripts, to get it done.

I do not know what happens if troop class assignments are changed by players during play; my guess is that changes that class assignment (in that savegame) permanently, and will affect things like AI usage of said troop.  For AI purposes, using agent_set_division is quite a lot safer, if a wee bit more complicated to implement.

Basically, depending on what you want to do, this can be either something easy to learn Module System with, or a fairly complicated gamecode project.  If you just want the Companions assigned to group 4, that's pretty easy.
 
Caba`drin said:
If you are talking just when you are playing, you do both through the Party Screen.

By code, and if you want it to apply always and to all parties, I'd recommend using troop_set_class somewhere outside of mission templates, for two reasons: first, troop_set_class will not affect agents already spawned within a mission template, and second, agent_set_division is a buggy/temperamental operation and agents whose divisions are changed dynamically with that operation will revert to their troop-class-based division any time that base division is given an order.

In order to maintain divisions changed by agent_set_division, you need to set an agent slot for each agent you change divisions and then use another trigger to check that slot and change the division back periodically.

Also, if we are talking through code, use (class_set_name, <sub_class>, <string_id>), to rename the class.



And a final, related note to remember: any time you adjust the division/class of a troop either in the party screen or by code, that class-assignment will apply to ALL agents based on that troop template, regardless of whether or not they belong to the player's party. This could cause problems with any more advanced AIs expecting agents to be in the three basic divisions, or certain types of troops to be in their basic division.
It's for a multiplayer mod, so setting it ingame is not an option.
Could I please get a step by step, "for noobs" explanation? Also, would such a method also work to make a unit with guarantee_range (or whatever it's called) be assigned as infantry by default?



xenoargh said:
Well, you'd have to do something like:

(troop_set_class, "trp_my_nifty_guy", 4),

To set a given troop to class 4.  Suggestion; do it as a script called during script_game_start in module_scripts, to get it done.

I do not know what happens if troop class assignments are changed by players during play; my guess is that changes that class assignment (in that savegame) permanently, and will affect things like AI usage of said troop.  For AI purposes, using agent_set_division is quite a lot safer, if a wee bit more complicated to implement.

Basically, depending on what you want to do, this can be either something easy to learn Module System with, or a fairly complicated gamecode project.  If you just want the Companions assigned to group 4, that's pretty easy.
script_game_start would mean it would only apply to SP, right?
 
I may have found my answer in the "battle" presentation code. Thanks Xeno & Caba, I hope you find your answer Scarf Ace.  :smile:

EDIT:
What about "script_multiplayer_get_troop_class"?
 
agent classes in multiplayer are used to denote which player id commands which bots.
That particular script categorizes arbitrary troop classes in order to facilitate discounts on equipment.
 
Nevermind, that's agent_set/get_group. You can still use troop_set_class in script_game_quick_start. The player shouldn't be able to change this assignment. agent_get_class is similar to agent_get_division except it fetches the original troop class?
 
Somebody said:
agent_get_class is similar to agent_get_division except it fetches the original troop class?
Aye, it should fetch the guarantee_horse/ranged-set grc_infantry, grc_archers, grc_cavalry of the troop.
I've experienced it failing to do so, however, for certain troop types (bandits, primarily...it seems to group them all as grc_infantry, even if they have the guarantee flags).

xenoargh said:
I do not know what happens if troop class assignments are changed by players during play; my guess is that changes that class assignment (in that savegame) permanently, and will affect things like AI usage of said troop.  For AI purposes, using agent_set_division is quite a lot safer, if a wee bit more complicated to implement.
Exactly. Whatever the player sets in the Party Window is like calling a troop_set_class operation for that troop type. As it changes the troop class, it will affect all agents spawned of that troop ID, regardless of party.


For reference, I use the following triggers for dealing with agent_set_division (SP, of course, cause I'm lame like that :wink: )
Code:
  (ti_on_agent_spawn, 0, 0, [], 
   #This is called after agent_reassign_team, so can safely assume correct team is set
   [(store_trigger_param_1, ":agent"),
    (agent_set_slot, ":agent", slot_agent_new_division, -1),    
    (get_player_agent_no, ":player"),
    
    (ge, ":player", 0),
    (agent_is_human, ":agent"),
    (agent_get_team, ":player_team", ":player"),
    (agent_get_team, ":team", ":agent"),
    (neq, ":team", ":player_team"),
    (agent_get_troop_id, ":troop", ":agent"),
    (try_begin),
        (troop_is_guarantee_horse, ":troop"),
        (assign, ":target_division", grc_cavalry),
    (else_try),
        (troop_is_guarantee_ranged, ":troop"),
        (assign, ":target_division", grc_archers),
    (else_try),
        (assign, ":target_division", grc_infantry),        
    (try_end),
    (agent_get_division, ":division", ":agent"),
    (neq, ":division", ":target_division"),
    (agent_set_division, ":agent", ":target_division"),
    (agent_set_slot, ":agent", slot_agent_new_division, ":target_division"),
   ]),
  (0.5, 0, 0, [(store_mission_timer_a, reg0),(gt, reg0, 4)], 
   [
    (try_for_agents, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_slot_ge, ":agent", slot_agent_new_division, 0),
        (agent_get_division, ":division", ":agent"),
        (neg|agent_slot_eq, ":agent", slot_agent_new_division, ":division"),
        (agent_get_slot, ":new_div", ":agent", slot_agent_new_division),
        (agent_set_division, ":agent", ":new_div"),
    (try_end),    
   ]), 
 
OK, so xenoargh's solution has worked for the purposes I need. Thanks!
My problem now is that troops that have been assigned to one of the "unnamed" keys aren't selectable at all (not even when selecting everyone). The unnamed keys don't even make the player say "X, hear me!". I can change that somehow, right?
Is it a multiplayer issue?
 
Scarf Ace said:
OK, so xenoargh's solution has worked for the purposes I need. Thanks!
My problem now is that troops that have been assigned to one of the "unnamed" keys aren't selectable at all (not even when selecting everyone). The unnamed keys don't even make the player say "X, hear me!". I can change that somehow, right?
Is it a multiplayer issue?
This is definitely a multiplayer issue; I can't give any more information than that I know this doesn't happen in SP. Perhaps only the core 3 divisions work in MP?
 
Caba`drin said:
Scarf Ace said:
OK, so xenoargh's solution has worked for the purposes I need. Thanks!
My problem now is that troops that have been assigned to one of the "unnamed" keys aren't selectable at all (not even when selecting everyone). The unnamed keys don't even make the player say "X, hear me!". I can change that somehow, right?
Is it a multiplayer issue?
This is definitely a multiplayer issue; I can't give any more information than that I know this doesn't happen in SP. Perhaps only the core 3 divisions work in MP?
That's what I'm thinking. Do you think there could be a way to make the other divisions work?
 
Back
Top Bottom