losing hitpoints
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.
losing hitpoints
Hi, I tried to create a unit, wich loses 2 hitpoints at the beginning of every turn. However, I wrote this:
But somehow, nothing happens at all.
Code: Select all
#define ABILITY_MAGIC
[event]
name=new turn
[effect]
apply_to=hitpoints
increase_total=-2
[/effect]
name= _ "magic"
description= _ "Magic:
This unit is only held in this world by magic,
however, the magic energy gets lost from time to time."
name_inactive= _ "magic"
description_inactive= _ "Magic:
This unit is only held in this world by magic,
however, the magic energy gets lost from time to time."
[/event]
#enddef
Working on the Era of Ilthan
Re: losing hitpoints
There's too many things to list that are wrong in that code.
Look how other abilities utilizing events do it.
Look how other abilities utilizing events do it.
Re: losing hitpoints
Oh, sorry, I put this topic into the wrong forum. It should of course have been in the WML-Workshop topic.
EDIT: Moved. -zookeeper
EDIT: Moved. -zookeeper
Working on the Era of Ilthan
Re: losing hitpoints
Ok, now I tried:
Doesn't work either.
Sorry, if this is a really stupid question, but I wanted to do this since november and I always thought, I had to find this out myself, so I never asked here. Now again, I'm trying to find it out since two hours and tried 100 different variations, but none of them worked.
Code: Select all
#define ABILITY_MAGIC
[dummy]
id=magic
name= _ "magic"
description= _ "Magic:
This unit is only held in this world by magic,
however, the magic energy gets lost from time to time."
[/dummy]
[/abilities]
[event]
name=new turn
first_time_only=no
[effect]
apply_to=hitpoints
increase=-2
[/effect]
[/event]
[+abilities]
#enddef
Sorry, if this is a really stupid question, but I wanted to do this since november and I always thought, I had to find this out myself, so I never asked here. Now again, I'm trying to find it out since two hours and tried 100 different variations, but none of them worked.
Working on the Era of Ilthan
Re: losing hitpoints
Check the thread just under this one.
Re: losing hitpoints
Yes, I did that before writing this post, but the problem is, that the moveto event seems to work quite diffrently from the new turn event. Maybe I understood something completely wrong, but now I tried this one:
And I never saw that message.
Code: Select all
#define ABILITY_MAGIC
[dummy]
id=magic
name= _ "magic"
description= _ "Magic:
This unit is only held in this world by magic,
however, the magic energy gets lost from time to time."
[/dummy]
[/abilities]
[event]
name=new turn
first_time_only=no
[filter]
ability=magic
[/filter]
[message]
message="event works fine"
speaker=$this_unit
[/message]
[/event]
[+abilities]
#enddef
Working on the Era of Ilthan
Re: losing hitpoints
I am no WML wizard, but, I think there is something wrong with your [abilities] tags.
ThanatoNoth | Necromanteion | Undead Rights Protection Society
"The gods can demand nothing of me. Even gods answer to me, eventually. [...] I cannot be bidden, I cannot be forced. I will do only that which I know to be right." (Death in Pratchett's "Mort")
"The gods can demand nothing of me. Even gods answer to me, eventually. [...] I cannot be bidden, I cannot be forced. I will do only that which I know to be right." (Death in Pratchett's "Mort")
Re: losing hitpoints
Hi! I'm only a beginner in WML, but I think I figured it out, since I tried to do something similar. The explanation lies, as you already assumed, in the difference between moveto and new turn. I stumbled over it by accident.
Quote from wesnoth.org/wiki/eventWML
This is caused by the units' details getting automatically stored in variables by [store_unit] if you use one of the "action" event triggers. With [store_unit] you can manipulate and change a units' stats and stuff.
So, I think the hp change will work with "new turn" etc. if you first use [store_unit], which stores the details of a unit into variables, and then accordingly change them.
Quote from wesnoth.org/wiki/eventWML
Every time you try to manipulate a unit with an [object] and use an event trigger which is "actions by units or things that happen to units", like "attack", "moveto" or "die", your [effect] will work. Every time you use a different event trigger, like "side turn" or "new turn" it won't work.Filters can be applied to the following event triggers (see FilterWML; see also below). The actions specified in the event tag will be executed only if the filter returns true. These event triggers are all actions by units (moveto, attack) or things that happen to units (recruit, advance). When one of these events is triggered, the position of the active unit (referred to as the primary unit) is stored in the variables x1 and y1 and the position of any unit that primary unit does something to is stored in the variables x2 and y2 (this unit is referred to as the secondary unit below). These units are also automatically stored in the variables 'unit' and 'second_unit' as if they had been stored using the [store_unit] tag
This is caused by the units' details getting automatically stored in variables by [store_unit] if you use one of the "action" event triggers. With [store_unit] you can manipulate and change a units' stats and stuff.
So, I think the hp change will work with "new turn" etc. if you first use [store_unit], which stores the details of a unit into variables, and then accordingly change them.
- beetlenaut
- Developer
- Posts: 2827
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: losing hitpoints
If you are trying to check if an event works, don't use a variable as the speaker--you don't know if that variable is part of the problem you are having! (It is in this case.) Use "narrator" as the speaker, or just use {DEBUG_MSG "whatever you want"}.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: losing hitpoints
Now this is my next try. It almost works, but the units with 0 or less LP don't die.
Can you please tell me what's wrong with my [kill]?
Can you please tell me what's wrong with my [kill]?
Code: Select all
#define ABILITY_MAGIC
[dummy]
id=magic
name= _ "magic"
description= _ "Magic:
This unit is only held in this world by magic, however, the magic energy gets lost from time to time, so this unit loses two
hitpoints at the beginning of every turn."
[/dummy]
[/abilities]
[event]
name=side turn
first_time_only=no
[store_unit]
[filter]
ability=magic
side=$side_number
[/filter]
variable=MAGIC_UNIT_store
kill=yes
[/store_unit]
{FOREACH MAGIC_UNIT_store MAGIC_UNIT_i}
[set_variable]
name=MAGIC_UNIT_store[$MAGIC_UNIT_i].hitpoints
add=-2
[/set_variable]
[unstore_unit]
variable=MAGIC_UNIT_store[$MAGIC_UNIT_i]
{COLOR_HARM}
text= _ "-2"
find_vacant=no
[/unstore_unit]
[if]
[variable]
name=MAGIC_UNIT_store[$MAGIC_UNIT_i].hitpoints
less_than_equal_to=0
[/variable]
[then]
[set_variable]
name=MAGIC_UNIT_store[$MAGIC_UNIT_i].description
value=death_magic_unit
[/set_variable]
[kill]
ability=magic
description=death_magic_unit
animate=yes
fire_event=yes
[/kill]
[/then]
[/if]
{NEXT MAGIC_UNIT_i}
{CLEAR_VARIABLE MAGIC_UNIT_store}
[/event]
[+abilities]
#enddef
Working on the Era of Ilthan
- Ken_Oh
- Moderator Emeritus
- Posts: 2178
- Joined: February 6th, 2006, 4:03 am
- Location: Baltimore, Maryland, USA
Re: losing hitpoints
Others might tell me I don't know what I'm talking about, but I'm not sure ability= and description= are the best thing to use for [kill]. I would use MAGIC_UNIT_store[$MAGIC_UNIT_i].x/y.
Re: losing hitpoints
Yes, that works! Finally! Thanks a lot to everyone who helped me.
Working on the Era of Ilthan
Re: losing hitpoints
Yes, that's a much better way of doing it. The reason why what you posted didn't work was because you didn't unstore the unit between your [set_variable] and [kill], so the latter found no units matching the filter.
Re: losing hitpoints
Maybe there is something small, I could do better. Right now, if the unit is resting (or in a village), there comes a red -2 and then a green 2 (or above the unit. Although this is not desastrous, it's a bit terrible and I wonder, if I can turn all the healing stuff 2 smaller and then avoid losing two hitpoints in those cases. I think, I would manage to do the filtering for the hitpoints losing stuff (if an adjacent unit heals, if the unit is in a village, if the unit is resting, it doesn't lose any hitpoints), but I don't know how I could turn the resting healing off, set the village healing to 2 and set the healing two smaller than it is normally. I think the last one should be the most difficult one. Although no unit has both regeneration and magic, it would be nice to do the same for regeneration, too.
I hope I expressed clearly enough what I meant, I don't know how to explain that simpler.
Although it seems to me, that this should be lots too difficult, so maybe I'll just leave it like that and it works and that's fine, only if someone knows this by accident.
I hope I expressed clearly enough what I meant, I don't know how to explain that simpler.
Although it seems to me, that this should be lots too difficult, so maybe I'll just leave it like that and it works and that's fine, only if someone knows this by accident.
Working on the Era of Ilthan