WML problem, attack that has a chance to do extra damage

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
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

WML problem, attack that has a chance to do extra damage

Post by siddh »

Hello I am trying to piece together this era called "Draconian Era" which is completely work in progress. In the era there's so far a Samurai styled faction and a Dwarven faction. This question relates to the Dwarven faction, which is supposed to have a Dwarf called Stormhammer, which hits for impact damage. The trick is that I'd want the Stormhammer dwarf to deal extra lightning damage with each succesful hit, or that there's a 50% chance that it happens. Anyway this only makes sense if it takes into account the defender's resistance, since the chief idea is to counter units with high physical resistances but low lightning resistance. However this is way beyond my WML abilities at the moment, I've just dabbled with WML previously, and not really made anything before starting to make this Era. I looked up this ability called "Cleave" which has some little bit of similarity, but I couldn't really get it. For now at least. :D

So it's not like I'm asking anyone to make this for me, but could someone maybe point me to similar abilities so I could try and mimic the technique? Or maybe give some points on where to start? What kind of a things are involved? :D
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: WML problem, attack that has a chance to do extra damage

Post by Max »

have a look at http://wiki.wesnoth.org/DirectActionsWM ... rm_unit.5D

there's an "attacker hits" event. and according to this: http://wiki.wesnoth.org/VariablesWML#Au ... _Variables you can easily query the weapon.
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

Max wrote:have a look at http://wiki.wesnoth.org/DirectActionsWM ... rm_unit.5D

there's an "attacker hits" event. and according to this: http://wiki.wesnoth.org/VariablesWML#Au ... _Variables you can easily query the weapon.
Thanks, those elements certainly seem like they'd be the key ingredients in making this. But it still seems a little complicated so I think I'll come back to this after doing some simpler stuff like adding units and simpler abilities, but eventually gotta make this :D
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

Well I started trying to do this anyway with those help files and this is what I came up with so far, but it dosen't seem to work. :D Any ideas? I'm guessing the filter is wrong, I gotta try some other variations like [filter][filter_location] or something like that :D

Code: Select all

[event]
       name=attacker hits
       first_time_only=no
   
       [filter_attack]
           special=electrocute
       [/filter_attack]
                          [harm_unit] 
                           [filter]
                           x,y=$x2,$y2
                           [/filter]
                           amount=5
                           damage_type=lightning
                           fire_event=yes
                           experience=no
                           [/harm_unit]
[/event]
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

well the problem was quite simple. I had written the WEAPON_SPECIAL_ELECTROCUTE into the event as special=electrocute, but actually I got the id as draconian_electrocute... So well anyway I got it done. In case someone is interested doing a similar ability, etc, then here's how it works:

Code: Select all

#define WEAPON_SPECIAL_ELECTROCUTE
     [dummy]
        id=draconian_electrocute
        name= _ "Electrocute"
        description= _ "Electrocute:
This attack has a chance to deal additional lightning damage to the target on every hit."
    [/dummy]
[/specials]
[/attack]
[event]
name=attacker_hits
first_time_only=no
[filter_attack]
special=draconian_electrocute
[/filter_attack]
[filter_second]
[/filter_second]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=6
	damage_type=lightning
	fire_event=yes
	experience=yes
	[/harm_unit]
[/event]
[event]
name=defender_hits
first_time_only=no
[filter_second_attack]
special=draconian_electrocute
[/filter_second_attack]
[filter]
[/filter]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=6
	damage_type=lightning
	fire_event=yes
	experience=yes
	[/harm_unit]
[/event]
[+attack]
[+specials]
#enddef
User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: WML problem, attack that has a chance to do extra damage

Post by Azeal »

that is a good start, now all you need is to get rid of some of the code that does nothing, and add a random variable.

Code: Select all


#define WEAPON_SPECIAL_ELECTROCUTE
     [dummy]
        id=draconian_electrocute
        name= _ "Electrocute"
        description= _ "Electrocute:
This attack has a 50% chance to deal 6 additional lightning damage to the target on every hit."
    [/dummy]
#enddef

### the event will fire multiple times for each different unit type that has this ability, so we need to add the event separately so it is not duplicated.
### add the event to your era file

[event]
    name=attacker_hits
    first_time_only=no
    [filter_attack]
        special=draconian_electrocute
    [/filter_attack]
   {VARIABLE_OP electrocute_chance rand (1,0)}
   [if]
       [variable]
           name=electrocute_chance
           equals=1
       [/variable]
       [then] 
           [harm_unit]
               [filter]
                   x,y=$x2,$y2
               [/filter]
               amount=6
               damage_type=lightning
               kill=yes
               ###this means the damage will kill the unit if it's HP reaches 0
               ###the unit is already receiving experience through the attack, adding it here would make it double
           [/harm_unit]
        [/then]
    [/if]
    {CLEAR_VARIABLE electrocute_chance}
[/event]
[event]
    name=defender_hits
    first_time_only=no
    [filter_second_attack]
        special=draconian_electrocute
    [/filter_second_attack]
   {VARIABLE_OP electrocute_chance rand (1,0)}
   [if]
       [variable]
           name=electrocute_chance
           equals=1
       [/variable]
       [then] 
           [harm_unit]
               [filter]
                   x,y=$x1,$y1
               [/filter]
               amount=6
               damage_type=lightning
               kill=yes
               ###this means the damage will kill the unit if it's HP reaches 0
               ###the unit is already receiving experience through the attack, adding it here would make it double
           [/harm_unit]
        [/then]
    [/if]
    {CLEAR_VARIABLE electrocute_chance}
[/event]

there is an alternative if you want the damage to scale with the units level to.

Code: Select all


#define WEAPON_SPECIAL_ELECTROCUTE TYPE DAMAGE
     [dummy]
        id=draconian_electrocute{TYPE}
        name= _ "Electrocute {DAMAGE}"
        description= _ "Electrocute:
This attack has a 50% chance to deal {DAMAGE} additional lightning damage to the target on every hit."
    [/dummy]
[/specials]
[/attack]
### because this time we want to be able to modify the event, we use TYPE to change the special id to prevent multiple firing
### instead of adding {WEAPON_SPECIAL_ELECTROCUTE} to your weapon specials it would be, for example {WEAPON_SPECIAL_ELECTROCUTE dwarf_dude 6}
[event]
    name=attacker_hits
    first_time_only=no
    [filter_attack]
        special=draconian_electrocute{TYPE}
    [/filter_attack]
   {VARIABLE_OP electrocute_chance rand (1,0)}
   [if]
       [variable]
           name=electrocute_chance
           equals=1
       [/variable]
       [then] 
           [harm_unit]
               [filter]
                   x,y=$x2,$y2
               [/filter]
               amount={DAMAGE}
               damage_type=lightning
               kill=yes
           [/harm_unit]
        [/then]
    [/if]
    {CLEAR_VARIABLE electrocute_chance}
[/event]
[event]
    name=defender_hits
    first_time_only=no
    [filter_second_attack]
        special=draconian_electrocute{TYPE}
    [/filter_second_attack]
   {VARIABLE_OP electrocute_chance rand (1,0)}
   [if]
       [variable]
           name=electrocute_chance
           equals=1
       [/variable]
       [then] 
           [harm_unit]
               [filter]
                   x,y=$x1,$y1
               [/filter]
               amount={DAMAGE}
               damage_type=lightning
               kill=yes
           [/harm_unit]
        [/then]
    [/if]
    {CLEAR_VARIABLE electrocute_chance}
[/event]
[+attack]
    [+specials]
#enddef
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

Cool thanks! I think I actually got the {TYPE} thing. It was in several abilities And I just didn't get what it means - so - you replace the {TYPE} with the unit's unique id, or the name the game has stored for it, by adding the {TYPE} after the special=draconian_electrocute ? :D

Anyhow I started thinking that maybe the random chance isn't such a great idea because like well let's say you got 5 attacks, and the chance to hit hte target with each is 50% or something, and you expect to get 2 or 3 hits. Now if we have a random chance attached to the electrocture ability, then we're expecting like 1-3 hits from the special. Although this makes perfect sense stylewise, it makes it hard to use this ability in terms of countering some type of unit with negative resistance. On other hand it's possible to scale the damage up, by say doublingthe damage with 50% chance of firing. This also changes the probability distribution of the damage, so we have twice higher max damage and twice lower min damage, which means the unit becomes more luck influenced.. But I'm not decided on that... Anyway thanks coz at least now I know how to that :D Or maybe know :D Well I'm pretty sure I got the chance system.

But I'm not exactly sure on the {TYPE} and {DAMAGE} parts. is it that when you place the ability on a unit, you've to do something like

Code: Select all

[abilities]
{WEAPON_SPECIAL_ELECTROCUTE this_guy 5} 
[/abilities]
or is the {TYPE} automatic? :D
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

Now this is an entirely different question. I'm making this Vampire Faction in the era, and I wanted the vampires to have this ability called "COERCION" and some of the other non-vampire units in the faction to have this ability called "MINION" and the idea is that the Vampires give essentially [charge] to the minion units when adjacent, or at least the vampires with the coercion ability. Although i Was thinking it would be like +40% damage done, +60% damage taken or similar, instead of the +100%, +100% seen in normal, charge ability... But that's not so important it may as well be 50,50. I found the "initiative aura" in the links given by Max earlier, and tried to work it out based off that. But I couldn't quite get it. Anyway here's how i changed it, and I think this has to problems at least 1. I didn't get the TYPE thing at all (when making this, now I have a better idea though) and 2. the [firststrike] tag probably just can't be replaced with a custom ability..
.. but anyway i made this invisible weaponspecial "COERCED" which is supposed to create the coercion/minion effect. here's what i got - well it's essentially directly copied from the link and just replaced firststrike with coerced, and of course it doesn't work. But I've not really yetg one through a huge deal of effort with that one, been making other stuffs and such :D

Code: Select all

#define ABILITY_MINION
    [dummy]
        id=draconian_minion
        name= _ "Minion"
        description= _ "Minion"
    [/dummy]
#enddef

#define WEAPON_SPECIAL_COERCED
    [damage]
        id=draconian_coerced
        name= _ ""
        description= _ ""
        multiply=1.5
        apply_to=both
        active_on=both
    [/damage]
#enddef

#define ABILITY_COERCION
    [dummy]
        id=draconian_coercion
        name= _ ""
        description= _ ""
    [/dummy]
[/abilities]
	[event]
		name=attack
		first_time_only=no

		[filter]
			[filter_adjacent]
				ability=draconian_minion
				is_enemy=no
			[/filter_adjacent]
		[/filter]
		
		{FOREACH unit.attack i}
			{VARIABLE unit.attack[$i].specials.coerced.id "coercion"}
		{NEXT i}
		
		[unstore_unit]
			variable=unit
		[/unstore_unit]
	[/event]
	[event]
		name=attack
		first_time_only=no

		[filter_second]
			[filter_adjacent]
				ability=draconian_minion
				is_enemy=no
			[/filter_adjacent]
		[/filter_second]
		
		{FOREACH second_unit.attack i}
			{VARIABLE second_unit.attack[$i].specials.coerced.id "coercion"}
		{NEXT i}
		
		[unstore_unit]
			variable=second_unit
		[/unstore_unit]
	[/event]
	[event]
		name=attack_end
		first_time_only=no

		[filter]
			[wml_filter]
				[attack]
					[specials]
						[coerced]
							id=draconian_coerced
						[/coerced]
					[/specials]
				[/attack]
			[/wml_filter]
		[/filter]
		
		{FOREACH unit.attack i}
			{CLEAR_VARIABLE unit.attack[$i].specials.coerced}
		{NEXT i}
		
		[unstore_unit]
			variable=unit
		[/unstore_unit]
	[/event]
	[event]
		name=attack_end
		first_time_only=no

		[filter_second]
			[wml_filter]
				[attack]
					[specials]
						[coerced]
							id=draconian_coerced
						[/coerced]
					[/specials]
				[/attack]
			[/wml_filter]
		[/filter_second]
		
		{FOREACH second_unit.attack i}
			{CLEAR_VARIABLE second_unit.attack[$i].specials.coerced}
		{NEXT i}
		
		[unstore_unit]
			variable=second_unit
		[/unstore_unit]
	[/event]
[+abilities]
#enddef

User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: WML problem, attack that has a chance to do extra damage

Post by Azeal »

siddh wrote:

Code: Select all

[abilities]
{WEAPON_SPECIAL_ELECTROCUTE this_guy 5} 
[/abilities]
That is right =)

As for the second part you've done a good start, however the specials variable applies to the tag, not the id, so that can only be done that way with pre-existing specials.
Also these are abilities not weapon specials.Try this.

Code: Select all


#define ABILITY_COERCION
    [dummy]
        id=draconian_coercion
        name= _ ""
        description= _ ""
    [/dummy]
#enddef

#define ABILITY_MINION
    [dummy]
        id=draconian_minion
        name= _ "Minion"
        description= _ "Minion"
    [/dummy]
[/abilities]
   [event]
      name=attack
      first_time_only=no

      [filter]
         ability=draconian_minion
         [filter_adjacent]
            ability=draconian_coercion
            is_enemy=no
         [/filter_adjacent]
      [/filter]
      
      [set_variables]
          name=unit.abilities.damage
          [value]
              id=draconian_coerced
              name= _ ""
              description= _ ""
              multiply=1.5
              apply_to=both
              active_on=both
          [/value]
      [/set_variables]

   [/event]
   [event]
      name=attack
      first_time_only=no

      [filter_second]
         ability=draconian_minion
         [filter_adjacent]
            ability=draconian_coercion
            is_enemy=no
         [/filter_adjacent]
      [/filter_second]
      
      [set_variables]
          name=second_unit.abilities.damage
          [value]
              id=draconian_coerced
              name= _ ""
              description= _ ""
              multiply=1.5
              apply_to=both
              active_on=both
          [/value]
      [/set_variables]

   [/event]
   [event]
      name=attack_end
      first_time_only=no

      [filter]
         ability=draconian_minion
         [filter_adjacent]
            ability=draconian_coercion
            is_enemy=no
         [/filter_adjacent]
      [/filter]
      
      {FOREACH unit.abilities.damage i}
         [if]
             [variable]
                 name=unit.abilities.damage[$i].id
                 equals=draconian_coerced
             [/variable]
             [then]
                 {CLEAR_VARIABLE unit.abilities.damage[$i]}
             [/then]
         [/if]
      {NEXT i}
      
   [/event]
   [event]
      name=attack_end
      first_time_only=no

      [filter_second]
         ability=draconian_minion
         [filter_adjacent]
            ability=draconian_coercion
            is_enemy=no
         [/filter_adjacent]
      [/filter_second]
      
      {FOREACH second_unit.abilities.damage i}
         [if]
             [variable]
                 name=second_unit.abilities.damage[$i].id
                 equals=draconian_coerced
             [/variable]
             [then]
                 {CLEAR_VARIABLE second_unit.abilities.damage[$i]}
             [/then]
         [/if]
      {NEXT i}

   [/event]
[+abilities]
#enddef

siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

Thanks :D I tried that and couldn't get it to work, but I think I got the idea from your post of how it might work, so I think I might get it working in a bit :D It's also possible I did something wrong (well that would be no surprise) :D
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: WML problem, attack that has a chance to do extra damage

Post by 8680 »

I believe that the “coercion”/“minion” abilities could be implemented without events, like so:

Code: Select all

#define ABILITY_COERCION
    [dummy]
        id="draconian_coercion"
        name= _ "coercion"
        description= _ "The presence of this unit instills fear and rage into its nearby minions, causing them to charge recklessly into battle. Adjacent allied units with the <i>minion</i> ability will, when attacking, deal 40% more damage, and take 60% more damage."
    [/dummy]
#enddef

#define ABILITY_MINION
    [dummy]
        id="draconian_minion"
        name= _ "minion"
        description= _ "This unit is a born minion, and can easily be coerced into disregarding its own safety in order to please its master. An adjacent allied unit with the <i>coercion</i> ability will cause this unit to, when attacking, deal 40% more damage, and take 60% more damage."
    [/dummy]
#enddef

#define WEAPON_SPECIAL_MINION
    ## An invisible weapon special to be applied to all attacks of units
    ## with `ABILITY_MINION`.
    [damage]
        id="draconian_minion_damage_self"
        active_on=offense
        apply_to=self
        multiply=1.4
        [filter_self]
            [filter_adjacent]
                ability="draconian_coercion"
                is_enemy=no
            [/filter_adjacent]
        [/filter_self]
    [/damage]
    [damage]
        id="draconian_minion_damage_opponent"
        active_on=offense
        apply_to=opponent
        multiply=1.6
        [filter_self]
            [filter_adjacent]
                ability="draconian_coercion"
                is_enemy=no
            [/filter_adjacent]
        [/filter_self]
    [/damage]
#enddef
User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: WML problem, attack that has a chance to do extra damage

Post by Azeal »

wow, ok, that is a lot simpler. Don't know how I overlooked that :S
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem, attack that has a chance to do extra damage

Post by siddh »

Cool that is a *lot simpler*. I was just *right now* trying to make this work and am very dumbfound : D Thanks 8680. And Azeal. :)

PS. I'm not sure if Azeal's version worked because I had some other errors which prevented it from working so it's very possible :D
Post Reply