[Solved] [filter] for [modify_unit] in [prerecruit] event

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Chief_Chasso
Posts: 132
Joined: December 15th, 2012, 2:36 am

[Solved] [filter] for [modify_unit] in [prerecruit] event

Post by Chief_Chasso »

I'm trying to find the appropriate unit [filter] for a unit that has just been recently recruited. I want to be able to modify a single unit that has just been recruited within a prerecruit event before the unit is displayed.

This is what I want:

Code: Select all

# all units recruited for side 1 will start with only 75% of the unit's total HP.
	[event]
		name=prerecruit
		first_time_only=no
		[filter]
			side=1
		[/filter]
		[filter_second]
			id=leader
		[/filter_second]
		[modify_unit]
			[filter]
				side=1 # I need a filter tag here to filter just the most recently recruited single unit
			[/filter]
			hitpoints=$($this_unit.hitpoints*0.75)
		[/modify_unit]
	[/event] 

Can you modify a single individual recruited unit during a prerecruit event? I think, ideally, you would filter the unit's id, however, you wouldn't know the unit's id that has just been recruited (I believe the unit is automatically assigned an id internally).

Or am I approaching this incorrectly? Any thoughts?
Last edited by Chief_Chasso on June 5th, 2015, 11:20 pm, edited 1 time in total.
SP Campaign: Rally For Roanic
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: Need unit [filter] for [modify_unit] in [prerecruit] eve

Post by Iris »

Chief_Chasso wrote:I think, ideally, you would filter the unit's id, however, you wouldn't know the unit's id that has just been recruited (I believe the unit is automatically assigned an id internally).
Use either id=$unit.id or x,y=$unit.x,$unit.y in the action’s [filter] — both will work just the same. prerecruit events, like every other event that takes a unit, autostore the primary and secondary units in unit and second_unit respectively.

EDIT: Whoops, I somehow forgot x1 and y1. See below and use those instead, since they make for cleaner code and are considerably more efficient.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: Need unit [filter] for [modify_unit] in [prerecruit] eve

Post by tekelili »

Code: Select all

[filter]
    x,y=$x1,$y1
[/filter]
Will also work. Those variables, as unit, are also autostored when a event is fired.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
Chief_Chasso
Posts: 132
Joined: December 15th, 2012, 2:36 am

Re: Need unit [filter] for [modify_unit] in [prerecruit] eve

Post by Chief_Chasso »

Thanks shadowm and tekelili- $x1,$y1 worked perfectly. I'll get the hang of these variables eventually ;)
SP Campaign: Rally For Roanic
hay207
Double Style Tourney #1 Champ
Posts: 121
Joined: November 26th, 2009, 5:46 am
Location: Egypt

Re: [Solved] [filter] for [modify_unit] in [prerecruit] even

Post by hay207 »

shouldn't hitpoints be placed inside an effect tag?

I am trying to edit hp of all peasants , not a single unit, how to do so?

Code: Select all

[event]
  name=recruit
  first_time_only=yes

   [modify_unit] 
           [filter]
			      type=Peasant
			      side=1
			      
 			  [/filter]
    			  [object]
				duration=forever
			        [filter]
				type=Peasants
				#x,y=$unit.x,$unit.y

				[/filter]

				
				[effect]
			          apply_to=hitpoints
			          increase_total=20%
			          heal_full=yes
			          hitpoints="$(this_unit.hitpoints * 1.2)"

				[/effect]

			      [/object]
	 [/modify_unit]
[/event]
Ports: Velensk's tower defense, dov's deep shrine, Scrolling survival, Scrolling survival Co-op, Temples of the nagas.
Addons: Tower defense maps , some ANL scenarios like: ANL 3p "A New Land" survival type, and ANL Co-operative map for 2p
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [Solved] [filter] for [modify_unit] in [prerecruit] even

Post by Ravana »

You use [effect] when you use [object]. Other ways of modifying units do not use it. And [modify_unit] does not need any [object].
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: [Solved] [filter] for [modify_unit] in [prerecruit] even

Post by gfgtdf »

modyfying units with [object] or via direct modification has different effects. Changes done via [object] will for example stay if the unit advances to another type, but also other things, specially undoing objects with durations will remove all changed done via direct modification.

Also there are some things (animations) that can only be changed uing [object] while there are other things that can only be done via direct modifications.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Post Reply