Results 1 to 20 of 20

Thread: Help with script!

Hybrid View

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

    Default Help with script!

    Hi! Could anyone help me with a script issue please?

    I'm trying to spawn a general with some troops. The problem is that my script does everything it is supposed to do, but 1 thing.

    When it is supposed to move a named character (character_move) to a specific location, it doesn't do it. This issue only happens with 1 faction, for other factions is working correctly and its exactly the same dynamic. Also, some times it moves a totaly different unit but the named character remains at the same place. So I don't know what I'm doing wrong or missing.

    Now let me explain the code a little bit.

    First it fires an historic event and increments an event counter for several turns, when the counter is 8 it:

    • Sets event counter to 9.
    • Kills a named character if exists.
    • If condition "Pxs_Rhun_CInvasion " is true, it spaws a general for a faction with different amount of units depending on another counter "Pxs_Invasion_Type".
    • Once spawned the faction declares war to local faction.
    • Then, if faction is local it moves the character next to its capital. (this is the part that is not working correctly)
    • Finally it fires another event and gives a trait to the spawned character.


    Code:
    ;Invasion Started
    monitor_event FactionTurnStart FactionIsLocal
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and I_EventCounter Pxs_Evil_Invasion_Ready = 1
    	and I_EventCounter Pxs_Evil_Invasion_Faction_Assigned = 1
    	and not I_EventCounter Pxs_Invasion_Cancelled > 0
    		ui_flash_stop
    		;Enemy army arrived, move to safe position near target settlement
    		if I_EventCounter Pxs_Invasion_Phase = 8
    		
    				set_event_counter Pxs_Invasion_Phase 9
    				
    				if I_CharacterExists Cinvader
    					kill_character Cinvader
    				end_if
    				if not I_CharacterExists Cinvader
    				
    					;Rhun
    					if I_EventCounter Pxs_Rhun_CInvasion = 1
    						if not I_EventCounter Pxs_Invasion_Type > 0
    							spawn_army
    							faction venice
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    							end
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 1
    							spawn_army
    							faction venice
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    							unit	Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    							unit	Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    							unit	Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    							end
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							spawn_army
    							faction venice
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    							unit	Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    							unit	Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    							unit	Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    							unit	Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    							unit	Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    							unit	Mounted Clanguard	exp 2 armour 0 weapon_lvl 0
    							unit	Mounted Clanguard	exp 1 armour 0 weapon_lvl 0
    							end
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							spawn_army
    							faction venice
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    							unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    							unit	Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    							unit	Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    							unit	Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    							unit	Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    							unit	Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    							unit	Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    							unit	Mounted Clanguard	exp 2 armour 0 weapon_lvl 0
    							unit	Mounted Clanguard	exp 1 armour 0 weapon_lvl 0
    							unit	Mounted Clanguard	exp 4 armour 0 weapon_lvl 0
    							unit	Rhunnic Elite Infantry	exp 1 armour 0 weapon_lvl 0
    							unit	Rhunnic Elite Archers	exp 1 armour 0 weapon_lvl 0
    							unit	Rhunnic Elite Archers	exp 3 armour 0 weapon_lvl 0
    							end
    						end_if
    						;Declare war, mov camera, mov army 
    						if I_LocalFaction sicily
    							console_command diplomatic_stance venice sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance venice milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance venice egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance venice mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance venice moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance venice turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance venice byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance venice scotland War
    						end_if
    					end_if
    					;Repeat same code for each faction
    				end_if
    					
    				if I_LocalFaction sicily
    				and I_SettlementOwner Anorien = sicily
    					snap_strat_camera 246 , 129
    					console_command move_character Cinvader, 246 , 129
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction milan
    				and I_SettlementOwner Kings-Land = milan
    					snap_strat_camera 192 , 154
    					console_command move_character Cinvader, 192 , 154
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction egypt
    				and I_SettlementOwner Imladris = egypt
    					snap_strat_camera 182 , 250
    					console_command move_character Cinvader, 182 , 250
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction mongols
    				and I_SettlementOwner Elven-Mirkwood = mongols
    					snap_strat_camera 258 , 267
    					console_command move_character Cinvader, 258 , 267
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction moors
    				and I_SettlementOwner Erebor = moors
    					snap_strat_camera 296 , 264
    					console_command move_character Cinvader, 296 , 264
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction turks
    				and I_SettlementOwner Bree = turks
    					snap_strat_camera 125 , 247
    					console_command move_character Cinvader, 125 , 247
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction byzantium
    				and I_SettlementOwner Lake_Evendim = byzantium
    					snap_strat_camera 98 , 259
    					console_command move_character Cinvader, 98 , 259
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction scotland
    				and I_SettlementOwner Dale = scotland
    					snap_strat_camera 296 , 264
    					console_command move_character Cinvader, 296 , 264
    					console_command mp Cinvader -250
    				end_if
    				console_command give_trait Cinvader CInvader
    				historic_event Pxs_Enemy_Army_Near_By
    		end_if
    		;Alert Incoming Invasion
    		if not I_EventCounter Pxs_Invasion_Phase > 0
    			historic_event Pxs_Inminent_Invasion
    		end_if
    		;Wait 3 turns
    		if I_EventCounter Pxs_Invasion_Phase < 8
    			inc_event_counter Pxs_Invasion_Phase 1
    		end_if
    end_monitor
    In the end the named character spawns and all historic events fire up, but I never manage to move it correctly for certain factions, so spawned units get stuck at the spawned position for the entire campaign since it is a restricted area.

    Thanks in advance for your help.
    Regards!

  2. #2
    Emperor of Hell's Avatar SPA-NED 1-5
    Join Date
    Jul 2011
    Location
    Netherlands
    Posts
    5,747

    Default Re: Help with script!

    What faction doesn't work?

    edit: nvm

  3. #3

    Default Re: Help with script!

    Quote Originally Posted by Emperor of Hell View Post
    What faction doesn't work?

    edit: nvm
    Those lines mean that I repeat the same code for each faction. I didn't paste it because it would make the code too long.

    edit:

    It just doesn't work for venice. When I test this with england or spain, it works.

    edit 2:

    Go it working now.

    Added "wait 5" just before moving the character and it seems is working now, very wierd.
    Last edited by proximusj; February 02, 2012 at 09:56 AM.

  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: Help with script!

    Instead of just giving the character a name, which might be used by other characters, give the character a label and before creating the character use the kill character to kill any previous incarnation if necessary.
    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
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Help with script!

    Quote Originally Posted by Squid View Post
    Instead of just giving the character a name, which might be used by other characters, give the character a label and before creating the character use the kill character to kill any previous incarnation if necessary.
    The script is doing this already but it is possible that more than one character has the name, so this would only kill one of them.

    Instead of...

    Code:
    if I_CharacterExists Cinvader
      kill_character Cinvader
    end_if
    ..you could do...

    Code:
    while I_CharacterExists Cinvader
      kill_character Cinvader
    wend
    ...but this will also kill characters of other factions if that name can belong to them (as could the first method). And if using labels then killing characters shouldn't be required anyway. Unless it is your character from a previous spawn that you need to kill prior to respawning.

    If that's true (respawning is possible) then labels won't work either because you can't reuse labels with named characters.

    You might want to check this out proximusj. It is ideal for the kind of thing you're doing I think. TATW already uses this method in a few places and already has a spawning faction (Hungary).

  6. #6
    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: Help with script!

    Quote Originally Posted by Withwnar View Post
    The script is doing this already but it is possible that more than one character has the name, so this would only kill one of them.
    No its not, look at the character line there's no label being applied to the character, hence he's working with the characters name, which other characters might share, instead of with a label which can be made unique.

    Instead of...

    Code:
    if I_CharacterExists Cinvader
      kill_character Cinvader
    end_if
    ..you could do...

    Code:
    while I_CharacterExists Cinvader
      kill_character Cinvader
    wend
    ...but this will also kill characters of other factions if that name can belong to them (as could the first method). And if using labels then killing characters shouldn't be required anyway. Unless it is your character from a previous spawn that you need to kill prior to respawning.
    This is what I was getting at.
    Last edited by Squid; February 03, 2012 at 10:06 AM.
    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

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

    Default Re: Help with script!

    I meant the script is already killing the character. (I bolded your quote. )

    It looks to me like this script is to run more than once. Labels won't work: there will be a "label already exists" error every time after the first run. Unless a different label is used each time.

  8. #8

    Default Re: Help with script!

    Quote Originally Posted by Withwnar View Post
    I meant the script is already killing the character. (I bolded your quote. )

    It looks to me like this script is to run more than once. Labels won't work: there will be a "label already exists" error every time after the first run. Unless a different label is used each time.
    Exactly, I'm trying to make this script run every 50 turns.

    When I test this script in a short length of something like every 3 turns, it always works. The problem comes when I use it on a long length cycle (ex. 50 turns), the script won always work.

    As suggested, I tried using labels but for some reason if I try to spawn an army using that label again it wont work (no character will spawn).

    Code:
    while I_CharacterExists Cinvader
      kill_character Cinvader
    wend
    Thank's, this might be the solution to my problems. I guess I'll have to run these lines each turn so I can get the desired behaviour.

    Oh!, another question. I added the name "Cinvader" to descr_names.txt and placed it at the top of the name list of each faction. Does it makes any difference if I place it at the bottom, will the game use it less frequently? [Ignore this, got the answer from Withwnar tutorial.]

    Thank you all for your kind help in this matter.



    Edit: Ahhhh!!!

    I just checked your tutorial. I saw this method being used in Baron's Additional Invations script and didn't understand it that time. So if I undertand correctly, with this I can give the name "Cinvader" to hungary only. Then I can spawn the named character, move it to wherever I wan't and finally give it the correct faction?
    Last edited by proximusj; February 03, 2012 at 09:05 PM.

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

    Default Re: Help with script!

    Quote Originally Posted by proximusj View Post
    So if I undertand correctly, with this I can give the name "Cinvader" to hungary only. Then I can spawn the named character, move it to wherever I wan't and finally give it the correct faction?
    Exactly. The Palantiri script uses it too. Baron mentioned that he had some trouble getting it working at first and that he had to do it a little differently. I haven't seen his script. I have never had trouble doing it exactly how the tutorial describes so I would use that as a guide rather than Baron's (or even the Palantiri's which is a bit outdated now).

    If by "move" you mean move_character or reposition_character then yes. Or you could just spawn him to that location to begin with. But if you mean the "move" command then no; either you'll see a Hungary general moving on the map or he'll turn rebel.

    Ah, looking at your script you probably mean move_character. That's fine. But you can do the "give to faction" step before the move.

    In your script example it should just be a case of this...

    Code:
    if not I_EventCounter Pxs_Invasion_Type > 0
    	spawn_army
    	faction hungary
    	character Cinvader, named character, age 56, x 399, y 340
    	traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    	unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    	unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	unit	Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    	unit	Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    	end
    end_if
    give_everything_to_faction hungary venice false
    The tutorial mentions that sometimes units are lost in the faction "give". To avoid this - and to simplify your script a bit - you could do this...

    Spoiler Alert, click show to read: 

    WARNING: this is missing the comma separators that create_unit requires!

    Code:
    if I_EventCounter Pxs_Rhun_CInvasion = 1
    
    	;spawn the general
    	spawn_army
    		faction hungary
    		character Cinvader, named character, age 56, x 399, y 340
    		traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    		unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    	end
    	give_everything_to_faction hungary venice false
    	
    	;add his units
    	if not I_EventCounter Pxs_Invasion_Type > 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    	end_if
    	if I_EventCounter Pxs_Invasion_Type = 1
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    	end_if
    	
    	... and so on ...
    end_if

    ... or even better... as each Pxs_Invasion_Type level is just adding extra units to the level below it you could do this...

    Spoiler Alert, click show to read: 

    WARNING: this is missing the comma separators that create_unit requires!

    Code:
    if I_EventCounter Pxs_Rhun_CInvasion = 1
    
    	;spawn the general
    	spawn_army
    		faction hungary
    		character Cinvader, named character, age 56, x 399, y 340
    		traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    		unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    	end
    	give_everything_to_faction hungary venice false
    	
    	;add his units
    	;base level
    	create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    
    	if I_EventCounter Pxs_Invasion_Type >= 1
    		create_unit Cinvader, Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    	end_if
    	if I_EventCounter Pxs_Invasion_Type >= 2
    		create_unit Cinvader, Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Mounted Clanguard	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Mounted Clanguard	exp 1 armour 0 weapon_lvl 0
    	end_if
    	if I_EventCounter Pxs_Invasion_Type = 3
    		create_unit Cinvader, Mounted Clanguard	exp 4 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Elite Infantry	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Elite Archers	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Elite Archers	exp 3 armour 0 weapon_lvl 0
    	end_if
    end_if

    Quote Originally Posted by proximusj View Post
    As suggested, I tried using labels but for some reason if I try to spawn an army using that label again it wont work (no character will spawn).
    They can't be reused with named character spawns, even when using random_name, which is very frustrating. It fails to spawn, with an error in the log. However, they can be reused with normal generals (captains).

    EDIT: and another thing... if the destination tile is occupied then move_character will put your army on top of the character that's there. reposition_character will instead make him bounce off to some random place nearby. Which is worse depends on the scenario: choose your poison.
    Last edited by Withwnar; February 04, 2012 at 01:44 AM.

  10. #10

    Default Re: Help with script!

    Quote Originally Posted by Withwnar View Post
    Exactly. The Palantiri script uses it too. Baron mentioned that he had some trouble getting it working at first and that he had to do it a little differently. I haven't seen his script. I have never had trouble doing it exactly how the tutorial describes so I would use that as a guide rather than Baron's (or even the Palantiri's which is a bit outdated now).

    If by "move" you mean move_character or reposition_character then yes. Or you could just spawn him to that location to begin with. But if you mean the "move" command then no; either you'll see a Hungary general moving on the map or he'll turn rebel.

    Ah, looking at your script you probably mean move_character. That's fine. But you can do the "give to faction" step before the move.

    In your script example it should just be a case of this...

    Code:
    if not I_EventCounter Pxs_Invasion_Type > 0
    	spawn_army
    	faction hungary
    	character Cinvader, named character, age 56, x 399, y 340
    	traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    	unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    	unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	unit	Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	unit	Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    	unit	Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    	end
    end_if
    give_everything_to_faction hungary venice false
    The tutorial mentions that sometimes units are lost in the faction "give". To avoid this - and to simplify your script a bit - you could do this...

    Spoiler Alert, click show to read: 

    WARNING: this is missing the comma separators that create_unit requires!

    Code:
    if I_EventCounter Pxs_Rhun_CInvasion = 1
    
    	;spawn the general
    	spawn_army
    		faction venice
    		character Cinvader, named character, age 56, x 399, y 340
    		traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    		unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    	end
    	give_everything_to_faction hungary venice false
    	
    	;add his units
    	if not I_EventCounter Pxs_Invasion_Type > 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    	end_if
    	if I_EventCounter Pxs_Invasion_Type = 1
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    	end_if
    	
    	... and so on ...
    end_if

    ... or even better... as each Pxs_Invasion_Type level is just adding extra units to the level below it you could do this...

    Spoiler Alert, click show to read: 

    WARNING: this is missing the comma separators that create_unit requires!

    Code:
    if I_EventCounter Pxs_Rhun_CInvasion = 1
    
    	;spawn the general
    	spawn_army
    		faction venice
    		character Cinvader, named character, age 56, x 399, y 340
    		traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    		unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    	end
    	give_everything_to_faction hungary venice false
    	
    	;add his units
    	;base level
    	create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 2 armour 0 weapon_lvl 0
    	create_unit Cinvader, Easterling Clansmen	exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Balchoth Horde		exp 1 armour 0 weapon_lvl 0
    	create_unit Cinvader, Balchoth Horde		exp 3 armour 0 weapon_lvl 0
    
    	if I_EventCounter Pxs_Invasion_Type >= 1
    		create_unit Cinvader, Rhunnic Pikemen		exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Dismounted Variags	exp 3 armour 0 weapon_lvl 0
    	end_if
    	if I_EventCounter Pxs_Invasion_Type >= 2
    		create_unit Cinvader, Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Swordsmen	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Mounted Clanguard	exp 2 armour 0 weapon_lvl 0
    		create_unit Cinvader, Mounted Clanguard	exp 1 armour 0 weapon_lvl 0
    	end_if
    	if I_EventCounter Pxs_Invasion_Type = 3
    		create_unit Cinvader, Mounted Clanguard	exp 4 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Elite Infantry	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Elite Archers	exp 1 armour 0 weapon_lvl 0
    		create_unit Cinvader, Rhunnic Elite Archers	exp 3 armour 0 weapon_lvl 0
    	end_if
    end_if


    They can't be reused with named character spawns, even when using random_name, which is very frustrating. It fails to spawn, with an error in the log. However, they can be reused with normal generals (captains).

    EDIT: and another thing... if the destination tile is occupied then move_character will put your army on top of the character that's there. reposition_character will instead make him bounce off to some random place nearby. Which is worse depends on the scenario: choose your poison.
    Heh! Man my entire script is getting really heavy, and its getting very hard to test the whole thing at once. When I add something I fear that I might be ruining something else, and I lose track of what is causing problems very easily.

    Those optimization tips are very helpfull. I'll try your sugestions, I just have one doubt.

    In the code above, did you mean hungary instead of venice (code in blue)?

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

    Default Re: Help with script!

    Oops, yes you are right. It should be "faction hungary" in every occurrence of spawn_army in my examples. I'll edit my post.

    EDIT: done. Also, in case you missed my warnings, those create_unit lines should look something like this...

    Code:
    create_unit Cinvader, Easterling Clansmen, num 1, exp 1, arm 0, wep 0
    Last edited by Withwnar; February 04, 2012 at 01:49 AM.

  12. #12

    Default Re: Help with script!

    Quote Originally Posted by Withwnar View Post
    Oops, yes you are right. It should be "faction hungary" in every occurrence of spawn_army in my examples. I'll edit my post.

    EDIT: done. Also, in case you missed my warnings, those create_unit lines should look something like this...

    Code:
    create_unit Cinvader, Easterling Clansmen, num 1, exp 1, arm 0, wep 0
    It is working so far. Thanks a lot for your help +rep (when I can).

    My code ended like this, removed a lot of lines.

    Code:
    ;Invasion Started
    monitor_event FactionTurnStart FactionIsLocal
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and I_EventCounter Pxs_Evil_Invasion_Ready = 1
    	and I_EventCounter Pxs_Evil_Invasion_Faction_Assigned = 1
    	and not I_EventCounter Pxs_Invasion_Cancelled > 0
    		ui_flash_stop
    		;Enemy army arrived, move to safe position near target settlement
    		if I_EventCounter Pxs_Invasion_Phase = 8
    		
    				set_event_counter Pxs_Invasion_Phase 9
    				
    				while I_CharacterExists Cinvader
    					kill_character Cinvader
    				end_while
    				
    				if not I_CharacterExists Cinvader
    					
    					;Harad
    					if I_EventCounter Pxs_Harad_CInvasion = 1
    						spawn_army 
    							faction hungary
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Serpent Bodyguard	exp 3 armour 1 weapon_lvl 0
    						end
    						give_everything_to_faction hungary spain false
    							
    							;add his units
    							;base level
    							create_unit Cinvader, Southron Spearmen, num 4,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Corsairs, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Corsair Archers, num 1, exp 1, arm 0, wep 0
    						
    						if I_EventCounter Pxs_Invasion_Type = 1
    							create_unit Cinvader, Southron Spearmen, num 1, exp 1, arm 0, wep 0
    							create_unit Cinvader, Corsairs, num 1, exp 1, arm 0, wep 0
    							create_unit Cinvader, Corsair Archers, num 1, exp 1, arm 0, wep 0
    							create_unit Cinvader, Raiders Cavalry, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							create_unit Cinvader, Southron Pikemen, num 2, exp 1, arm 0, wep 0
    							create_unit Cinvader, Southron Lancers, num 1, exp 1, arm 0, wep 0
    							create_unit Cinvader, Mumakil, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							create_unit Dismounted Serpent Guard, num 2, exp 1, arm 0, wep 0
    							create_unit Cinvader, Southron Lancers, num 1, exp 1, arm 0, wep 0
    							create_unit Cinvader, Mumakil, num 1, exp 1, arm 0, wep 0
    						end_if
    						
    						;Declare war, mov camera
    						if I_LocalFaction sicily
    							console_command diplomatic_stance spain sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance spain milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance spain egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance spain mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance spain moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance spain turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance spain byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance spain scotland War
    						end_if
    					end_if
    					;Rhun
    					if I_EventCounter Pxs_Rhun_CInvasion = 1
    						spawn_army 
    							faction hungary
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Kataphracts Bodyguard	exp 3 armour 1 weapon_lvl 0
    						end
    						give_everything_to_faction hungary venice false
    							
    							;add his units
    							;base level
    							create_unit Cinvader, Easterling Clansmen, num 4,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Balchoth Horde, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Rhunnic Pikemen, num 1, exp 1, arm 0, wep 0
    							
    						if I_EventCounter Pxs_Invasion_Type = 1
    							create_unit Cinvader, Easterling Clansmen, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Dismounted Variags, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Mounted Clanguard, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							create_unit Cinvader, Rhunnic Swordsmen, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Dismounted Variags, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Mounted Clanguard, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							create_unit Cinvader, Rhunnic Elite Archers, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Rhunnic Elite Infantry, num 2, exp 1, arm 0, wep 0
    						end_if
    						;Declare war, mov camera, mov army 
    						if I_LocalFaction sicily
    							console_command diplomatic_stance venice sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance venice milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance venice egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance venice mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance venice moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance venice turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance venice byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance venice scotland War
    						end_if
    					end_if
    					;OOMM
    					if I_EventCounter Pxs_OOMM_CInvasion = 1
    						spawn_army 
    							faction hungary
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Moria Bodyguards	exp 3 armour 1 weapon_lvl 0
    						end
    						give_everything_to_faction hungary hre false
    							
    							;add his units
    							;base level
    							create_unit Cinvader, Goblin Orcs Mercs, num 4,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Snaga Skirmishers, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Moria Orcs, num 1, exp 1, arm 0, wep 0
    							
    						if I_EventCounter Pxs_Invasion_Type = 1
    							create_unit Cinvader, Goblin Archers, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Snaga Skirmishers, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Moria Orcs, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							create_unit Cinvader, Goblin Orcs Mercs, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Cave Trolls, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Goblin Wargs, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							create_unit Cinvader, Goblin Orcs Mercs, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Cave Trolls, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Goblin Wargs, num 1, exp 1, arm 0, wep 0
    						end_if
    						;Declare war, mov camera, mov army 
    						if I_LocalFaction sicily
    							console_command diplomatic_stance hre sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance hre milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance hre egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance hre mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance hre moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance portugal turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance hre byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance hre scotland War
    						end_if
    					end_if
    					;Isengard
    					if I_EventCounter Pxs_Isengard_CInvasion = 1
    						spawn_army 
    							faction hungary
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Uruk-Hai Bodyguards	exp 3 armour 1 weapon_lvl 0
    						end
    						give_everything_to_faction hungary france false
    							
    							;add his units
    							;base level
    							create_unit Cinvader, Uruk-Hai Raiders Mercs, num 4,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Uruk-Hai Infantry, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Dunlendings Mercs, num 2,	exp 1, arm 0, wep 0
    							
    						if I_EventCounter Pxs_Invasion_Type = 1
    							create_unit Cinvader, Uruk-Hai Archers, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Uruk-Hai Pikemen, num 2,	exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							create_unit Cinvader, Uruk-Hai Crossbow, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Uruk-Hai Raiders Mercs, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Wargs, num 1,	exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							create_unit Cinvader, Uruk-Hai Crossbow, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Uruk-Hai Raiders Mercs, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Wargs, num 1,	exp 1, arm 0, wep 0
    						end_if
    						;Declare war, mov camera, mov army 
    						if I_LocalFaction sicily
    							console_command diplomatic_stance france sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance france milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance france egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance france mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance france moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance france turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance france byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance france scotland War
    						end_if
    					end_if
    					;OOG
    					if I_EventCounter Pxs_OOG_CInvasion = 1
    						spawn_army 
    							faction hungary
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Moria Bodyguards	exp 3 armour 1 weapon_lvl 0
    						end
    						give_everything_to_faction hungary portugal false
    							
    							;add his units
    							;base level
    							create_unit Cinvader, Goblin Spears, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Snaga Band, num 4,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Orc Fellers, num 1, exp 1, arm 0, wep 0
    							
    						if I_EventCounter Pxs_Invasion_Type = 1
    							create_unit Cinvader, Orc Fellers, num 1, exp 1, arm 0, wep 0
    							create_unit Cinvader, Orc Halberd, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Goblin Trackers, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							create_unit Cinvader, Goblin Trackers, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Goblin Spears, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Snow Trolls, num 1, exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							create_unit Cinvader, Goblin Trackers, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Snaga Band, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Snow Trolls, num 1, exp 1, arm 0, wep 0
    						end_if
    						;Declare war, mov camera, mov army 
    						if I_LocalFaction sicily
    							console_command diplomatic_stance portugal sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance portugal milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance portugal egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance portugal mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance portugal moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance portugal turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance portugal byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance portugal scotland War
    						end_if
    					end_if	
    					;Mordor
    					if I_EventCounter Pxs_Mordor_CInvasion = 1
    						spawn_army 
    							faction hungary
    							character Cinvader, named character, age 56, x 399, y 340
    							traits LoyaltyStarter 1 , GoodCommander 2 , ReligionStarter 1 , GoodAttacker 2 , Loyal 2 , GoodAdministrator 1 , StrategicSkill 1 , LogisticalSkill 1
    							unit	Uruk Bodyguards 	exp 3 armour 1 weapon_lvl 0
    						end
    						give_everything_to_faction hungary england false
    							
    							;add his units
    							;base level
    							create_unit Cinvader, Mordor Orcs Mercs, num 5,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Mordor Archers Mercs, num 2,	exp 1, arm 0, wep 0
    							
    						if I_EventCounter Pxs_Invasion_Type = 1
    							create_unit Cinvader, Mordor Archers Mercs, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, 2handed Orcs, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Morannon Guard, num 1,	exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 2
    							create_unit Cinvader, Battle Trolls, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Mordor Uruks, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Morannon Guard, num 1,	exp 1, arm 0, wep 0
    						end_if
    						if I_EventCounter Pxs_Invasion_Type = 3
    							create_unit Cinvader, Battle Trolls, num 1,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Mordor Uruks, num 2,	exp 1, arm 0, wep 0
    							create_unit Cinvader, Morannon Guard, num 1,	exp 1, arm 0, wep 0
    						end_if
    						;Declare war, mov camera, mov army 
    						if I_LocalFaction sicily
    							console_command diplomatic_stance england sicily War
    						end_if	
    						if I_LocalFaction milan
    							console_command diplomatic_stance england milan War
    						end_if	
    						if I_LocalFaction egypt
    							console_command diplomatic_stance england egypt War
    						end_if	
    						if I_LocalFaction mongols
    							console_command diplomatic_stance england mongols War
    						end_if	
    						if I_LocalFaction moors
    							console_command diplomatic_stance england moors War
    						end_if	
    						if I_LocalFaction turks
    							console_command diplomatic_stance england turks War
    						end_if	
    						if I_LocalFaction byzantium
    							console_command diplomatic_stance england byzantium War
    						end_if	
    						if I_LocalFaction scotland
    							console_command diplomatic_stance england scotland War
    						end_if
    					end_if
    				end_if
    				
    				if I_LocalFaction sicily
    				and I_SettlementOwner Anorien = sicily
    					snap_strat_camera 246 , 129
    					console_command move_character Cinvader, 246 , 129
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction milan
    				and I_SettlementOwner Kings-Land = milan
    					snap_strat_camera 192 , 154
    					console_command move_character Cinvader, 192 , 154
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction egypt
    				and I_SettlementOwner Imladris = egypt
    					snap_strat_camera 182 , 250
    					console_command move_character Cinvader, 182 , 250
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction mongols
    				and I_SettlementOwner Elven-Mirkwood = mongols
    					snap_strat_camera 258 , 267
    					console_command move_character Cinvader, 258 , 267
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction moors
    				and I_SettlementOwner Erebor = moors
    					snap_strat_camera 296 , 264
    					console_command move_character Cinvader, 296 , 264
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction turks
    				and I_SettlementOwner Bree = turks
    					snap_strat_camera 125 , 247
    					console_command move_character Cinvader, 125 , 247
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction byzantium
    				and I_SettlementOwner Lake_Evendim = byzantium
    					snap_strat_camera 98 , 259
    					console_command move_character Cinvader, 98 , 259
    					console_command mp Cinvader -250
    				end_if	
    				if I_LocalFaction scotland
    				and I_SettlementOwner Dale = scotland
    					snap_strat_camera 296 , 264
    					console_command move_character Cinvader, 296 , 264
    					console_command mp Cinvader -250
    				end_if
    				console_command give_trait Cinvader CInvader
    				historic_event Pxs_Enemy_Army_Near_By
    		end_if
    		;Alert Incoming Invasion
    		if not I_EventCounter Pxs_Invasion_Phase > 0
    			historic_event Pxs_Inminent_Invasion
    		end_if
    		;Wait 3 turns
    		if I_EventCounter Pxs_Invasion_Phase < 8
    			inc_event_counter Pxs_Invasion_Phase 1
    		end_if
    end_monitor

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

    Default Re: Help with script!

    Excellent, glad to help.

    I'm pretty sure that this line won't work correctly:

    if not I_EventCounter Pxs_Invasion_Phase > 0

    (It's at the bottom of your script.)

    Someone correct me if I'm wrong (I have been muddled in my "not" and zero rules before ) but as I remember it you can't use "not" with conditions that take logical operators (< > <= >= etc.). You might find that this IF statement always evaluates to true, even when it should be false.

    Use this instead:

    if I_EventCounter Pxs_Invasion_Phase < 1

    or similar, such as ...

    if I_EventCounter Pxs_Invasion_Phase <= 0

    I see that there's a similar use of "not" at the top of the script too.


    EDIT:
    you can't use "not" with conditions that take logical operators (< > <= >= etc.).
    Yeah, don't quote me on that. Maybe there are cases where it doesn't work (certain conditions) but as far as I know it does.
    Last edited by Withwnar; February 13, 2012 at 01:02 AM.

  14. #14

    Default Re: Help with script!

    Quote Originally Posted by Withwnar View Post
    Excellent, glad to help.

    I'm pretty sure that this line won't work correctly:

    if not I_EventCounter Pxs_Invasion_Phase > 0

    (It's at the bottom of your script.)

    Someone correct me if I'm wrong (I have been muddled in my "not" and zero rules before ) but as I remember it you can't use "not" with conditions that take logical operators (< > <= >= etc.). You might find that this IF statement always evaluates to true, even when it should be false.

    Use this instead:

    if I_EventCounter Pxs_Invasion_Phase < 1

    or similar, such as ...

    if I_EventCounter Pxs_Invasion_Phase <= 0

    I see that there's a similar use of "not" at the top of the script too.
    Heh! you'r probably right. Actually my script was evaluating those kind of lines as you say. I changed them to "not .... > 0" because I was getting a lot of unwanted behaviour, I read somewhere about some "0" rules and misunderstood them.

    Even though I haven't found any errors with these lines, I'll change them back to what your are saying since you help me fix the real issue.

    Now I can work in the next oddity, trying to make conditions like GlobalStanding and FactionStanding to work. I though I was using them correctly but while testing I'm seen more rare behaviour.

    Code:
    declare_counter Pxs_Has_Reputation 
    
    monitor_event FactionTurnStart FactionIsLocal
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 0
    	and GlobalStanding <= 1
    
    	set_counter Pxs_Has_Reputation 1
    	historic_event Pxs_Rep1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 2
    	and GlobalStanding <= 4
    
    	set_counter Pxs_Has_Reputation 2
    	historic_event Pxs_Rep2
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 4
    	and GlobalStanding <= 7
    
    	set_counter Pxs_Has_Reputation 3
    	historic_event Pxs_Rep3
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 7
    
    	set_counter Pxs_Has_Reputation 4
    	historic_event Pxs_Rep4
    end_monitor
    To my surprise, the game fires each turn the event Pxs_Rep1 no matter what reputation I have.
    Last edited by proximusj; February 04, 2012 at 07:56 AM.

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

    Default Re: Help with script!

    I have never used GlobalStanding but given that the docudemons example uses a decimal number it might be that the range is something like 0.0 to 1.0.

    Also, even if the range is 0 to, say, 10, your script doesn't catch the case where it is between 1 and 2 (because it is a decimal value). And if it is 4 or 7 then it will be caught twice.

    You would need to do something like...

    >= 0 and < 2

    >= 2 and < 4

    >= 4 and < 7

    >= 7

    ... but adjusted to suit what the real range is.

  16. #16

    Default Re: Help with script!

    Quote Originally Posted by Withwnar View Post
    I have never used GlobalStanding but given that the docudemons example uses a decimal number it might be that the range is something like 0.0 to 1.0.

    Also, even if the range is 0 to, say, 10, your script doesn't catch the case where it is between 1 and 2 (because it is a decimal value). And if it is 4 or 7 then it will be caught twice.

    You would need to do something like...

    >= 0 and < 2

    >= 2 and < 4

    >= 4 and < 7

    >= 7

    ... but adjusted to suit what the real range is.
    Well, I did the following tests and I'm still getting the same results.
    Spoiler Alert, click show to read: 

    Test 1:
    Code:
    ;The more reputation, the more chances to persuade allies
    declare_counter Pxs_Has_Reputation 
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= -0.1
    	and GlobalStanding <= 1.0
    
    	set_counter Pxs_Has_Reputation 1
    	historic_event Pxs_Rep1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 1.1
    	and GlobalStanding <= 4.0
    
    	set_counter Pxs_Has_Reputation 2
    	historic_event Pxs_Rep2
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 4.1
    	and GlobalStanding <= 7.0
    
    	set_counter Pxs_Has_Reputation 3
    	historic_event Pxs_Rep3
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 7.1
    
    	set_counter Pxs_Has_Reputation 4
    	historic_event Pxs_Rep4
    end_monitor
    Test 2:

    Code:
    ;The more reputation, the more chances to persuade allies
    declare_counter Pxs_Has_Reputation 
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= -0.0001
    	and GlobalStanding <= 1.0000
    
    	set_counter Pxs_Has_Reputation 1
    	historic_event Pxs_Rep1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 1.0001
    	and GlobalStanding <= 4.0000
    
    	set_counter Pxs_Has_Reputation 2
    	historic_event Pxs_Rep2
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 4.0001
    	and GlobalStanding <= 7.0000
    
    	set_counter Pxs_Has_Reputation 3
    	historic_event Pxs_Rep3
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 7.0001
    
    	set_counter Pxs_Has_Reputation 4
    	historic_event Pxs_Rep4
    end_monitor


    Still getting Pxs_Rep1 all the time. I need to add that I reset Pxs_Has_Reputation to 0 at the end of each turn.

  17. #17
    EP!anastasi's Avatar Biarchus
    Join Date
    Jul 2008
    Location
    Athens, Greece
    Posts
    652

    Default Re: Help with script!

    I'm not at all sure about this, but maybe, just MAYBE, the range for global standing is between -1.0 and 1.0 (*)

    I'd try it if i were you.


    (*) edit: i mean -1.0 <= global_standing <= 1.0
    Last edited by EP!anastasi; February 04, 2012 at 11:03 AM.
    Quote Originally Posted by 1988matej View Post
    <snip> i won't preorder to get the dacian's, wont pay for the elephant dlc nor will i settle for a dumbed down game <snip>
    "My garden may be smaller than your Rome, but my pilum is harder than your sternum!"

    a great song ... and one more ... ok, one last






    (\__/)
    ( O.o)
    (> < ) This is Bunny. Please help Bunny reach global domination by copying this message and pasting it to your own signature. Thank you!










    Fred Putz
    Quote Originally Posted by Fred Putz View Post
    Hmm - in my political spectrum Nazism is always on the extreme stupid wing.
    jimkatalanos

    Quote Originally Posted by jimkatalanos View Post
    Can someone delete this one temporarily?
    It's way too active and I am worried.
    Spoiler Alert, click show to read: 
    Taiji
    Quote Originally Posted by Taiji View Post
    Honestly there is no ceremony while I sacrifice stuff
    Garbarsardar
    Quote Originally Posted by Garbarsardar View Post
    <snip> the behaviour of moderators is a clear example of the corruption that absolute power brings to these hitherto innocent kids. Jom, Hesus, Ishan, Giga, were a merry bunch of fellows until the DeletePostDemon went into them and made them do the unthinkable. Praise the lord. And pass the bucket.
    ~Gort~
    Quote Originally Posted by ~Gort~ View Post
    Irony is one of the few saving graces of humanity.
    irelandeb
    Quote Originally Posted by irelandeb View Post
    What we understand is neglible compared to what we know we don't understand, never mind what we don't know we don't understand.
    Squid
    Quote Originally Posted by Squid View Post
    It won't help, people will believe what they want to believe even when presented with incontrovertible proof to the contrary.
    Magicman2051
    Quote Originally Posted by Magicman2051 View Post
    Clarifying, I don't disagree with what I quoted, I don't agree with it either.
    Aradan
    Quote Originally Posted by Aradan View Post
    You do make sense.

  18. #18

    Default Re: Help with script!

    Quote Originally Posted by EP!anastasi View Post
    I'm not at all sure about this, but maybe, just MAYBE, the range for global standing is between -1.0 and 1.0

    I'd try it if i were you.
    Its working now! You are right, the game evaluates from -1.0 to 1.0. Probably the same rules apply to FactionStanding.

    This time I got all events while rising my global reputation.

    Thank you for all your help guys, now I can finish what I started.

  19. #19
    EP!anastasi's Avatar Biarchus
    Join Date
    Jul 2008
    Location
    Athens, Greece
    Posts
    652

    Default Re: Help with script!

    Quote Originally Posted by proximusj View Post
    You are right, the game evaluates from -1.0 to 1.0. Probably the same rules apply to FactionStanding.
    Yeah, probably the same.

    Quote Originally Posted by proximusj View Post
    Its working now!

    This time I got all events while rising my global reputation.

    Thank you for all your help guys, now I can finish what I started.
    Glad to be of help!
    Last edited by EP!anastasi; February 04, 2012 at 08:32 PM.
    Quote Originally Posted by 1988matej View Post
    <snip> i won't preorder to get the dacian's, wont pay for the elephant dlc nor will i settle for a dumbed down game <snip>
    "My garden may be smaller than your Rome, but my pilum is harder than your sternum!"

    a great song ... and one more ... ok, one last






    (\__/)
    ( O.o)
    (> < ) This is Bunny. Please help Bunny reach global domination by copying this message and pasting it to your own signature. Thank you!










    Fred Putz
    Quote Originally Posted by Fred Putz View Post
    Hmm - in my political spectrum Nazism is always on the extreme stupid wing.
    jimkatalanos

    Quote Originally Posted by jimkatalanos View Post
    Can someone delete this one temporarily?
    It's way too active and I am worried.
    Spoiler Alert, click show to read: 
    Taiji
    Quote Originally Posted by Taiji View Post
    Honestly there is no ceremony while I sacrifice stuff
    Garbarsardar
    Quote Originally Posted by Garbarsardar View Post
    <snip> the behaviour of moderators is a clear example of the corruption that absolute power brings to these hitherto innocent kids. Jom, Hesus, Ishan, Giga, were a merry bunch of fellows until the DeletePostDemon went into them and made them do the unthinkable. Praise the lord. And pass the bucket.
    ~Gort~
    Quote Originally Posted by ~Gort~ View Post
    Irony is one of the few saving graces of humanity.
    irelandeb
    Quote Originally Posted by irelandeb View Post
    What we understand is neglible compared to what we know we don't understand, never mind what we don't know we don't understand.
    Squid
    Quote Originally Posted by Squid View Post
    It won't help, people will believe what they want to believe even when presented with incontrovertible proof to the contrary.
    Magicman2051
    Quote Originally Posted by Magicman2051 View Post
    Clarifying, I don't disagree with what I quoted, I don't agree with it either.
    Aradan
    Quote Originally Posted by Aradan View Post
    You do make sense.

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

    Default Re: Help with script!

    It would explain why the first monitor always fires.

    And I would avoid doing this kind of thing...

    Code:
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 1.0001
    	and GlobalStanding <= 4.0000
    
    	set_counter Pxs_Has_Reputation 2
    	historic_event Pxs_Rep2
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding >= 4.0001
    	and GlobalStanding <= 7.0000
    
    	set_counter Pxs_Has_Reputation 3
    	historic_event Pxs_Rep3
    end_monitor
    I don't know if it's possible in this engine but what happens if the value is 4.00005?

    Using < instead of <= (or > instead of >=) for one of them will cover all possibilities...

    Code:
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding > 1.0
    	and GlobalStanding <= 4.0
    
    	set_counter Pxs_Has_Reputation 2
    	historic_event Pxs_Rep2
    end_monitor
    
    monitor_event FactionTurnStart FactionType sicily
    	and I_CompareCounter Pxs_LocalFaction_Is_Good  = 1
    	and GlobalStanding > 4.0
    	and GlobalStanding <= 7.0
    
    	set_counter Pxs_Has_Reputation 3
    	historic_event Pxs_Rep3
    end_monitor
    Last edited by Withwnar; February 04, 2012 at 10:39 AM.

Posting Permissions

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