Getting locations adjacent to a certain unit

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
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Getting locations adjacent to a certain unit

Post by Anagkai »

What I want to do:
Have a unit be "prisoner" (I removed their movement points). To achieve this I use an event that "frees" the unit, when I come close to it, i.e. restores the movement points and makes it change to the player's side. Also I got an avoid statement for the ennemies to prevent them from getting next to the unit

What happens:
-ennemies don't recruit (I suppose it is because they somehow try to avoid the whole map)
-the moveto event triggers moving ANYWHERE on the map.

That's what I used for both the avoid statement and the moveto event.

Code: Select all

[filter_adjacent_location]
	[filter]
		id=prisoner
		side=3
	[/filter]
[/filter_adjacent_location]
Can somebody explain, why it doesn't work? :D
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Getting locations adjacent to a certain unit

Post by zookeeper »

Anagkai wrote: February 27th, 2018, 8:35 am-the moveto event triggers moving ANYWHERE on the map.
Because you're not telling it to trigger in any specific location(s).
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Re: Getting locations adjacent to a certain unit

Post by Anagkai »

Okay, then let me reformulate: how do I need to implement the filter to have a specific location for my event that corresponds to the hexes adjacent to a certain unit?
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: Getting locations adjacent to a certain unit

Post by Iris »

Could you post the full code you're using in both cases, instead of just the filter contents? It sounds like you may have misinterpreted how the filter tags are supposed to be used.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Getting locations adjacent to a certain unit

Post by beetlenaut »

With the link he posted, zookeeper was pointing out that you have several specific options for filtering a moveto event, and [filter_adjacent_location] is not one of them. That filter does not exist in any context, actually. I know that because it's not on the wiki. (The wiki is your friend.) If you follow that link and read where it describes "moveto" and the variables it automatically stores, you might be able to see a way to do what you want. If not, then follow shadowm's excellent suggestion.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Re: Getting locations adjacent to a certain unit

Post by Anagkai »

Okay, I looked up the moveto event but I didn't see any information on what filters are allowed with it. I tried filter_adjacent now, but it doesn't change anything.

That's the code for the moveto-event.
Spoiler:
That's the avoid statement I used.
Spoiler:
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Getting locations adjacent to a certain unit

Post by Sapient »

For the first one, [event]s don't accept [filter_adjacent], but they do accept [filter], which is a standard unit filter.... So just put the [filter_adjacent] inside a [filter].

for the second one, [avoid] contains a standard location filter. Since this one is a location filter, not a unit filter, it doesn't accept [filter_adjacent]. Instead you should use [filter_adjacent_location] then inside that put [filter] to hold the adjacent unit filter.

Note: when I said "doesn't accept"... the wiki will show you what contents are allowed in every tag, as I have shown with links above. If you put something in a place where it is not listed, then it will be ignored.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Shiki
Developer
Posts: 348
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Getting locations adjacent to a certain unit

Post by Shiki »

With this code the AI would leave at least 1 hex distance to the units who match the filter
Spoiler:
Edit: Sapient has the explanation how it works above
Try out the dark board theme.
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Re: Getting locations adjacent to a certain unit

Post by Anagkai »

Thanks, that solved my problem.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
Post Reply