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

Thread: I_NumberUnitsInSettlement

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 I_NumberUnitsInSettlement

    EDIT: to sum up the findings: I_NumberUnitsInSettlement takes a unit Type as its argument (not Dictionary or Name) and it doesn't work if the Type contains spaces. e.g. Breeland_Militia will work; Breeland Militia will not, even if put in quotes.


    I've tried for hours, and searched, and I just cannot figure this one out. ... help?

    How do you use it with a unit that has more than one word in the name?

    EDIT: post #8 gives a better explanation of the problem

    To use a simple example, playing a new campaign as England in M2TW...

    (M2TW)\data\world\maps\campaign\imperial_campaign\campaign_script.txt

    Code:
    monitor_event FactionTurnStart england	
      if I_NumberUnitsInSettlement London Peasants > 0
        console_command add_money 20000
      end_if
    end_monitor
    That works fine. But if I try the same for Town Militia it doesn't work. I tried all of the following, where Peasants is above:
    • Town_Militia
    • "Town Militia"
    • Town Militia


    The first one does nothing but no script errors while the second two give me a "Number of units not declared" error and seem to work but I think the whole "if" line is being ignored and the add_money command is being made every turn regardless of whether these guys are in the settlement or not.

    Anybody have any ideas?
    Last edited by Withwnar; February 11, 2012 at 02:30 AM.

  2. #2

    Default Re: I_NumberUnitsInSettlement

    Use this bro.
    100% sure about this:-
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	and I_NumberUnitsInSettlement London town_militia > 0
    	add_money England 20000
    	end_monitor
    Not 100% sure
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	if I_NumberUnitsInSettlement London town_militia > 0
    	add_money England 20000
    	end_if
    	end_monitor
    Last edited by Ishan; August 19, 2010 at 09:20 AM.

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

    Default Re: I_NumberUnitsInSettlement

    Thanks Ishan but still no joy. (+rep by the way )

    I realise now that I missed the "FactionType england" although it still worked for Peasants.

    "add_money England 20000" gave me a "don't recognise this token: add_money" error.

    I have Kingdoms installed even though I'm trying this on M2 vanilla. I don't know if that makes any difference.

    Anyway... this works:
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	and I_NumberUnitsInSettlement London Peasants > 0
    	console_command add_money 20000
    	end_monitor
    and this doesn't:
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	and I_NumberUnitsInSettlement London town_militia > 0
    	console_command add_money 20000
    	end_monitor
    No errors. Just does nothing.

    I'm actually trying to get this working for a custom unit of mine. I renamed its [type] so that its type, dictionary and name were all different:
    type = CustomUnit
    dictionary = Custom_Unit
    name = Custom Unit
    When I make the I_NumberUnitsInSettlement call with CustomUnit then it works so it looks like type is needed here, which for Town Militia is [Town Militia] (space, no underscore).

    But if I try:
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	and I_NumberUnitsInSettlement London town militia > 0
    	console_command add_money 20000
    	end_monitor
    I get a "Number of units not declared" error, as described before. It seems to work but move that guy out of London and the money keep rolling in anyway. (Also tried Town Militia (caps)).
    Last edited by Withwnar; August 19, 2010 at 10:06 AM.

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

    Default Re: I_NumberUnitsInSettlement

    l'd test 'and I_NumberUnitsInSettlement London' to see what err message I get. Then 'and I_NumberUnitsInSettlement London town_militia'. Then 'and I_NumberUnitsInSettlement London town_militia = 1'.

    I don't know if it would help, I'd just be trying to learn what the error messages mean.

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

    Default Re: I_NumberUnitsInSettlement

    Quote Originally Posted by Taiji View Post
    l'd test 'and I_NumberUnitsInSettlement London' to see what err message I get. Then 'and I_NumberUnitsInSettlement London town_militia'. Then 'and I_NumberUnitsInSettlement London town_militia = 1'.

    I don't know if it would help, I'd just be trying to learn what the error messages mean.
    Thanks Taiji but no go:

    and I_NumberUnitsInSettlement London
    ==> "Number of units not declared" error

    and I_NumberUnitsInSettlement London town_militia
    ==> "Number of units not declared" error

    and I_NumberUnitsInSettlement London town_militia = 1
    ==> no errors but does nothing (condition fails)

  6. #6

    Default Re: I_NumberUnitsInSettlement

    First of all in vanilla this command "add_money England 20000" doesn't work it works in kingdoms only.
    For vanilla u have to use "console_command add_money 20000".

    Anyways u can use "monitor_event FactionTurnStart"
    But for giving the money u have to define the faction type also.

    But out of curiosity why are u making a mod on vanilla coz kingdoms have a load of new features that vanilla doesn't have. Use a modfolder mod like BareGeomod that is default vanilla but uses kingdoms.exe file to launch itself.

    I'll back in a few mins gotta make dinner.

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

    Default Re: I_NumberUnitsInSettlement

    Cheers Ishan.

    I'm making the mod in Kingdoms (TATW) but I was having no luck with this condition so I thought I would "go back to basics" and try it at the root level, so to speak.

    I only included the add_money as a test to see if it's working. I'm not too concerned with only giving it to my faction etc. I was just going for a simple example for posting's sake.

    All of those scenarios I tried apply also to Kingdoms (well, TATW at least). I could successfully test for "Bandits" but not "Breeland Militia" for example.

    As it happens it's now working for me since I renamed my unit's type so that it doesn't include spaces. But a time will come when I will need to use it on units that I can't rename so I'm still curious about the solution.

    Thanks for the BareGeomod tip. I'll check that out.

  8. #8

    Default Re: I_NumberUnitsInSettlement

    Are you sure that town_militia is a valid unit name in the mod that you were using? There's no such entry for TATW for instance. The docudemons' example shows the dictionary name for the unit should be used and that's the one with the underscores. Searching for Breeland Militia with a space wouldn't work, because the dictionary name for that unit is Breeland_Militia.

    So with your custom unit above, you should be using Custom_Unit and not CustomUnit. I'm not sure how fiddly it is with capitals and lowercase but best match the dictionary name exactly as well.

    EDIT- and also, double check that the faction can use the unit specified.
    Currently following these promising mods - Imperia Antiquitatis by Splenyi
    Traits, Talents, and Toadies
    by Hellbent
    Real Roman Reforms
    by Aodh Mor
    Unit Icons project
    by Bullgod
    Also recommended:
    City Sack, Liberation and Diplomatic Options
    by Dresden

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

    Default Re: I_NumberUnitsInSettlement

    Sorry guys, my efforts to simplify things and then explain the full story out of sequence is creating confusion. I'll start again...

    I'm making a submod for TATW (Kingdoms) that provides a unit named "Elven Rangers". It is trying to do this in campaign_script.txt:
    Code:
    monitor_event FactionTurnStart turks	
      if I_NumberUnitsInSettlement Bree Elven_Rangers > 0
        {do something}
      end_if
    end_monitor
    This didn't work. Taking my unit out of the equation I tried again with standard TATW units for the "turks" faction:
    Breeland Militia (type = Breeland Militia, dictionary = Breeland_Militia)
    Bandits (type = Bandits, dictionary = Bandits)

    This worked:
    Code:
    monitor_event FactionTurnStart turks	
      if I_NumberUnitsInSettlement Bree Bandits > 0
        {do something}
      end_if
    end_monitor
    But this:
    Code:
    monitor_event FactionTurnStart turks	
      if I_NumberUnitsInSettlement Bree Breeland_Militia > 0
        {do something}
      end_if
    end_monitor
    did nothing (but no errors in the log).

    When I tried either of these:
    Code:
    monitor_event FactionTurnStart turks	
      if I_NumberUnitsInSettlement Bree Breeland Militia > 0
        {do something}
      end_if
    end_monitor
    Code:
    monitor_event FactionTurnStart turks	
      if I_NumberUnitsInSettlement Bree "Breeland Militia" > 0
        {do something}
      end_if
    end_monitor
    then at first glance it appears to work but if I take that unit out of the city then it still works, which it shouldn't do. Looking at the log shows a "Number of units not declared" error. My guess is the IF statement is failing to parse and therefore being ignored so the {do something} is always being called - no longer being wrapped in an IF block.

    Flummoxed, I wanted to see if vanilla M2TW had this same behaviour - using add_money as the {do something} - and sure enough it does.

    Okay, so now I have installed BareGeomod and tried again in London with:
    Town Militia (type = Town Militia, dictionary = Town_Militia)
    Peasants (type = Peasants, dictionary = Peasants)

    Peasants works fine.
    Town_Militia and town_militia do nothing.
    Town Militia and "Town Militia" give the same error and ignore-IF behaviour as before.

    I tried both structures:
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	and I_NumberUnitsInSettlement London town_militia > 0
    	add_money England 20000
    	end_monitor
    and:
    Code:
    monitor_event FactionTurnStart FactionType england
    	and I_SettlementOwner London = england
    	
      if I_NumberUnitsInSettlement London town_militia > 0
        add_money England 20000
      end_if
    end_monitor

    Now, here's the strange thing. I renamed my Elven Ranger unit's "type" so that it didn't contain spaces:
    type = ElvenRangers
    dictionary = Elven_Rangers
    name = Elven Rangers

    Using ElvenRangers in the call works perfectly. The {do something} does its thing when this unit is in the city and doesn't do it when they're out of the city.

    Surely this means, then, that type is the parameter to use, not dictionary. Which begs the question: how can you use a type that contains spaces? Because Town Militia, "Town Militia", Breeland Militia and "Breeland Militia" all failed with that error and ignore-the-IF behaviour.

    The Docudemons say to use the "unit type (id)" and then uses a dictionary name in its sample. Maybe using dictionary is how RTW did it? I know that some of the samples are out of date.

    @Taiji
    Sorry mate - I only just noticed your post. I'll take a look at what you suggested.

    +reps all round for trying to help

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

    Default Re: I_NumberUnitsInSettlement

    OK maybe I'm being slow here but, the number of units is counted as undeclared when the unit name is absent. I would just check that it's the same when the unit name is wrong, use a nonexistant unit name. Just so I knew that this is taken into account and reported. But I might be 'being slow', you might have mentioned something already that makes this pointless, having already confirmed it one way or the other. I have just woken up

    declare_counter breakfast

    monitor_conditions I_NumberUnitsInSettlement London town_militia = 1
    and I_CompareCounter breakfast = 0
    set_counter breakfast 1
    end_monitor

    monitor_event FactionTurnStart FactionType England
    and I_CompareCounter breakfast = 1
    console_command add_money 20000
    end_monitor

    Maybe that helps.... I need some breakfast I think...

  11. #11

    Default Re: I_NumberUnitsInSettlement

    I think the lesson to be learned here is to not have spaces in your unit names!
    Currently following these promising mods - Imperia Antiquitatis by Splenyi
    Traits, Talents, and Toadies
    by Hellbent
    Real Roman Reforms
    by Aodh Mor
    Unit Icons project
    by Bullgod
    Also recommended:
    City Sack, Liberation and Diplomatic Options
    by Dresden

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

    Default Re: I_NumberUnitsInSettlement

    @Taiji
    I hope you enjoyed your breakfast. I tried what you suggested using the incorrectly-named town_militiax as the parameter and nothing happened - no error but no result (the condition check presumably returned false).

    In my mind the end of post #8 puts it in a nutshell: TYPE is the expected parameter, not DICTIONARY. And I cannot for the life of me figure out how use this on a unit that has spaces in its TYPE name.

    Quote Originally Posted by redxavier View Post
    I think the lesson to be learned here is to not have spaces in your unit names!
    Indeed, this is what I'm (almost) ready to conclude. I'm hoping that someone else will get it to work and tell me where I'm going wrong (Ishan kindly offered to test it himself ).

    If it turns out that this is the case then this condition is unusable on the majority of units I've seen so far. Ones that I can't change the TYPE of I mean.

    EDIT:
    Quote Originally Posted by Gigantus View Post
    I am wondering if it is possible to use a description instead of the unit name, eg cavalry or mercenary_unit
    It would be consistent with many/most other unit tests. Yet it does work when using a TYPE with no spaces.
    Last edited by Withwnar; August 20, 2010 at 11:52 AM.

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

    Default Re: I_NumberUnitsInSettlement

    Quote Originally Posted by Withwnar View Post
    @Taiji
    I hope you enjoyed your breakfast. I tried what you suggested using the incorrectly-named town_militiax as the parameter and nothing happened - no error but no result (the condition check presumably returned false).

    In my mind the end of post #8 puts it in a nutshell: TYPE is the expected parameter, not DICTIONARY. And I cannot for the life of me figure out how use this on a unit that has spaces in its TYPE name.
    Yep, breakfast was great, thankyou

    You could indeed have nailed the problem down already.

    Unit types are only used in recruitment related files. So a unit type change is just a find and replace operation in about 4 or 5 files and you've solved your problem.

    Interesting that spaces work everywhere else, unless I miss something, so I guess this particular condition checker is unusually 'underdeveloped'.
    Last edited by Taiji; August 20, 2010 at 12:19 PM.

  14. #14
    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: I_NumberUnitsInSettlement

    I am wondering if it is possible to use a description instead of the unit name, eg cavalry or mercenary_unit










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

    Default Re: I_NumberUnitsInSettlement

    Yeah I wondered that when I was looking for a solution to a different problem, but then the docudemons is pretty specific. I suppose it could be wrong about this, but I didn't test it. descr_formations_ai.txt uses unit_type to designate unit attribute labels, if needed, so to me that's a pointer towards the possibility.
    Last edited by Taiji; August 20, 2010 at 11:50 AM.

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

    Default Re: I_NumberUnitsInSettlement

    My suspicion is that RTW used DICTIONARY but it was changed to TYPE in M2TW without modifying the parser to handle spaces. Pure guesswork based on the Docudemons using a dictionary entry in its sample - could be way, way off of course.

    Well, thanks all for the input. Hopefully the next time somebody is banging their head against a wall trying to get this to work they'll find this thread quickly.

    Is it worth adding this tip to the Wiki entry? Or am I jumping the gun?

  17. #17

    Default Re: I_NumberUnitsInSettlement

    Bro i'm a little busy writing a mod preview in WIKI so as soon as i get free i try it further till now no success.

    After i confirm it then i'll edit the WIKI entry for the command as well.

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

    Default Re: I_NumberUnitsInSettlement

    No worries Ishan. That would be great. Thanks.

  19. #19

    Default Re: I_NumberUnitsInSettlement

    Not all commands in the docudemons work, and some of the commands are meant for specific use in specific files (but being in the docudemons are generally all usable in the campaign script) - such as commands for the factionstandings file, traits file, EDB, Missions etc. Some are not necersarily intended for the campaign script but can more often then not still be used in the campaign script, if u follow my meaning. It is therefore possible you stumbled onto one of those specific commands. Has anyone tried to see if this command works in Missions, EDB, or any other scripted file as intended (with the SPACE in the TYPE name)?

    Unit type works in Missions and EDB and im sure it works in factionstandings. Therefore im of the belief this command is meant for those files.

    Just my 2 cents.
    ...longbows, in skilled hands, could reach further than trebuchets...

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

    Default Re: I_NumberUnitsInSettlement

    Quote Originally Posted by Tsarsies View Post
    Unit type works in Missions and EDB and im sure it works in factionstandings. Therefore im of the belief this command is meant for those files.
    Forgive my newbieness here but can conditions be used in EDB?

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
  •