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

Thread: Creating Unique Units?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Creating Unique Units?

    Is there a way to create a unit that, once created, is unavailable to be recruited again until the first one is dead? I assumed the answer is "no", but at the same time, I once thought special leaders were also unattainable in SS, and I'm pretty sure I saw some Lionheart abilities floating about...

    Creator of Kingdoms of Heaven

  2. #2
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Creating Unique Units?

    1. Check the unique units in the crusades campaign of kingdoms. "Sheriff of Jerusalem" I think and others like him. Not sure how it works, but some scripting is involved.

    2. Wrong forum - this is the "Text" tutorial forum, the "Text" question forum is here.










  3. #3
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    Oh crap, you're right. My bad. I accidentally clicked on "tutorials" and didn't notice. Thank you for pointing out my mistake.
    Last edited by King Siegfried; August 16, 2009 at 01:55 PM.

    Creator of Kingdoms of Heaven

  4. #4
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: Creating Unique Units?

    Moved to Workshop->Text Editing and Scripting
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  5. #5
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Creating Unique Units?

    Yes, it's very possible. The following uses mockups(this would go in the campaign script):

    Code:
    monitor_event UnitTrained UnitType Sauron
      set_event_counter sauron 0
    end_monitor
    
    monitor_event AddedToTrainingQueue UnitType Sauron
     set_event_counter sauron 0
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
    
     if I_UnitExists mordor Sauron
      set_event_counter sauron 0
     end_if
    
     if not I_UnitExists mordor Sauron
      set_event_counter sauron 1
     end_if
    
    end_monitor
    You also need to add and event_counter sauron 1 to the recruit_pool line in the export_descr_buildings.txt. One caveat to the above is if the player tried to build sauron then removed him from the queue, they'd be unable to re-add until the next turn when the counter is reset. This is a small problem compared to the antithesis which allows the player to build one in every settlement.

  6. #6
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Creating Unique Units?

    You could make a building come with the unit ready to produce when the building is constructed but then have a less than 0 recruit pool.
    Code:
     recruit_pool "Lithuanian Regular Spearmans"  1   0.5   0.99  0  requires factions { lit, }  and region_religion pagan 60
    That setup should allow 1 unit to be produced once the building is constructed. Then 0.99 allows for retraining after battles but no more would be produced. Setting the recruit pool to zero would prevent any retraining.
    Last edited by Taiji; August 21, 2009 at 11:41 AM.

  7. #7
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    I hate to resurrect this thread a month later, but I'm having trouble with the scripting process. I've tried copying both Augustus Lucifer's method and the Crusades campaign. However, neither works. In a similar light, my attempts at recreating the Crusades campaign's "power center" scripts failed as well, which is frustrating me a bit.

    Okay, as it stands, here are my entries. Here is the custom_script entry where I tried Augustus Lucifer's suggestion:
    Spoiler Alert, click show to read: 
    ;------------------- RECRUITMENT - UNIQUE UNITS -------------------;

    ;Only one unique unit can exist at a time

    ;Jerusalem
    ;Constable of Jerusalem
    ;Canons of the Holy Sepulcher

    ;Test if the unit doesn't exist at start of turn
    ;Increment event counter - allows recruitment

    set_event_counter no_canon_sepluchre 0

    monitor_event FactionTurnStart FactionType jerusalem
    and I_EventCounter no_canon_sepluchre == 0
    and not I_UnitExists jerusalem Canons of the Holy Sepulcher
    add_events
    event counter no_canon_sepluchre
    date 0
    end_add_events
    end_monitor

    ;Test if the unit exists at start of turn
    ;Decrement event counter - stops recruitment

    monitor_event AddedToTrainingQueue UnitType Canons of the Holy Sepulcher
    and I_EventCounter no_canon_sepluchre == 1
    set_event_counter no_canon_sepluchre 0
    end_monitor

    monitor_event UnitTrained UnitType Constable of Jerusalem
    set_event_counter constable 0
    end_monitor

    monitor_event AddedToTrainingQueue UnitType Constable of Jerusalem
    set_event_counter constable 0
    end_monitor

    monitor_event FactionTurnStart FactionIsLocal

    if I_UnitExists jerusalem Constable of Jerusalem
    set_event_counter constable 0
    end_if

    if not I_UnitExists jerusalem Constable of Jerusalem
    set_event_counter constable 1
    end_if

    end_monitor

    ...and here is the entry in the EDB:
    Spoiler Alert, click show to read: 
    kings_stables castle requires factions { hre, teutonic_order, ireland, jerusalem, france, middle_eastern, eastern_european, greek, venice, milan, }
    {
    capability
    {
    recruit_pool "Constable of Jerusalem" 0 0.1 0.99 0 requires factions { jerusalem, } and event_counter constable 1

    Main problem: the Constable never shows up as recruitable, even after building the King's Stables and waiting a few turns. Am I forgetting to manipulate another file?

    Creator of Kingdoms of Heaven

  8. #8
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Creating Unique Units?

    Well your recruitment pool seems to start with 0 and never add up to 1(it has the max accumulated at 0.99), so it's possible it doesn't enter into the Recruitment area until it registers at least 1. That's one possibility. Another possibility is I_UnitExists requiring the faction to be capitalized, it is in the DocuDemons, but I've never come across a condition that actually required that.

  9. #9
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    What if the faction starts off with a Constable? Might that solve problems?

    Creator of Kingdoms of Heaven

  10. #10
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Creating Unique Units?

    It's worth a try, if by start with you mean changing the first number in the recruit pool to 1. If it just starts with one spawned somewhere I don't see how that would rectify anything.

  11. #11
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    EDIT:

    Got rid of Jerusalem being able to retrain it, enabled the King's Stables to come with the Constable ready to recruit, set the refresh rate to 0, and changed the maximum capacity to 1. And Augustus's script seems to be working just fine! The turn after I disbanded the Constable, I was able to recruit him again. On top of that, if he's in the recruit queue and I cancel him, he is available to be recruited again immediately.

    The only problem I see with this is that when the player gets another King's Stables, it comes with the Constable ready for recruitment (at least from testing thus far). So as it stands, the player is able to get a second Constable. So I'm gonna see if there's a way I can fix this...
    Last edited by King Siegfried; September 23, 2009 at 01:22 PM.

    Creator of Kingdoms of Heaven

  12. #12
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Creating Unique Units?

    Glad to hear it. As an addendum, if you need to manipulate a pool of this nature the best way to do it is using the command set_recruit_pool or inc_recruit_pool in a script. The reason I mention this is since you have 0 replenish rate, it might only be adding a unit to the pool because you disbanded it in Jerusalem, so if it were to die in battle I'd imagine the recruit pool wouldn't change back to 1. You could use this to have the starting number at 0, replenish at 0, and max at 1. Then just increase the recruit pool by 1 when you need to recruit it, such as in the I_UnitExists monitor.

  13. #13
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    I think I see what you're saying. So just drop it down to 0 0 1 (instead of 1 0 1), and let the script do the pool setting? I'm going to give it a shot, and I'll let you know how it works out.

    EDIT :: I'm not sure I'm understanding what you're trying to point me towards. So I'm going to spend some time looking up scripting tuts and see if I can figure this out by myself. I really appreciate the help, Augustus. I'll post here if I keep having trouble.

    EDIT #2 :: Argh. I'm lost, and don't see a similar script being discussed elsewhere. I'm gonna keep trying different things, but if you figure out what I'm doing wrong, please let me know. I really appreciate it!
    Last edited by King Siegfried; September 23, 2009 at 06:13 PM.

    Creator of Kingdoms of Heaven

  14. #14

    Default Re: Creating Unique Units?

    Have the unit in game via the strategic file, but omit it from the buildings file so it cannot be built and does not generate replacements, and or, arrive via spawn.

    If you want it to have repalcements, asign it to a charcter as a bodygaurd unit and it gets free repalcements. Of course it will not e ba free upkeep unit however as no one can build it, but you can get free upkeep ina fort.

    Hope that helps.

  15. #15
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    That won't work because the Constable of Jerusalem is the KoJ's final cavalry from the King's Stables. For my purposes, it needs to come from the King's Stables, and it needs to be unique. Whether or not it exists at the start of the campaign is unimportant at this point. As long as it works, I'm fine.

    Now, regarding that, I decided to just go back to the Crusades campaign's script, copy it, and have the player start the campaign with the unit. And now the script isn't working, which is really upsetting me. Why would it work in Crusades and not SS? They both use Kingdoms, do they not?

    Creator of Kingdoms of Heaven

  16. #16
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Creating Unique Units?

    Quote Originally Posted by King Siegfried View Post
    That won't work because the Constable of Jerusalem is the KoJ's final cavalry from the King's Stables. For my purposes, it needs to come from the King's Stables, and it needs to be unique. Whether or not it exists at the start of the campaign is unimportant at this point. As long as it works, I'm fine.

    Now, regarding that, I decided to just go back to the Crusades campaign's script, copy it, and have the player start the campaign with the unit. And now the script isn't working, which is really upsetting me. Why would it work in Crusades and not SS? They both use Kingdoms, do they not?
    Well the Crusades script first of all uses a deprecated practice of using add_events but that won't kill the script, the script should work fine. The discrepancy is likely that they have two recruit pools, one that only turns on when there isn't an existing Constable and probably functions to bump the pool up to 1. I'd still suggest doing it via script though. Try this:
    Code:
    ; Sets recuit pool based on whether the unit existed last turn
    monitor_event FactionTurnStart FactionIsLocal
    		and FactionType jerusalem
    		
    	if I_UnitExists jerusalem Constable of Jerusalem
    		set_event_counter constable 1
    		set_event_counter constable_existed 1
    	end_if
    	if not I_UnitExists jerusalem Constable of Jerusalem
    		set_event_counter constable 0
    		; If the constable existed last turn, we let it be recruited again
    		if I_EventCounter constable_existed == 1
    			inc_recruit_pool Jerusalem_Province -2 Constable of Jerusalem
    			inc_recruit_pool Jerusalem_Province 1 Constable of Jerusalem
    		end_if
    		set_event_counter constable_existed 0
    	end_if
    end_monitor
    
    ;Resets recruit pool to 0 once it has been recruited
    monitor_event UnitTrained UnitType Constable of Jerusalem
    		and FactionType jerusalem
    		and FactionIsLocal
    	inc_recruit_pool Jerusalem_Province -2 Constable of Jerusalem	
    	set_event_counter constable_existed 1
    	set_event_counter constable 1
    end_monitor
    
    ;Un-comment this line if the constable exists initially
    ;set_event_counter constable_existed 1
    And this as the recruit pools in the EDB:
    Code:
    recruit_pool "Constable of Jerusalem" 0 0 1 0 requires factions { jerusalem, } and event_counter constable 0 
    recruit_pool "Constable of Jerusalem" 0 0.1 0.99 0 requires factions { jerusalem, } and event_counter constable 1
    I haven't tested it expressly. What it should do is if the unit doesn't exist, increase the recruit pool to 1 so it can be recruited. If it does exist, say that it existed so that the next turn it can pick that up. The reason for this is while a unit is being trained it won't 'exist', so if you didn't check whether it existed last turn then it'd just keep increasing it by 1 until the unit is built. The order is also very specific in the first monitor, because if you set the constable_existed counter back to 0 before the if statement it would invalidate itself. The recruit pools are setup so that while the constable exists it increases 0.1 per turn to a max of 0.99, and when it doesn't exist the max is 1 but it doesn't get any increase as that comes from the script. If you add it to the queue and then remove it, it should add the unit back into the pool automatically since it was never made, unless I'm forgetting something.
    Last edited by Augustus Lucifer; September 24, 2009 at 06:03 PM.

  17. #17
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    Hmmmm. I want to say I'm starting to understand how the scripting works. I've been trying to test it out, but I won't be sure about anything until I can test it some more tomorrow. As it stands right now, it seems to work, except the Canons (I'm testing it on them as they will be a unique unit as well) are a little buggy. Once the Canons are recruited (or already implemented via strat) and either die, or are disbanded, the next turn they are recruitable again (hooray!). However then I noticed that the Canons said "turns until next available: 7". I kept ending turn to see if it was just a bug, but the Canons can indeed be recruited a second time after waiting the 7 turns.

    That being said, it's quite possible that's due to an error on my part, and I want to keep testing it.

    Thanks for your constant help, Augustus. On a side note, I'm looking forward to your Song Dynasty mod, and can't wait to play it. It looks amazing.

    Creator of Kingdoms of Heaven

  18. #18
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Creating Unique Units?

    Quote Originally Posted by King Siegfried View Post
    Hmmmm. I want to say I'm starting to understand how the scripting works. I've been trying to test it out, but I won't be sure about anything until I can test it some more tomorrow. As it stands right now, it seems to work, except the Canons (I'm testing it on them as they will be a unique unit as well) are a little buggy. Once the Canons are recruited (or already implemented via strat) and either die, or are disbanded, the next turn they are recruitable again (hooray!). However then I noticed that the Canons said "turns until next available: 7". I kept ending turn to see if it was just a bug, but the Canons can indeed be recruited a second time after waiting the 7 turns.

    That being said, it's quite possible that's due to an error on my part, and I want to keep testing it.

    Thanks for your constant help, Augustus.
    It's possible there's a recruit pool for the Canon in addition to the two you added that hasn't been removed, since 0.1 x 7 =/= 1. It's also possible this is due to some function of the recruit pools that I'm overlooking, I haven't had the time to do all the tests with them that I'd like and they aren't really documented in full anywhere. One solution would be to keep applying a -1 to the recruit pool in the first I_UnitExists if statement, it wouldn't fix it saying it could be recruited but at least it never would be. Another solution which would only work if the inc_recruit_pool command ignores the maximum of a recruit pool, would be to just ditch the pool that maxes at 1 altogether and keep the 0.99 one.

    Quote Originally Posted by King Siegfried View Post
    On a side note, I'm looking forward to your Song Dynasty mod, and can't wait to play it. It looks amazing.
    Thanks.

  19. #19
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    Quote Originally Posted by Augustus Lucifer View Post
    One solution would be to keep applying a -1 to the recruit pool in the first I_UnitExists if statement, it wouldn't fix it saying it could be recruited but at least it never would be.
    It worked! Unless there's a situation where someone loses their Canons the very first turn it's recruited - say, the city is attacked (which in most cases won't happen), the Canons are always available to be recruited. I haven't tested the city siege scenario yet, but it should be easy enough to prevent losing the Canons like that, so I'm not going to worry about it.

    Now I'm going to see about combining the Canons script with the original Sauron script you provided me and see if I can get the Constable to work properly even from the Kings Stables. If not, I'll just work around the script and have them recruited only from Jerusalem, which doesn't matter too much so long as it actually works, right?

    Anyway, thanks again for all the help!

    Creator of Kingdoms of Heaven

  20. #20
    King Siegfried's Avatar Semisalis
    Join Date
    Feb 2009
    Location
    Savannah, GA
    Posts
    474

    Default Re: Creating Unique Units?

    An update ::
    Code:
    declare_counter no_constable
    
    monitor_condition not I_UnitExists Faction Unit
      set_event_counter no_constable 0
    end_monitor
    
    monitor_condition I_UnitExists Faction Unit
      set_event_counter no_constable 1
    end_monitor
    coupled with
    Code:
    recruit_pool "Constable of Jerusalem" .75 .25 1 0 requires factions { jerusalem, }  and event_counter no_constable 1 
    recruit_pool "Constable of Jerusalem" 0 0.1 0.99 0 requires factions { jerusalem, }  and not event_counter no_constable 1
    in the EDB results in the Constable being more or less a unique unit. My only question is whether or not you can script the game to monitor what is in a recruitment queue. I seem to recall Augustus Lucifer saying before that you can't do this, but I can't find where he said that. The reason I ask this? If players get two citadels, let their Constable die, and wait for both citadels to fill the queue up, then they could recruit two Constables at the same time.

    If there's no way around that, then I'll leave it up to the players to be "honest" about it lol.

    Creator of Kingdoms of Heaven

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
  •