[resolved] event firing tied to count function
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.
[resolved] event firing tied to count function
Hi guys,
I've been trying to write an event which will fire when side once reaches a total of eight units. I figured I could use the count tag for this, and It was recommended that I use the recently added "unit placed" event name. However, I can't get it to work right.
These units are obtained via the [modify_unit] tag, where I switch their side.
This is what I have so far:
What I want to happen is for this event to fire when side one reaches eight units. This doesn't happen. Anyone know another way, or what I'm doing wrong?
Thanks!
EDIT: I was told that switching a unit's side doesn't fire this event. I have an idea, although it's very hacky I guess. I'll just kill the units and respawn them in. The creation of the unit should fire the event, right?
I've been trying to write an event which will fire when side once reaches a total of eight units. I figured I could use the count tag for this, and It was recommended that I use the recently added "unit placed" event name. However, I can't get it to work right.
These units are obtained via the [modify_unit] tag, where I switch their side.
This is what I have so far:
Code: Select all
[event]
name=unit placed
[filter_condition]
[have_unit]
side=1
count=8
[/have_unit]
[/filter_condition]
[message]
speaker=Gandfal
message= _ "Alright, I think it's about time we move on. I don't think we'll get anyone else."
[/message]
[/event]
Thanks!
EDIT: I was told that switching a unit's side doesn't fire this event. I have an idea, although it's very hacky I guess. I'll just kill the units and respawn them in. The creation of the unit should fire the event, right?
Last edited by tribes55 on July 22nd, 2018, 4:38 am, edited 1 time in total.
Re: event firing tied to count function
Hi guys, I doubt anyone will ever need anything as specific as what I needed, but this is how we resolved it ( I had help from IRC):
Changed the event name to a custom event
And we included
In every event which modified the side of a unit.
Alternatively, a path I did not take was to kill the unit and respawn it, but that's much more rough around the edges.
Thanks for the help.
Changed the event name to a custom event
Code: Select all
[event]
name=count_units
first_time_only=no
[if]
[have_unit]
count=8
side=1
[/have_unit]
[then]
[message]
speaker=Gandfal
message= _ "Alright, I think it's about time we move on. That's all we're going to get."
[/message]
[/then]
[/if]
[/event]
Code: Select all
[fire_event]
name=count_units
[/fire_event]
Alternatively, a path I did not take was to kill the unit and respawn it, but that's much more rough around the edges.
Thanks for the help.
- ResExsention
- Posts: 97
- Joined: March 17th, 2018, 12:00 am
- Location: Alberta, Canada
Re: [resolved] event firing tied to count function
Have you also tried to stop the player from recruiting? I've noticed that Gandfal just said that they would move on, but nothing is actually forcing the player to do just that. From what I know (if you haven't just spawned a whole bunch of orcs near Gandfal's keep and chased him out of it), the player could just keep recruiting over and over again until he (or she) runs out of gold, which would kind of suck, if you intended to limit Gandfal's recruits to 8. Here's how to stop the player from recruiting if she (or he) has already recruited 8 times:
This should suffice.
Code: Select all
[event]
name=count_units
first_time_only=no
[if]
[have_unit]
count=8
side=1
[/have_unit]
[then]
[message]
speaker=Gandfal
message= _ "Alright, I think it's about time we move on. That's all we're going to get."
[/message]
[disallow_recruit]
type= # Whatever Gandfal can recruit; a comma separated list
side= # Whatever Gandfal's side is
[/disallow_recruit]
[/then]
[/if]
[/event]
I am a ranger and my WML knives will implant themselves in your back.
Creator of the abandoned campaign Royalties Forgotten and the work in progress campaign Purger of Evil.
Maintainer of Fate of a Princess.
Creator of the abandoned campaign Royalties Forgotten and the work in progress campaign Purger of Evil.
Maintainer of Fate of a Princess.
Re: [resolved] event firing tied to count function
The event would look cleaner with [filter_condition] instead of [if][then].
Re: [resolved] event firing tied to count function
If that's true, it sounds like a bug. The documentation on the wiki states that it is fired for every unstore.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: [resolved] event firing tied to count function
It depends on how side is changed, new ways no longer require unstore.
Re: [resolved] event firing tied to count function
So, the implementation details changed. For example, maybe modify_unit no longer relies on unstore_unit. OK? I still see that as a bug. The "unit placed" event no longer functions as intended. The workaround proposed here is far from ideal.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: [resolved] event firing tied to count function
I'd disagree. Modify_unit isn't placing a unit on the map, it's only, well, modifying one. It isn't consistent for "unit placed" to apply to [modify_unit] just because it's used in similar situations as [unstore_unit]; really its a lot closer to [heal_unit] and many other tags that "unit placed" obviously shouldn't apply to.
In a situation where an event should fire whenever any unit changes in a certain way, then it's up to the author to make a custom event, because only the author knows exactly which changes are of interest.
In this particular situation, where the event should fire both for certain wml and for new unit creation, I'd make the event like this:
Code: Select all
[event]
name=unit placed
id=count_units
[/event]
Code: Select all
#define MODIFY_WITH_COUNT SUF
[modify_unit]
[filter]
{SUF}
[/filter]
<whatever modification you're making>
[/modify_unit]
[fire_event]
id=count_units
[primary_unit]
{SUF}
[/primary_unit]
[/fire_event]
#enddef
The last few months have been nothing but one big, painful reminder that TIMTLTW.
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Re: [resolved] event firing tied to count function
The documentation says that unstore should trigger it. Unstore is (or was) a catch-all for any unit modifications, not just placing a unit with a new id. Otherwise there can be many edge cases where a unit become placed unexpectedly through transformation.
Maybe in the past that would have been a viable strategy, but currently Wesnoth allows modifications to be used in a modular way. A modification that uses gold to grant privileges, for example, could transform a unit from level 1 to level 2. That's just one example.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: [resolved] event firing tied to count function
You ask for separate event then - unit modified.
Re: [resolved] event firing tied to count function
That's a good point. Still, I don't think that mixing and matching add-ons should be too high a priority, sometimes there will be conflicts no matter what.Sapient wrote: ↑July 23rd, 2018, 9:34 amMaybe in the past that would have been a viable strategy, but currently Wesnoth allows modifications to be used in a modular way. A modification that uses gold to grant privileges, for example, could transform a unit from level 1 to level 2. That's just one example.
Wow, now that would be a catch-all event. It would have to fire for every "enter hex," every "attacker hits," every rest heal... you'd need some very good filters, but that could definitely be useful. Maybe with a special
wml_only=
tag, so you can ignore normal gameplay.EDIT: Ooh, and what if $second_unit held the unit's previous state?
The last few months have been nothing but one big, painful reminder that TIMTLTW.
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG