Ability depending on opponent and own weapon

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

Ability depending on opponent and own weapon

Post by Civhai »

Hi,

I'd like to create an ability called "death blow". This should double the strength of a unit A if the enemy is almost killed, that is, if unit A could kill opponent B with two hits. The problem is, that I don't really know how to filter that. There are very good possibilities to filter properties of the weapon of A or the unit B, but I don't know a way to filter on the combination. But the filter depends on the strength of the attack of A and the hitpoints of B...

#define WEAPON_SPECIAL_DEATH_BLOW
[damage]
id=death_blow
name= _ "Death Blow"
description= _ "Death Blow:
If an enemy is already severely wounded, this unit can deal a devastating final blow to finish them off. If a unit with this ability attacks an enemy for which it only
needs two hits to kill them, it doubles its strength."
mulitply=2
[filter_opponent]
has only so many lp left that I could kill him in two hits...
[/filter_opponent]
[/damage]
#enddef
Working on the Era of Ilthan
User avatar
Dugi
Posts: 4960
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Ability depending on opponent and own weapon

Post by Dugi »

It doesn't look doable that way. I think that you will need to attach an event to it to make that work, because the filter would need to check if the second_unit's hp is greater than the unit's damage affected by its resistance.

Code: Select all

#define WEAPON_SPECIAL_DEATH_BLOW
[dummy]   #This is just to tag the unit that it has the weapon special
id=death_blow
name= _ "Death Blow"
description= _ "Death Blow:
If an enemy is already severely wounded, this unit can deal a devastating final blow to finish them off. If a unit with this ability attacks an enemy for which it only
needs two hits to kill them, it doubles its strength."
[/dummy]
[/abilities]   #Events have no effect in abilities tags, have to be placed outside of it
[event]
name=attacker hits
[filter_attack]
  special=death_blow
[/filter_attack]
[if]
  [variable]
    name=second_unit.hitpoints
    less_than_equal_to=$damage_inflicted
  [/variable]
  [then]
    [harm_unit]   #This is the easiest way to make the unit get experience
      [filter]
        x,y=$x2,$y2
      [/filter]
      [filter_second]
        x,y=$x1,$y1
      [/filter_second]
      amount=1000  #It is killed, so we don't need to check for resists and damage; we just need to kill it
      experience=yes
      kill=yes
    [/harm_unit]
  [/then]
[/if]
[/event]
[+abilities]  #Reopening the abilities tag
#enddef

User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: Ability depending on opponent and own weapon

Post by Civhai »

Very nice idea. I have no time to test it right now, but thanks a lot.
Working on the Era of Ilthan
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Ability depending on opponent and own weapon

Post by zookeeper »

Yet an event-driven ability will not show the correct damage calculations, which seems rather important for an ability like this.
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: Ability depending on opponent and own weapon

Post by Civhai »

Yes, that is true and that sucks a little bit, but I expected that and so I assume I'll have to live with that. Or do you know any trick to make this work?

By the way, I tested it and it didn't work. It is not an ability but a weapon special, so I put a [/specials][/attack] and [+attack][+specials] around the event, but somehow it doesn't trigger.

Is it possible to reload the WML without having to restart wesnoth? Or is there at least a possibility to avoid the annoying procedure of changing one line -> start wesnoth -> click multiplayer -> Choose Battle -> Choose correct people and choose the unit in question as the leader -> create enemy to try it out on -> try out attack
Working on the Era of Ilthan
User avatar
Dugi
Posts: 4960
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Ability depending on opponent and own weapon

Post by Dugi »

Stupid me, I confused it. Place instead of the filter_attack tag this:

Code: Select all

[filter]
  ability=death_blow
[/filter]
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: Ability depending on opponent and own weapon

Post by Civhai »

That didn't work either. But it is a weapon special, not an ability, so that line shouldn't cause the problem. Here is what my code looks like:

Code: Select all

#define WEAPON_SPECIAL_DEATH_BLOW
    [dummy]
        id=death_blow
        name= _ "Death Blow"
        description= _ "Death Blow:
If an enemy is already severely wounded, this unit can deal a devastating final blow to finish them off. If a unit with this ability attacks an enemy for which it only
needs two hits to kill them, it doubles its strength."
    [/dummy]
[/specials]
[/attack]
[event]
    name=attacker hits
    [filter_attack]
        special=death_blow
    [/filter_attack]
    [if]
        [variable]
            name=second_unit.hitpoints
            less_than_equal_to=$damage_inflicted
        [/variable]
        [then]
            [harm_unit]
                [filter]
                    x,y=$x2,$y2
                [/filter]
                [filter_second]
                    x,y=$x1,$y1
                [/filter_second]
                amount=10000
                experience=yes
                kill=yes
            [/harm_unit]
        [/then]
    [/if]
[/event]
[+attack]
[+specials]
#enddef
And here it is used:

Code: Select all

[unit_type]
    id=EOI_desert_halberdier
    name= _ "Desert Halberdier"
    {MAGENTA_IS_THE_TEAM_COLOR}
    race=EOI_desert_undead
    image="units/desert_undead/desert_halberdier.png"
    hitpoints=50
    movement_type=desert_undead
    movement=5
    level=2
    experience=80
    alignment=chaotic
    advances_to=EOI_desert_slayer
    cost=30
    usage=fighter
    description= _ "These where the elite fighters of an ancient culture. They where extremely strong and considering that mostly, the living counterparts are even stronger than the death ones, the army of that culture must have been extremely powerful."
    {DEFENSE_ANIM "units/desert_undead/desert_halberdier.png" "units/desert_undead/desert_halberdier.png" {SOUND_LIST:SKELETON_BIG_HIT} }
    die_sound=skeleton-big-die.ogg
    [attack]
        description=_"halberd"
        icon=attacks/axe-deathblade.png
        type=blade
        range=melee
        damage=12
        number=3
        [specials]
	    {WEAPON_SPECIAL_DEATH_BLOW}
        [/specials]
    [/attack]
[/unit_type]
Working on the Era of Ilthan
User avatar
Civhai
Posts: 74
Joined: November 5th, 2006, 9:35 am

Re: Ability depending on opponent and own weapon

Post by Civhai »

Ok, thanks again, it works now, I forgot the "first_time_only=no" key, that was why it somehow almost never worked as I expected. But I think it is somehow confusing that the damage is displayed again with this red number. Everyone knows that it is enough damage to kill the other unit, so I thought it would be nicer to display "Death Blow" instead. I found out how to display "Death Blow", however, right now it displays both the number and the text "Death Blow" on top of each other, which looks strange. Do you know how I can fix this, i.e, how I can suppress the normal floating text for damage?

Here is how it looks now:

Code: Select all

[event]
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=death_blow
    [/filter_attack]
    [if]
        [variable]
            name=second_unit.hitpoints
            less_than_equal_to=$damage_inflicted
        [/variable]
        [then]
            [floating_text]
                x,y=$x2,$y2
                text="<span color='#FF0000'>" + _ "Death Blow" + "</span>"
            [/floating_text]
            [harm_unit]
                [filter]
                    x,y=$x2,$y2
                [/filter]
                [filter_second]
                    x,y=$x1,$y1
                [/filter_second]
                amount=10000
                experience=yes
                kill=yes
                fire_event=yes
            [/harm_unit]
        [/then]
    [/if]
[/event]
Working on the Era of Ilthan
Post Reply