Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: Labelling characters [SOLVED - partially]

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Labelling characters [SOLVED - partially]

    I'm pretty sure that the answer is "no" but need to confirm for sure...

    Is there any way to label a spawned non-general character such as a spy, diplomat, etc.?

    As I understand it label can only be used for generals, either in descr_strat or within spawn_army in script. Maybe labels can be used on non-generals in descr_strat too (?) but I need to do it from within campaign_script.

    spawn_character doesn't seem to accept labels.

    I also experimented with including a spy in a spawn_army, hoping to then kill everyone but him and thus leave him as the label holder. It was a long shot and it didn't work; extra character lines confused the hell out of the parser. Which I suppose also means that you can't spawn an army containing more than one general.

    Thanks.

    EDIT: post #12 has an alternative solution for some situations: using unique names instead of labels.

    EDIT: But see this tutorial instead. It is more complete and accurate.
    Last edited by Withwnar; October 01, 2011 at 03:41 AM.

  2. #2

    Default Re: Labelling characters

    I've tried and failed with the same thing, I don't think you can have a label for any character except general and captain. You could perhaps use the characters name and maybe coordinates if you just want a one shot script...

    You could also try and make the character unique, by giving him a vaild first name from descr_names and an invalid surname. As long as the surname is in the text\names.txt file the game engine will run but not display the surname. I'm not sure how well this will work from the campaign_script, but it's probably worth a try...

  3. #3
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Labelling characters

    Quote Originally Posted by Eothese View Post
    You could also try and make the character unique, by giving him a vaild first name from descr_names and an invalid surname. As long as the surname is in the text\names.txt file the game engine will run but not display the surname. I'm not sure how well this will work from the campaign_script, but it's probably worth a try...
    Alas it did not work. True that it spawned the character without error*, and the surname was missing in-game as you said, but the script commands would not treat him uniquely. (*almost; see P.S. below)

    For example:
    Code:
    monitor_event {some event}
      spawn_character sicily, Joe,        diplomat, age 18, x 246, y 128
      spawn_character sicily, Joe Bloggs, diplomat, age 18, x 247, y 128
    end_monitor        
            
    monitor_event {some other event}
      kill_character Joe Bloggs
    end_monitor
    The kill_character command kills Joe in his case, not Joe Bloggs. If I then trigger the second monitor again it will kill Joe Bloggs. So to the game engine both characters are just "Joe" and if you tell it to kill "Joe [anybody]" then all it sees is "kill Joe".

    So no good. But thanks very much anyway Eothese. It was worth a shot.

    P.S. On a side note, if I swap the order of spawning in the first monitor then Joe fails to spawn with an "already exists" error. Curiously it works error-free in that original order.

    EDIT: actually, this does work. But you need to use...
    Code:
    console_command kill_character "firstname surname"
    console_command kill_character, not just kill_character, and put the full name in double quotes.

    This also worked:
    Code:
    console_command move_character "firstname surname", x, y
    But these did not:
    Code:
    reposition_character "firstname surname", x, y
    reposition_character firstname surname, x, y
    ...both failing to parse: "no x coordinate" error in the log.

    I didn't try any other commands but it seems pretty safe to say that some of them won't work. Perhaps only console_command ones do.
    Last edited by Withwnar; October 21, 2011 at 04:10 AM.

  4. #4
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Labelling characters

    Thanks Eothese. This surname approach is news to me. I'll give it a shot.

  5. #5

    Icon1 Re: Labelling characters

    Withwnar: I had a similar problem. In my case I wanted to spawn some merchants at certain times. Because I was only spawning them one at a time, I was able to use the ‘retire_characters’ command to get rid of them:
    Code:
    retire_characters Lithuania priest

  6. #6
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Labelling characters

    Thanks TNZ. It is retire_characters I am trying to avoid so that I don't wipe out more than just my spawned one.

    Plus I was hoping to use commands like move_character to move my spawned one around, which works just fine with labels and unique names... it is getting the name to be unique that is the cruncher.

  7. #7

    Default Re: Labelling characters

    How about giving him a unique trait that can't normally be picked up, then including the that in the monitor? Again it's not something I've tried...

  8. #8
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: Labelling characters

    Managing characters via traits works perfectly well (for some purposed ofc), I've used it in IG mod for TATW, you can check out the code for reference.

    Basically you need to setup a trait, then do something like:
    monitor_event CharacterSelected CharacterIsLocal (or whatever that exports character_record and involves clicking on a character)
    and Trait blahblah

    blahblahblah (for instance if I_CharacterSelected blahblah
    console_command kill_character "blahblah"
    end_if)
    or just console_command kill_character "blahblah"
    end_monitor

    Then you might be interested in this as well:

    http://www.twcenter.net/forums/showt...81#post8091581

    Regards
    Last edited by Germanicu5; June 18, 2011 at 09:09 AM.
    I have no memory of this place.

  9. #9
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Labelling characters

    Thanks folks. Traits can be used to limit the monitor to firing only on my spawned character, but at the end of the day the kill_character (and other) commands require a name, and I need to be 100% sure that it is killing my "Joe" and not some other "Joe" who happens to be on the map.

    G5, I had seen that killing script in TATW: an IF statement for each possible character name. Congrats on the effort of just writing all of those! Am I missing something or is it still possible that you will kill the wrong "Joe", or "Aragorn" in TATW speak.

    Besides, between spawning and killing I have 200+ move_character calls, each requiring a name (or label) argument. Repeating all of these for each possible name is out of the question.

    I should explain: I currently have a working solution. The script uses a princess and it is 100% guaranteed that no other character on the map has her name because TATW does not have female characters on the map. But if anybody decided to introduce princesses into TATW then there would be big problems, so I was hoping to find a safer solution.

    But this is really a general question, for any situation where I wish to spawn a character, make him do something (e.g. move) and then possibly kill him. If there was a way to label him then problem solved.

  10. #10

    Icon1 Re: Labelling characters

    Withwnar: This is probably an overly complicated idea. But if the agent were spawned from another faction, say a hoarding faction, it may then be possible to use the ‘give_everything_to_faction’ command to give that agent to the desired faction.

    Now assuming that the ‘give_everything_to_faction’ command would actually transfer the agent to the faction you want, and if the names of the hoarding faction were not shared with any other faction, you could be assured that no other character shares the name of the agent you need to spawn.

    I don't know if any of this will actually work, and even if it did you would need to sacrifice a faction slot, so it might not be worth it in the end.

  11. #11
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Labelling characters

    Some nice lateral thinking there TNZ.

    I don't know much about hoarding factions so I'll need to read up on that.

    Meanwhile, I gave it a quick try using give_everything_to_faction on a normal existing faction. Princesses and priests were not transferred to the receiving faction but spies were. (I only tried these types.) The spy's name does not exist in the receiving faction list but after the transfer I was still able to do a move_character using his name. This is definitely something.

    Thanks man. Have some rep. In fact, reps all round!

  12. #12
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Labelling characters

    NOTE: some of this has since been found to incorrect. Please see my tutorial for the complete solution.

    SOLVED! Sort of. Thanks again TNZ: using another faction is the way to do it.

    Well, not for some character types, only those that are transferred over by a give_everything_to_faction. So it doesn't solve my princess problem but it does work for generals and spies at least, which opens up a LOT of scripting possibilities! Well, for the kinds of things I'm trying to do anyway.

    This solution spawns characters with guaranteed-to-be-unique names. Those names can then be used in script instead of labels.

    Here's how I did it...

    (In TATW Hungary is not being used. It exists in all of the files, presumably left over from whatever TATW was built on top of, but it is absent from descr_strat. To create a brand new faction to use for this will require a lot more steps than I'm mentioning here.)

    I didn't need to make the faction "horde", just unplayable.

    In descr_strat I added:

    Code:
    faction	hungary, balanced smith
    ai_label	default 
    dead_until_resurrected
    denari	10000
    denari_kings_purse	3000
    ...and added it to the unplayable list at the top of the file. The denari numbers are irrelevant - these were inherited from a copy-paste.

    I then added some names to the Hungary faction that do not exist in any other faction: UniqueNameA, UniqueNameB, UniqueNameC and UniqueNameD. Only one is needed but I was experimenting with spawning multiple characters.

    Then in campaign_script:

    Code:
    monitor_event {some event}
      
      ;emerge the faction
      faction_emerge hungary england 1 85.0 100.0 1.2 town false hungary_leader UniqueNameA 30
      
      ;spawn a 'real' general (not a captain)
      spawn_army
        faction hungary
        character  UniqueNameB, named character, age 18, x 242, y 133 
        unit Mordor Catapult  exp 0 armour 0 weapon_lvl 0    
      end      
      
      ;spawn some other character types
      spawn_character hungary, UniqueNameC, merchant, age 18, x 243, y 133
      spawn_character hungary, UniqueNameD, spy, age 18, x 244, y 133
      
      ;transfer to milan faction
      give_everything_to_faction hungary milan false
      
    end_monitor
    Characters UniqueNameB,C,D now belong to milan and despite not being defined names for milan they are still displayed just fine on the map etc.

    Because no other faction can have these names it is guaranteed that the only characters on the map are the ones I just spawned. Therefore I can now safely use other script to do what I want with them...

    Code:
    monitor_event {some other event}
      
      console_command move_character UniqueNameB, 242, 125
      console_command move_character UniqueNameC, 243, 125
      console_command move_character UniqueNameD, 244, 125
    
    end_monitor
    What's more, all of this can happen multiple times. Any time I want to spawn a new general/spy/whatever with a unique name I just do again what I did in that first bit of script. Of course, if it's done twice with the same name then there will be two characters with that name, which defeats the point. But if these characters are only temporary (spawn, do something, kill them) then the name can be reused. I was worried that a faction could only emerge once, but apparently not.

    Furthermore, there are no "faction emerges" or "faction destroyed" messages. It all happens silently and fast.

    From what I can tell these are not transferable: captain (must be "named character" not "general" in spawn_army), priest, princess.
    These are: general (named character), spy, diplomat, merchant, assassin.
    Unknown: admiral, inquisitor, witch, heretic.

    I also found that the give_everything_to_faction must immediately follow the spawns. Putting it in a different monitor - or even putting a wait before it in the same monitor - didn't work; the general turned rebel and the other characters disappeared.

    Also, the name given to the faction leader in the faction_emerge command is irrelevant. Neither he nor this name appears anywhere. The same name can be used as the one used for the spawn. i.e. If you only want to spawn one character then only one name needs to be defined; a separate one is not required for the faction leader.

    By the way, this is in Kingdoms. I don't know if that's relevant.

    EDIT:
    Important! It seems that this only works if an army is present in the emerging faction. e.g. If you spawn just a spy and try this then nothing happens. Include a spawn_army and it works. Of course this army (just a general) can be killed once the give_everything_to_faction has occurred, leaving just the spy as the brought-over character.
    Last edited by Withwnar; October 01, 2011 at 03:35 AM.

  13. #13

    Icon1 Re: [SOLVED - partially] Labelling characters

    Withwnar: I'm glad it worked.

  14. #14
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: [SOLVED - partially] Labelling characters

    So am I TNZ, thanks. I am very excited by the potential of this.

  15. #15
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: [SOLVED - partially] Labelling characters

    I'm forgetful... I tested it as well after TNZ's suggestion - it worked well on campaign map, I tried some related in-battle tricks as well, but I failed for now.

    My only concern is applying it to mods with full faction list... at least TATW isn't the case, unfortunately my most desired application would rather fit SS (there's a temporary free slot, but I understand meaning of "temporary" to well).

    Anyway it's a great idea to follow up with some scripting .

    @Withwnar

    I never happened to kill the wrong character with my script when testing, but I can't totally rule it out (particularly if names tend to repeat between factions). I had a theory that local faction names have priority, but I don't even recall how testing went.

    Regards
    Last edited by Germanicu5; July 02, 2011 at 07:08 AM.
    I have no memory of this place.

  16. #16

    Icon1 Re: [SOLVED - partially] Labelling characters

    It would, of course, be possible to do this trick using a faction that emerges late in the game. You would need to stop using that script once the faction emerges, but up until that point it should work without a problem. Similarly, in TATW you could use the timurids faction from the Fellowship Campaign if you wanted to script something for the main campaign.

  17. #17
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: [SOLVED - partially] Labelling characters

    The Timurids. That's a good idea. There is a TATW submod that has used all faction slots (DAC perhaps).

    Personally I think that keeping one slot free for this to provide some sweet scripting enhancements is worth one less faction in the game. Not everyone would agree of course.

    @G5
    Local faction first: that's interesting. I also found that when there are two characters with the same name then the one who is 'oldest' (spawned first) seems to always be the target for move, kill, etc. Within the local faction at least; I haven't really tried it when another faction has a character with the same name.
    Last edited by Withwnar; July 03, 2011 at 12:32 AM.

  18. #18
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: [SOLVED - partially] Labelling characters

    @TNZ

    Yes, actually one could make a script that checks what factions are in game and (almost) always spawn characters for a faction that got eliminated or hasn't appeared yet... I'd like it to be more fail-safe though, so I may just hit that one unused slot in SS.

    @Withwnar

    I'll recheck the order when I finish more urgent jobs... unless you happen to do it first.

    Regards
    I have no memory of this place.

  19. #19
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: [SOLVED - partially] Labelling characters

    Quote Originally Posted by Withwnar View Post
    I also found that when there are two characters with the same name then the one who is 'oldest' (spawned first) seems to always be the target for move, kill, etc. Within the local faction at least; I haven't really tried it when another faction has a character with the same name.
    Quote Originally Posted by Germanicu5 View Post
    I'll recheck the order when I finish more urgent jobs... unless you happen to do it first.
    It looks like the local faction takes precedence, as you thought G5.

    I gave it a quick test, spawning two spies with the same name - one local, one AI - then did a kill_character on that name. Regardless of the order in which they were spawned it was the local one that was killed.

  20. #20
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: [SOLVED - partially] Labelling characters

    This is already reaping some benefits: checking that a tile is empty.

    I am writing some script that needs to spawn a general onto one of three tiles, whichever one is first found to be empty.

    Previously, to set a counter to identify the empty tile, I would have had to do this...

    Spoiler Alert, click show to read: 
    Code:
    set_event_counter tile_to_use 0
    
    ;tile 1
    if not I_FactionNearTile venice 0 143, 252
      and not I_FactionNearTile sicily 0 143, 252
      and not I_FactionNearTile milan 0 143, 252
      and not I_FactionNearTile france 0 143, 252
      and not I_FactionNearTile england 0 143, 252
      and not I_FactionNearTile egypt 0 143, 252
      and not I_FactionNearTile hre 0 143, 252
      and not I_FactionNearTile scotland 0 143, 252
      and not I_FactionNearTile mongols 0 143, 252
      and not I_FactionNearTile portugal 0 143, 252
      and not I_FactionNearTile spain 0 143, 252
      and not I_FactionNearTile moors 0 143, 252
      and not I_FactionNearTile slave 0 143, 252
      
       set_event_counter tile_to_use 1
    end_if
    
    ;tile 2
    if I_EventCounter tile_to_use == 0
      and not I_FactionNearTile venice 0 144, 252
      and not I_FactionNearTile sicily 0 144, 252
      and not I_FactionNearTile milan 0 144, 252
      and not I_FactionNearTile france 0 144, 252
      and not I_FactionNearTile england 0 144, 252
      and not I_FactionNearTile egypt 0 144, 252
      and not I_FactionNearTile hre 0 144, 252
      and not I_FactionNearTile scotland 0 144, 252
      and not I_FactionNearTile mongols 0 144, 252
      and not I_FactionNearTile portugal 0 144, 252
      and not I_FactionNearTile spain 0 144, 252
      and not I_FactionNearTile moors 0 144, 252
      and not I_FactionNearTile slave 0 144, 252
      
      set_event_counter tile_to_use 2
    end_if
    
    ;tile 3
    if I_EventCounter tile_to_use == 0
      and not I_FactionNearTile venice 0 145, 252
      and not I_FactionNearTile sicily 0 145, 252
      and not I_FactionNearTile milan 0 145, 252
      and not I_FactionNearTile france 0 145, 252
      and not I_FactionNearTile england 0 145, 252
      and not I_FactionNearTile egypt 0 145, 252
      and not I_FactionNearTile hre 0 145, 252
      and not I_FactionNearTile scotland 0 145, 252
      and not I_FactionNearTile mongols 0 145, 252
      and not I_FactionNearTile portugal 0 145, 252
      and not I_FactionNearTile spain 0 145, 252
      and not I_FactionNearTile moors 0 145, 252
      and not I_FactionNearTile slave 0 145, 252
      
      set_event_counter tile_to_use 3
    end_if
    Now I can just do this...

    Spoiler Alert, click show to read: 
    Code:
    faction_emerge hungary england 1 85.0 100.0 1.2 town false hungary_leader UniqueNameA 30
    set_event_counter tile_to_use 0
    
    ;tile 1
    spawn_character hungary, UniqueNameB, merchant, age 18, x 143, y 252
    if I_CharacterTypeNearTile hungary merchant 0 143, 252
      set_event_counter tile_to_use 1
    end_if
    
    ;tile 2
    if I_EventCounter tile_to_use == 0
      reposition_character UniqueNameB, 144, 252
      if I_CharacterTypeNearTile hungary merchant 0 144, 252
        set_event_counter tile_to_use 2
      end_if
    end_if
    
    ;tile 3
    if I_EventCounter tile_to_use == 0
      reposition_character UniqueNameB, 145, 252
      if I_CharacterTypeNearTile hungary merchant 0 145, 252
        set_event_counter tile_to_use 3
      end_if
    end_if
    
    kill_character UniqueNameB
    give_everything_to_faction hungary milan false  ;(need this?)
    ...which has more than halved the lines of code. The saving will be greater the more tiles need to be tested and the more factions there are.

    Both spawn_character and reposition_character will fail to put the character on that tile if it is occupied - they land somewhere random instead. So if, after spawn/reposition, a hungary merchant is found on that tile then it must have been unoccupied.
    Last edited by Withwnar; July 19, 2011 at 06:16 AM.

Page 1 of 2 12 LastLast

Posting Permissions

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