How to get AI to move to a specific location?
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.
How to get AI to move to a specific location?
I had this problem when i was trying out new ways to use WML, in an event, i want the AI's units to move to a specific location, say x,y=20,20, and after it moved there, it would trigger the event which makes defeats the enemy. I know all the events and filter tags, but as far as i searched on the wiki, the closest to this is the [target] WML, but it only allows AI's unit to target it's attack on a certain enemy unit, like the one used in Elves Besieged. Is there anyway i could make the AI unit to move to a certain location?
The only way to really force AI movement is to set the goto_x and goto_y keys of a unit by hand in an ai turn event. Like this:
The above forces the unit to always try to move towards 8,35. Doesn't prevent it from attacking either I think, if it happens to land next to an enemy.
Code: Select all
[event]
name=ai turn
first_time_only=no
[if]
[variable]
name=side_number
equals=3 # assuming the AI unit's side is 3
[/variable]
[then]
[store_unit]
[filter]
description=my_ai_unit
[/filter]
kill=no
variable=stored_my_ai_unit
[/store_unit]
{VARIABLE stored_my_ai_unit.goto_x 8}
{VARIABLE stored_my_ai_unit.goto_y 35}
[unstore_unit]
variable=stored_my_ai_unit
find_vacant=no
[/unstore_unit]
{CLEAR_VARIABLE stored_my_ai_unit}
[/then]
[/if]
[/event]
If I read correctly (IIRC v2 ) it will replace it. As find_vacant=no.toms wrote:Out of curiousity: What happens if an enemy is standing on the given coordinates? Does the unit stop before the enemy or what?
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Well, it still tries to go there. Obviously it can't though, so I guess it'll settle for one of the adjacent hexes then. It won't replace the other unit or anything like that.toms wrote:Out of curiousity: What happens if an enemy is standing on the given coordinates? Does the unit stop before the enemy or what?
- thespaceinvader
- Retired Art Director
- Posts: 8414
- Joined: August 25th, 2007, 10:12 am
- Location: Oxford, UK
- Contact:
WIll it not do its best to clear the hex by attacking the unit occupying it?
http://thespaceinvader.co.uk | http://thespaceinvader.deviantart.com
Back to work. Current projects: Catching up on commits. Picking Meridia back up. Sprite animations, many and varied.
Back to work. Current projects: Catching up on commits. Picking Meridia back up. Sprite animations, many and varied.
I put the codes in like this, trying to get ai side 6,7,8 unit's to move to 6,35, i know i didn't fill in the my_ai_unit one so it didn't work, but i was wondering what do i have to put there to make every ai unit move to the location, if i put down specific units would it orders them to move?
Code: Select all
[event]
name=ai turn
first_time_only=no
[if]
[variable]
name=6,7,8
equals=6,7,8
[/variable]
[then]
[store_unit]
[filter]
description=my_ai_unit
[/filter]
kill=no
variable=stored_my_ai_unit
[/store_unit]
{VARIABLE stored_my_ai_unit.goto_x 6}
{VARIABLE stored_my_ai_unit.goto_y 35}
[unstore_unit]
variable=stored_my_ai_unit
find_vacant=no
[/unstore_unit]
{CLEAR_VARIABLE stored_my_ai_unit}
[/then]
[/if]
[/event]
Yikes! 6,7,8 is not a variable name. Try side_number instead:cool evil wrote:Code: Select all
[if] [variable] name=6,7,8 equals=6,7,8 [/variable] [then]
Code: Select all
[if]
[variable]
name=side_number
greater_than=5
[/variable]
[variable]
name=side_number
less_than=9
[/variable]
[then]
Try some Multiplayer Scenarios / Campaigns
Sorry, I think your phrasing threw me off the question and I went to look for answers in your code.cool evil wrote:i know i didn't fill in the my_ai_unit one so it didn't work, but i was wondering what do i have to put there to make every ai unit move to the location, if i put down specific units would it orders them to move?
You just put side=$side_number in the filter. That would make every ai unit of that side (and the event fires for each side) move to the location.
Try some Multiplayer Scenarios / Campaigns