Results 1 to 11 of 11

Thread: How to spawn custom agents by script?

  1. #1

    Default How to spawn custom agents by script?

    As I know, the standard method for spawning agents on the campaign map by script is the following line:

    spawn_character byzantium Denys, assassin, age 16, x 120, y 49
    However, unlike generals spawned by script and unlike agents created in descr_strat, agents spawned by script do not support custom portraits nor labels. They don't even support starting traits. I can easily address the traits by simply adding "console_command give trait..." after they are spawn, but being unable to customise the portrait and strat model is proving a problem as I need them to represent specific people rather than being random.

    I heard there is an alternative method in which a character is created outside of the map borders and later brought in by script, but I don't know anything else about this method. Is it practical? What are the downsides?

    Is there another alternative? Perhaps a script command that changes a character's portrait?

  2. #2
    Gigantus's Avatar You should always listen to your inner voice! - Agreed, but which one?
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    50,337
    Blog Entries
    29

    Default Re: How to spawn custom agents by script?

    custom portrait - not possible, only available for named characters on scripted spawning\descr_strat
    custom strat model - easy, via level traits
    'bringing in' - I am assuming you are talking about the off map function? Won't help in your case as those characters are being brought back into game by the usual spawning procedure




  3. #3

    Default Re: How to spawn custom agents by script?

    How do the level traits work?

    And, you saying there is no way I can accomplish my goal?

  4. #4
    Lusitanio's Avatar Senator
    Join Date
    Jan 2018
    Location
    Portugal
    Posts
    1,478

    Default Re: How to spawn custom agents by script?

    Quote Originally Posted by es157 View Post
    How do the level traits work?

    And, you saying there is no way I can accomplish my goal?
    Each agent can have up to 10 models:
    Model 0
    Model 1
    Model 2
    Etc...

    Those levels are given with traits that have a level effect like trait King Effect Level 2
    If you give that trait to the agent, the strat model will have the model 2 due to the level given by the trait.

  5. #5
    Gigantus's Avatar You should always listen to your inner voice! - Agreed, but which one?
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    50,337
    Blog Entries
    29

    Default Re: How to spawn custom agents by script?

    Quote Originally Posted by es157 View Post
    How do the level traits work?
    It's explained in the link, see part I and apply it to your type of agent - it's the same principle as the priest, bishop, cardinal strat model progression.


    Quote Originally Posted by es157 View Post
    And, you saying there is no way I can accomplish my goal?
    No portraits or labels for agents, you could however give the agent a unique trait without triggers which you could then use instead of a label. It does however has it's limits.
    Last edited by Gigantus; June 02, 2021 at 01:17 PM.




  6. #6

    Default Re: How to spawn custom agents by script?

    The problem is that only agents spawned in descr_strat can have portraits and labels. You can actually spawn agents using spawn_army (a trick Gigantus discovered) so that they can have portraits and labels, but they will die (presumably for lack of bodyguard unit) when the campaign is reloaded.

    I've used both approaches in my mod. If you have any unused faction slots, what you can do is spawn the agents with portraits and names in descr_strat for a dummy faction, then use give_everything_to_faction at the start of turn 0 in campaign_script. This will transfer the agents with unique portraits/labels from the dummy faction to your desired faction, but it only works on turn 0 and only for one target faction per dummy faction. You will need to add Level traits (for strat model and tooltips) after the give_everything as any traits containing the Level attribute will be removed by the game during a character conversion from faction to faction. If you do the transfer start of turn 0, you can immediately issue the give_trait commands followed by clear_messages to suppress the trait added messages.

  7. #7

    Default Re: How to spawn custom agents by script?

    Quote Originally Posted by Callistonian View Post
    You can actually spawn agents using spawn_army (a trick Gigantus discovered) so that they can have portraits and labels, but they will die (presumably for lack of bodyguard unit) when the campaign is reloaded.
    Maybe I could still learn something from this trick... How is it done?

    It's a shame I can't have custom agents. But maybe I can find a way around this. I feel this was already answered somewhere else, but just to be sure, it is not possible to transfer one agent from faction X to faction Y, is it? Except with give_everything_to_faction.
    Last edited by es157; June 03, 2021 at 12:04 PM.

  8. #8
    Gigantus's Avatar You should always listen to your inner voice! - Agreed, but which one?
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    50,337
    Blog Entries
    29

    Default Re: How to spawn custom agents by script?

    Sending a character off map is done via script or already in descr_strat. Do have a look at the Norwegian leader Haakon in the brittania campaign to see how it is embedded in his entry.

    The script command is: send_character_off_map [faction] [name]

    Otherwise I can only think of bribing - and that has it's own pitfalls as it can be done only through the mission mechanics.
    Last edited by Gigantus; June 02, 2021 at 08:22 PM.




  9. #9

    Default Re: How to spawn custom agents by script?

    Here is Gigantus' trick for spawning agents with spawn_army. There's really nothing to it - you just change the character type. This produces a sort of agent-general hybrid with some characteristics of agents and some of generals that aren't immediately obvious but will reveal themselves the more often you use this trick. Unfortunately, one of the aspects of this hybrid is that it requires a bodyguard unit to survive a map reload. If you destroy a named character's BG unit, the named character dies, hence we speculate that this is why hybrid agents die when the game is reloaded (reloading must trigger a check for all characters). I use this trick for a 'traveling' agent type that I need to have use a unique name and portrait but who only stays on the map for a couple turns anyway, so I don't care that he leaves prematurely if the player reloads. Beyond that, I don't think the trick is particularly useful. It can be combined with the uniquely named characters trick which you should definitely look into as you will learn essential scripting from that.

    As I mentioned a while back in that other thread, there are a few ways to transfer characters (including agents) between factions, but they're probably not useful to you. Yes, there is give_everything. As Gignatus said, we have bribery, but that's complicated by the necessary diplomacy/missions. We also have revolts (to slave or a shadow faction), although I'm not sure non-named characters can actually revolt (I've never seen it). And we have promotion of priests from the College of Cardinals. And I'm sure I'm forgetting one or two more obscure methods. If you have spare faction slots and you only need to transfer on turn 0, do what I recommended above using give_everything. Otherwise, your best bet is to kill/send off and spawn a clone for the other faction.

  10. #10

    Default Re: How to spawn custom agents by script?

    Unfortunately, it seems I won't be able to have my unique agent after all. A shame, but I'll keep testing alternatives.

    Thanks to both of you for the tips and suggestions. They'll probably be useful in the future.

  11. #11
    Gigantus's Avatar You should always listen to your inner voice! - Agreed, but which one?
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    50,337
    Blog Entries
    29

    Default Re: How to spawn custom agents by script?





Posting Permissions

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