losing hitpoints

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
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

losing hitpoints

Post by Civhai »

Hi, I tried to create a unit, wich loses 2 hitpoints at the beginning of every turn. However, I wrote this:

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
But somehow, nothing happens at all.
Working on the Era of Ilthan
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: losing hitpoints

Post by zookeeper »

There's too many things to list that are wrong in that code.

Look how other abilities utilizing events do it.
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: losing hitpoints

Post by Civhai »

Oh, sorry, I put this topic into the wrong forum. It should of course have been in the WML-Workshop topic.

EDIT: Moved. -zookeeper
Working on the Era of Ilthan
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: losing hitpoints

Post by Civhai »

Ok, now I tried:

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
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.
Working on the Era of Ilthan
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: losing hitpoints

Post by zookeeper »

Check the thread just under this one.
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: losing hitpoints

Post by Civhai »

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:

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
And I never saw that message.
Working on the Era of Ilthan
User avatar
Thanatos
Posts: 408
Joined: January 17th, 2006, 9:00 pm
Location: The End.
Contact:

Re: losing hitpoints

Post by Thanatos »

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")
Causley
Posts: 5
Joined: January 9th, 2009, 1:07 am

Re: losing hitpoints

Post by Causley »

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
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
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.
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.
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: losing hitpoints

Post by beetlenaut »

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
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: losing hitpoints

Post by Civhai »

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]?

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
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: losing hitpoints

Post by Ken_Oh »

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.
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: losing hitpoints

Post by Civhai »

Yes, that works! Finally! Thanks a lot to everyone who helped me.
Working on the Era of Ilthan
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: losing hitpoints

Post by zookeeper »

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.
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: losing hitpoints

Post by Civhai »

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 8) 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.
Working on the Era of Ilthan
Post Reply