Coding Unit Movement = 0
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.
-
- Posts: 9
- Joined: November 6th, 2020, 4:45 am
Coding Unit Movement = 0
Hi all,
Looking to make a specific type of unit on the enemy side not be able to move at all from their position throughout the scenario. In a previous scenario I have successfully used the following code to freeze an ai leader, but I would like to rework this code to work on other enemies.
Alternately, if there is better code that can be used here, please feel free to enlighten me. Any help would be greatly appreciated!! Thanks so much in advance.
Looking to make a specific type of unit on the enemy side not be able to move at all from their position throughout the scenario. In a previous scenario I have successfully used the following code to freeze an ai leader, but I would like to rework this code to work on other enemies.
Code: Select all
[event]
name=side 1 turn 1
[store_unit]
[filter]
side=2
[/filter]
variable=aileaders
[/store_unit]
{FOREACH aileaders i}
[object]
silent=yes
[filter]
id=$aileaders[$i].id
[/filter]
[effect]
apply_to=movement
set=0
[/effect]
[/object]
{NEXT i}
{CLEAR_VARIABLE aileaders}
[/event]
Re: Coding Unit Movement = 0
The unit storing and the for loop seems kinda redundant to me. You could just copy the contents of the [store_unit]'s filter to the [object]'s filter and then get rid of the [store_unit] and the enclosing for loop.
You then just filter there for the specific type of unit you want to freeze.
Other than that, I don't think there's a much better approach than this (but who knows, maybe someone will tell otherwise). In general, [object]s are very good because they are easy to keep track of - if you give it an id you can remove them whenever you want, and you could also specify
You then just filter there for the specific type of unit you want to freeze.
Other than that, I don't think there's a much better approach than this (but who knows, maybe someone will tell otherwise). In general, [object]s are very good because they are easy to keep track of - if you give it an id you can remove them whenever you want, and you could also specify
duration=scenario
, since you said you only want to freeze the units for the scenario. (Not specified duration means 'forever' by default).Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: Coding Unit Movement = 0
Hi
There's not much needed to be done differently. First of all, the code above does not change the movement of an ai leader, but of all of side 2's units. Though, as it happens before side 2 recruited, the movement restricting object will only be given to the leader.
You could fire the code at a later point, like turn 2.
Or, always when a unit is placed – and change the [filter].
And I agree with White Wolf, if can be easier:
The unit variable is one of a few automatically available variables:
https://wiki.wesnoth.org/SyntaxWML#Auto ... _Variables
There's not much needed to be done differently. First of all, the code above does not change the movement of an ai leader, but of all of side 2's units. Though, as it happens before side 2 recruited, the movement restricting object will only be given to the leader.
You could fire the code at a later point, like turn 2.
Or, always when a unit is placed – and change the [filter].
And I agree with White Wolf, if can be easier:
Code: Select all
[event]
name=unit placed
first_time_only=no
[object]
duration=scenario
[filter]
id=$unit.id # just this one unit which was just placed
[/filter]
[effect]
apply_to=movement
set=0
[/effect]
[/object]
[/event]
https://wiki.wesnoth.org/SyntaxWML#Auto ... _Variables
Try out the dark board theme.
-
- Posts: 9
- Joined: November 6th, 2020, 4:45 am
Re: Coding Unit Movement = 0
Thanks guys! Super helpful!
- lhybrideur
- Posts: 369
- Joined: July 9th, 2019, 1:46 pm
Re: Coding Unit Movement = 0
Don't you also need a side=2 inside the filter ?Shiki wrote: ↑November 17th, 2020, 8:51 pm Hi
There's not much needed to be done differently. First of all, the code above does not change the movement of an ai leader, but of all of side 2's units. Though, as it happens before side 2 recruited, the movement restricting object will only be given to the leader.
You could fire the code at a later point, like turn 2.
Or, always when a unit is placed – and change the [filter].
And I agree with White Wolf, if can be easier:
The unit variable is one of a few automatically available variables:Code: Select all
[event] name=unit placed first_time_only=no [object] duration=scenario [filter] id=$unit.id # just this one unit which was just placed [/filter] [effect] apply_to=movement set=0 [/effect] [/object] [/event]
https://wiki.wesnoth.org/SyntaxWML#Auto ... _Variables
Re: Coding Unit Movement = 0
You could use a side X turn refresh event with first_time_only=no. Then use modify_unit or MODIFY_UNIT to set the moves and maybe the attacks_left to 0. No object needed that way.