Modifying a unit after it moves

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
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Modifying a unit after it moves

Post by Helmet »

I have an orcish archer (id=Megdar) with the guardian status, and I changed his max_moves to 3. Now he waits patiently until someone gets close before he springs into action. It works great. However, once in a while Megdar somehow doesn't get killed by the player right away, and then he's stuck with a horrible 3 movement. When that happens, he just stands around, too far away from the other battles to bother getting involved.

I'm guessing his guardian status is part of the problem: why he just stands around after all the enemy units are dead or have moved more than 3 hexes away.

After Megdar moves off hex 21,3 and lands on some other hex, I'd like his max_moves returned to normal. What is the best way to do that? Should the guardian status be turned off? What would you do?
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Modifying a unit after it moves

Post by WhiteWolf »

Probably:

Code: Select all

[event]
    name=exit hex
    [filter]
        id=Megdar
        x,y=21,3
    [/filter]
    
    [event]
        name=turn end
        [modify_unit]
            [filter]
                id=Megdar
            [/filter]
            max_moves=$original
        [/modify_unit]
    [/event]
[/event]
Restoring the moves right after exiting the hex could mean that the AI will move the unit again, still within that turn. If you want to avoid that, you can do so with a nested turn end event as in the example.

EDIT: I also just realized that this was in the Writer's forum for some reason - moved to WML Workshop.
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
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Modifying a unit after it moves

Post by Helmet »

WhiteWolf wrote: October 16th, 2020, 11:16 pm Restoring the moves right after exiting the hex could mean that the AI will move the unit again, still within that turn. If you want to avoid that, you can do so with a nested turn end event as in the example.
I'm happy you anticipated a possible second move. That would've been another problem for me.

The code works great. Thanks, WhiteWolf!
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Post Reply