Results 1 to 8 of 8

Thread: Spawning Random Percentage Army Only Once

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Spawning Random Percentage Army Only Once

    I am trying to script an army to spawn between certain turns and with a random percentage chance. I have succeeded with this code:

    Code:
    declare_counter Dyfnwalexist
    monitor_conditions not I_CharacterExists Dyfnwal
    set_counter Dyfnwalexist 0
    end_monitor
    monitor_event FactionTurnStart FactionType slave
    and I_SettlementOwner Dumbarton = slave
    and I_TurnNumber > 34
    and I_TurnNumber < 61
    and RandomPercent < 31
    if I_CompareCounter Dyfnwalexist = 0
    spawn_army 
    faction slave, sub_faction scotland
    character Dyfnwal, named character, family, age 25, x 101, y 167
    traits LoyaltyStarter 1 , NaturalMilitarySkill 1 , BattleChivalry 2 , StrategyChivalry 2 , GoodCommander 3 , ReligionStarter 1
    unit  Scottishda Bodyguard   exp 4 armour 2 weapon_lvl 0
    unit  Border Horse    exp 4 armour 2 weapon_lvl 0
    unit  Border Horse    exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Swordsmen   exp 4 armour 3 weapon_lvl 0
    unit  Brythonic Swordsmen   exp 4 armour 3 weapon_lvl 0
    unit  Brythonic Spearmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Spearmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Spearmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Bowmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Bowmen   exp 4 armour 2 weapon_lvl 0
    end
    end_if
    set_counter Dyfnwalexist 1
    end_monitor
    I would like this army to spawn only once as it would not make any sense for the general to return from the dead. How should this code end?

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

    Default Re: Spawning Random Percentage Army Only Once

    Like this:

    Quote Originally Posted by sputnik View Post
    Code:
    monitor_event FactionTurnStart FactionType slave
    and I_SettlementOwner Dumbarton = slave
    and I_TurnNumber > 34
    and I_TurnNumber < 61
    and RandomPercent < 31
    spawn_army 
    faction slave, sub_faction scotland
    character Dyfnwal, named character, family, age 25, x 101, y 167
    traits LoyaltyStarter 1 , NaturalMilitarySkill 1 , BattleChivalry 2 , StrategyChivalry 2 , GoodCommander 3 , ReligionStarter 1
    unit  Scottishda Bodyguard   exp 4 armour 2 weapon_lvl 0
    unit  Border Horse    exp 4 armour 2 weapon_lvl 0
    unit  Border Horse    exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Swordsmen   exp 4 armour 3 weapon_lvl 0
    unit  Brythonic Swordsmen   exp 4 armour 3 weapon_lvl 0
    unit  Brythonic Spearmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Spearmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Spearmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Bowmen   exp 4 armour 2 weapon_lvl 0
    unit  Brythonic Bowmen   exp 4 armour 2 weapon_lvl 0
    end
    terminate_monitor
    end_monitor
    Last edited by Taiji; February 25, 2011 at 03:26 PM.

  3. #3

    Default Re: Spawning Random Percentage Army Only Once

    perfect thanks Taiji

  4. #4

    Icon1 Re: Spawning Random Percentage Army Only Once

    Sputnik: If you want to make a script that only runs once you just need to add ‘terminate_monitor’ to the end of it, just as Taiji did in the script he posted. Taiji is also right in that you do not need to use a counter in your script. A counter would really only be useful if you want to have multiple spawns, for example if you wanted a 31% chance that a spawn could happen each turn between turns 34 and 61, then it would be useful to use a counter in your script.

    Though you do need to declare any counter that you use in a script, you only need to set a counter initial value if you wanted its initial value to be greater than zero, because a ‘declare’ counter value is zero.

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

    Default Re: Spawning Random Percentage Army Only Once

    You're welcome, Sputnik

  6. #6

    Default Re: Spawning Random Percentage Army Only Once

    A counter would really only be useful if you want to have multiple spawns
    yes, I am planning on having multiple viking invasion spawns and this would be ideal. Like a counter number 1-10, each number being a different spawned army in a different location?

  7. #7

    Icon1 Re: Spawning Random Percentage Army Only Once

    Quote Originally Posted by sputnik View Post
    yes, I am planning on having multiple viking invasion spawns and this would be ideal. Like a counter number 1-10, each number being a different spawned army in a different location?
    :
    Code:
    declare_counter french_fleet
    
    	monitor_event FactionTurnStart FactionType france
    		and IsFactionAIControlled
    		and DiplomaticStanceFromFaction england = AtWar
    		and not I_UnitExists france cog
    		and I_CompareCounter french_fleet <= 2
    		inc_counter french_fleet 1
    		generate_random_counter location_of_French_fleet 1 3
    		if I_EventCounter location_of_French_fleet = 1
            spawn_army
                	faction france
                	character    	random_name, admiral, age 21, x 327, y 141, direction N
                	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
            end
    	end_if
    		if I_EventCounter location_of_French_fleet = 2
            spawn_army
                	faction france
                	character    	random_name, admiral, age 21, x 316, y 169, direction N
                	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
            end
    	end_if
    		if I_EventCounter location_of_French_fleet = 3
            spawn_army
                	faction france
                	character    	random_name, admiral, age 21, x 298, y 126, direction N
                	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
               	unit         	cog                	exp 2 armour 0 weapon_lvl 0
            end
    	end_if
    		set_event_counter location_of_French_fleet 0
    	end_monitor

  8. #8

    Default Re: Spawning Random Percentage Army Only Once

    Interesting, I have been using
    Code:
    and not I_LocalFaction
    and not
    Code:
    and IsFactionAIControlled


    Thanks again TNZ, you have been a great help.

    I will give it a go tomorrow.

    Luck is the residue of design ~ Milton

Posting Permissions

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