Where to place my event?
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.
Where to place my event?
Hello again everyone!
I'm still working on my custom thief units. I developed a "pickpocket" ability. It is different from the one on the wiki, because I found that one didn't work, and I think it had a whole lot of extra code. Anyways, the general code is located in my campaign folder, in a utils/abilities.cfg file. It follows the general idea below:
It works great, only if I give this special attack to several units, and the event is repeated for each different unit type with this special attack. By that, I mean if I only have a Street Urchin in game, he steals one gold alright.
But if I add a Pickpocket unit, then they both steal two golds each time, which would be expected since both units contain that event. In effect, the event is present twice, and will therefore trigger twice.
So my question is: Where can I place that event so that it will still work, but only appear once in the code?
I tried putting it in my abilities.cfg file, outside any define tags, but then it doesn't work. Should I place it in my main campaign file? Or could I place it in another file, then make sure that file is loaded when the campaign launches? How to do that?
Thanks !
I'm still working on my custom thief units. I developed a "pickpocket" ability. It is different from the one on the wiki, because I found that one didn't work, and I think it had a whole lot of extra code. Anyways, the general code is located in my campaign folder, in a utils/abilities.cfg file. It follows the general idea below:
Code: Select all
#define WEAPON_SPECIAL_PICKPOCKET
[dummy]
#ability name and description
[/dummy]
[/specials]
[/attacks]
[event]
#the event that triggers adding one gold to the side of the attacker for each successful attack made with this special
#filter is made with the id of the dummy special
[/event]
[+specials]
[+events]
#enddef
But if I add a Pickpocket unit, then they both steal two golds each time, which would be expected since both units contain that event. In effect, the event is present twice, and will therefore trigger twice.
So my question is: Where can I place that event so that it will still work, but only appear once in the code?
I tried putting it in my abilities.cfg file, outside any define tags, but then it doesn't work. Should I place it in my main campaign file? Or could I place it in another file, then make sure that file is loaded when the campaign launches? How to do that?
Thanks !
Re: Where to place my event?
So if two different unit types have the same event-driven ability and you then have units of both types in a scenario, the event gets duplicated? I haven't tested it myself, but that sounds very plausible to me. I'll try it out a bit later and file a bug report if that's really the case unless someone beats me to it.
EDIT: Well, I'm not sure why I thought I needed to test that. Yes, that's the way it works: unit type events are handled based on unit type. If you want to use the same event in several unit types, you either need to:
1) add some filtering so that the event which unit type X gets will only work for units of type X, and the event which unit type Y gets will only work for units of type Y (that is, not for any units with the dummy ability), and so on.
2) write the event so that its effects don't get duplicated no matter how many times it's duplicated in a row. Doesn't sound feasible in your case, however.
EDIT: Well, I'm not sure why I thought I needed to test that. Yes, that's the way it works: unit type events are handled based on unit type. If you want to use the same event in several unit types, you either need to:
1) add some filtering so that the event which unit type X gets will only work for units of type X, and the event which unit type Y gets will only work for units of type Y (that is, not for any units with the dummy ability), and so on.
2) write the event so that its effects don't get duplicated no matter how many times it's duplicated in a row. Doesn't sound feasible in your case, however.
Re: Where to place my event?
I'm not 100% sure that's what happened, but after much testing, I came to that conclusion.
I assume the code is added once you add the unit. Since the even is not in the ability tag, it applies once each time it's added.
I'll try to look if it is possible to make it not be cumulative, seeing as how you can do that for healing abilities, for example.
However, another fix would be to add the event in only one point of the code. I'll try adding it to the scenario to see if that would work.
However, it would be simpler if I could just include a file, containing those abilities events, into each of my scenarios. Is there a way to include a file into another?
----------------
edit: Adding the event in the scenario does work fine. If anyone can tell me how to include a file into a scenario (if it is even possible), it would be awesome !
I assume the code is added once you add the unit. Since the even is not in the ability tag, it applies once each time it's added.
I'll try to look if it is possible to make it not be cumulative, seeing as how you can do that for healing abilities, for example.
However, another fix would be to add the event in only one point of the code. I'll try adding it to the scenario to see if that would work.
However, it would be simpler if I could just include a file, containing those abilities events, into each of my scenarios. Is there a way to include a file into another?
----------------
edit: Adding the event in the scenario does work fine. If anyone can tell me how to include a file into a scenario (if it is even possible), it would be awesome !
Re: Where to place my event?
e.g. {~add-ons/MyCampaign/special/eventstuff.cfg} should work.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Where to place my event?
Half of any wml code consists of stuff included into each other...just don't think of macros as "functions", their code gets inserted instead.Katz wrote:If anyone can tell me how to include a file into a scenario (if it is even possible), it would be awesome !
E.g. map_data="{~some_path/some.map}" only includes some.map's content at that position between the "". Some (usually old) campaigns actually have their map data included in the scenario cfg, it's equivalent.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Where to place my event?
That's what I thought. I'll try it then ! Thank you !