A couple of questions about WML events

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
ReNoM
Posts: 50
Joined: November 23rd, 2008, 1:22 pm

A couple of questions about WML events

Post by ReNoM »

Hey guys. I have a couple of questions about WML:
1. Is it possible to run a code when a unit has been modified?
2. Is it possible to run a code when a label has been placed on the map?
3. Is it possible to run a code when a chat message has been received?
4. Is it possible to run a code when a unit movement has been undone?
5. Is it possible to prevent a player from performing any action? (e.g. action of moving units, recruiting units, ending a turn)
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: A couple of questions about WML events

Post by WhiteWolf »

I doubt that predefined events exist for 1-3). The workaround I'd use is the same for all of them: define my own methods of performing these tasks (either by a WML macro, or the nicer way is probably to define your own tags in Lua) and adding a fire_event call to a custom named event.
So for example, with a WML macro the unit modification would look like this:

Code: Select all

#define MY_MODIFY_UNIT CODE
[modify_unit]
    {CODE}
[/modify_unit]
[fire_event]
    name=on_modify_unit
    # you can possibly make this more robust by having dedicated {FILTER} macro arguments and passing them here as primary unit data
[/fire_event]
Then in your scenarios you can do:

Code: Select all

    #place where you modify a unit
    {MY_MODIFY_UNIT (
        [filter]
            id=someone
        [/filter]
        experience=20
    )}
[/event]

# and you can thus hook this:
[event]
    name=on_modify_unit
    # you could theoretically use filters too if you pass the primary unit in the previous [fire_event] call
    
    # this should fire when a unit is being modified
[/event]
Maybe someone can come up with something even better. With lua you probably have more freedom, but I don't know much about it.

For 4) there is [on_undo]

For 5) I think you have to do each of these prohibitions one-by-one. So prevent ending the turn by [disallow_end_turn], prevent recruit by [disallow_recruit], etc. I'm not sure about movement, you probably have to make a workaround like setting all mp to 0, but maybe there's a more clever way to do this, I don't know.
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
ReNoM
Posts: 50
Joined: November 23rd, 2008, 1:22 pm

Re: A couple of questions about WML events

Post by ReNoM »

Hey WhiteWolf, thanks for the info. About 1-3, the code would handle only the labels and messages created by the code itself, right? If a player sets a label, sends a message, or renames a unit, those would be ignored?
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: A couple of questions about WML events

Post by WhiteWolf »

Yes that's right, it would only be applied to code that you write. So player actions or additional code loaded by other mods won't be subject to this.
I'm moderately certain that in lua it's possible to somehow hook into the core implementation of the tags and set your triggers there, so that it would apply to all cases, but someone else will have to tell you how to do that, I can't :)
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
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: A couple of questions about WML events

Post by Celtic_Minstrel »

Even if you did that (hooking into the Lua tag implementations) I believe it wouldn't detect player actions (labels, unit renaming, chat messages), just things initiated by other addons. I don't know any way to detect these player actions.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply