A couple of questions about WML events
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.
A couple of questions about WML events
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)
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)
Re: A couple of questions about WML events
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:
Then in your scenarios you can do:
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.
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]
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]
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
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: A couple of questions about WML events
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?
Re: A couple of questions about WML events
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
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
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
- Celtic_Minstrel
- Developer
- Posts: 2222
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: A couple of questions about WML events
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.