Difference between revisions of "WML Abilities"

From The Battle for Wesnoth Wiki
m (See Also)
(Remove some dependebcies now in core, clean up macros.)
Line 1: Line 1:
 
Remember that you must include the WML ability code in every scenario where you intend them to work. Or include them in the unit file inside the [unit] tag.
 
Remember that you must include the WML ability code in every scenario where you intend them to work. Or include them in the unit file inside the [unit] tag.
  
Abilities require macros found elsewhere in UsefulFragments, typically ProgammingMacros, [[WML_Utilities|Utilities]], or Scenario Tools.  
+
Some abilities require macros from [[WML_Utilities|Utilities]].  
  
 
=== Knockback  ===
 
=== Knockback  ===
Line 11: Line 11:
 
  {KNOCKBACK description=Jane mace}
 
  {KNOCKBACK description=Jane mace}
  
Requires the macros ''OPPOSITE_SIDE'', ''IF'', ''IF_HAVE_UNIT'' and ''STORE_UNIT_VAR''.
+
Requires the macros ''OPPOSITE_SIDE'', '''IF_HAVE_UNIT'' and ''STORE_UNIT_VAR''.
  
 
  #define KNOCKBACK FILTER WEAPON
 
  #define KNOCKBACK FILTER WEAPON
Line 40: Line 40:
 
         {IF_HAVE_UNIT x,y=$target_hex.x,$target_hex.y (
 
         {IF_HAVE_UNIT x,y=$target_hex.x,$target_hex.y (
 
             [else]
 
             [else]
                 {IF defender_in_village.length not_equals 1 (
+
                 {IF_VAR defender_in_village.length not_equals 1 (
 
                     [then]
 
                     [then]
 
                         {STORE_UNIT_VAR x,y=$x2,$y2 side side_of_defender}
 
                         {STORE_UNIT_VAR x,y=$x2,$y2 side side_of_defender}
Line 76: Line 76:
 
  {CHARM (type=Troll Whelp) fist}
 
  {CHARM (type=Troll Whelp) fist}
  
Requires the macros ''IF'', ''STORE_UNIT_VAR'' and ''MODIFY_UNIT''.
+
Requires the macros ''IF_VAR'' and ''STORE_UNIT_VAR''.
  
 
  #define CHARM FILTER WEAPON
 
  #define CHARM FILTER WEAPON
Line 94: Line 94:
 
         {STORE_UNIT_VAR x,y=$x2,$y2 side charmed_side}
 
         {STORE_UNIT_VAR x,y=$x2,$y2 side charmed_side}
 
   
 
   
         {IF charmer_side not_equals $charmed_side (
+
         {IF_VAR charmer_side not_equals $charmed_side (
 
             [then]
 
             [then]
 
                 {MODIFY_UNIT x,y=$x2,$y2 variables.real_side $charmed_side}
 
                 {MODIFY_UNIT x,y=$x2,$y2 variables.real_side $charmed_side}
Line 118: Line 118:
 
         {VARIABLE_OP this_side_charmed to_variable "side_$side_number|_units_charmed"}
 
         {VARIABLE_OP this_side_charmed to_variable "side_$side_number|_units_charmed"}
 
   
 
   
         {IF this_side_charmed equals yes (
+
         {IF_VAR this_side_charmed equals yes (
 
             [then]
 
             [then]
 
                 [store_unit]
 
                 [store_unit]
Line 134: Line 134:
 
                     {VARIABLE_OP real_side format "0$possibly_charmed[$i].variables.real_side"}
 
                     {VARIABLE_OP real_side format "0$possibly_charmed[$i].variables.real_side"}
 
   
 
   
                     {IF real_side not_equals "0" (
+
                     {IF_VAR real_side not_equals "0" (
 
                         [then]
 
                         [then]
                             {IF side_number equals $possibly_charmed[$i].variables.real_side (
+
                             {IF_VAR side_number equals $possibly_charmed[$i].variables.real_side (
 
                                 [then]
 
                                 [then]
 
                                     {CLEAR_VARIABLE possibly_charmed[$i].variables.real_side}
 
                                     {CLEAR_VARIABLE possibly_charmed[$i].variables.real_side}
Line 160: Line 160:
  
 
Bloodlust is a very simple ability. If a unit that has bloodlust kills an enemy unit when attacking, it may attack again, provided that there are more enemy units adjacent to it.
 
Bloodlust is a very simple ability. If a unit that has bloodlust kills an enemy unit when attacking, it may attack again, provided that there are more enemy units adjacent to it.
 
Requires the macro MODIFY_UNIT.
 
  
 
This would give the bloodlust ability to all Dwarvish Ulfserkers (making them insanely powerful):
 
This would give the bloodlust ability to all Dwarvish Ulfserkers (making them insanely powerful):
Line 188: Line 186:
  
 
  #define WEAPON_SPECIAL_PICKPOCKET
 
  #define WEAPON_SPECIAL_PICKPOCKET
[damage]
+
    [damage]
id=pickpocket
+
        id=pickpocket
name="Pickpocket"
+
        name="Pickpocket"
description="Pickpocket:
+
        description="When used offensively, this attack gives 10 gold to the attacker on every successful hit."  
When used offensively, this attack gives 10 gold to the attacker on every successful hit."  
+
        multiply=1
multiply=1
+
    [/damage]
[/damage]
 
 
  #enddef
 
  #enddef
  
Line 200: Line 197:
  
 
  [event]
 
  [event]
name=attacker_hits
+
    name=attacker_hits
first_time_only=no
+
    first_time_only=no
[filter]
+
    [filter]
side=$side_number
+
        side=$side_number
canrecruit=1
+
canrecruit=1
[/filter]
+
    [/filter]
[special_filter]
+
    [special_filter]
weapon=pickpocket gloves
+
        weapon=pickpocket gloves
[/special_filter]
+
    [/special_filter]
[gold]
+
    [gold]
side=$side_number
+
        side=$side_number
amount=10
+
amount=10
[/gold]
+
    [/gold]
 
  [/event]
 
  [/event]
  
Line 218: Line 215:
  
 
  [object]
 
  [object]
silent=yes
+
    silent=yes
[effect]
+
    [effect]
apply_to=new_attack  
+
        apply_to=new_attack  
name=pickpocket gloves
+
name=pickpocket gloves
type=impact
+
type=impact
range=melee  
+
range=melee  
damage=3
+
damage=3
number=3  
+
number=3  
[specials]
+
[specials]
{WEAPON_SPECIAL_PICKPOCKET}
+
    {WEAPON_SPECIAL_PICKPOCKET}
[/specials]
+
[/specials]
  [/effect]
+
    [/effect]
 
  [/object]
 
  [/object]
  

Revision as of 16:10, 26 February 2008

Remember that you must include the WML ability code in every scenario where you intend them to work. Or include them in the unit file inside the [unit] tag.

Some abilities require macros from Utilities.

Knockback

When a unit is hit with a knockback attack, it is immediately pushed one hex away from the attacker, at which point the combat ends. Exception: units in villages can't be knocked out of them.

Examples that give knockback for every Drake Glider on their slam attack, and for the Shock Trooper named Jane:

{KNOCKBACK (type=Drake Glider) slam}
{KNOCKBACK description=Jane mace}

Requires the macros OPPOSITE_SIDE, 'IF_HAVE_UNIT and STORE_UNIT_VAR.

#define KNOCKBACK FILTER WEAPON
    [event]
        name=attacker_hits
        first_time_only=no

        [filter]
            {FILTER}
        [/filter]

        [special_filter]
            weapon={WEAPON}
        [/special_filter]

        [sound]
            name=ghoul-hit.wav
        [/sound]

        {OPPOSITE_SIDE $x2 $y2 $x1 $y1 target_hex}

        [store_locations]
            x,y=$x2,$y2
            terrain=AaBbDeLptUVvYZ
            variable=defender_in_village
        [/store_locations]

        {IF_HAVE_UNIT x,y=$target_hex.x,$target_hex.y (
            [else]
                {IF_VAR defender_in_village.length not_equals 1 (
                    [then]
                        {STORE_UNIT_VAR x,y=$x2,$y2 side side_of_defender}

                        [teleport]
                            [filter]
                                x,y=$x2,$y2
                            [/filter]

                            x,y=$target_hex.x,$target_hex.y
                        [/teleport]

                        [capture_village]
                            side=$side_of_defender
                            x,y=$target_hex.x,$target_hex.y
                        [/capture_village]

                        {CLEAR_VARIABLE side_of_defender}
                    [/then]
                )}
            [/else]
        )}

        {CLEAR_VARIABLE target_hex}
        {CLEAR_VARIABLE defender_in_village}
    [/event]
#enddef

Charm

When a unit is hit with a charm attack, it instantly jumps to the attacker's side, and returns to it's original side at the beginning of that side's turn. A charmed unit has 1 movement point and can attack.

Example that makes all Troll Whelps have charm on their attack:

{CHARM (type=Troll Whelp) fist}

Requires the macros IF_VAR and STORE_UNIT_VAR.

#define CHARM FILTER WEAPON
    [event]
        name=attacker_hits
        first_time_only=no

        [filter]
            {FILTER}
        [/filter]

        [special_filter]
            weapon={WEAPON}
        [/special_filter]

        {STORE_UNIT_VAR x,y=$x1,$y1 side charmer_side}
        {STORE_UNIT_VAR x,y=$x2,$y2 side charmed_side}

        {IF_VAR charmer_side not_equals $charmed_side (
            [then]
                {MODIFY_UNIT x,y=$x2,$y2 variables.real_side $charmed_side}
                {MODIFY_UNIT x,y=$x2,$y2 side $charmer_side}
                {MODIFY_UNIT x,y=$x2,$y2 moves 1}
                {MODIFY_UNIT x,y=$x2,$y2 attacks_left 1}

                {VARIABLE_OP varname format "side_$charmed_side|_units_charmed"}
                {VARIABLE $varname yes}

                {CLEAR_VARIABLE varname}
            [/then]
        )}

        {CLEAR_VARIABLE charmer_side}
        {CLEAR_VARIABLE charmed_side}
    [/event]

    [event]
        name=side turn
        first_time_only=no

        {VARIABLE_OP this_side_charmed to_variable "side_$side_number|_units_charmed"}

        {IF_VAR this_side_charmed equals yes (
            [then]
                [store_unit]
                    [filter]
                        [not]
                            side=$side_number
                        [/not]
                    [/filter]

                    variable=possibly_charmed
                    kill=no
                [/store_unit]

                {FOREACH possibly_charmed i}
                    {VARIABLE_OP real_side format "0$possibly_charmed[$i].variables.real_side"}

                    {IF_VAR real_side not_equals "0" (
                        [then]
                            {IF_VAR side_number equals $possibly_charmed[$i].variables.real_side (
                                [then]
                                    {CLEAR_VARIABLE possibly_charmed[$i].variables.real_side}
                                    {VARIABLE possibly_charmed[$i].side $side_number}

                                    [unstore_unit]
                                        variable=possibly_charmed[$i]
                                        find_vacant=no
                                    [/unstore_unit]
                                [/then]
                            )}
                        [/then]
                    )}
                {NEXT i}

                {CLEAR_VARIABLE possibly_charmed}
            [/then]
        )}
    [/event]
#enddef

Bloodlust

Bloodlust is a very simple ability. If a unit that has bloodlust kills an enemy unit when attacking, it may attack again, provided that there are more enemy units adjacent to it.

This would give the bloodlust ability to all Dwarvish Ulfserkers (making them insanely powerful):

{BLOODLUST (type=Dwarvish Ulfserker)}
#define BLOODLUST FILTER
    [event]
        name=die
        first_time_only=no

        [filter_second]
            {FILTER}
        [/filter_second]

        {MODIFY_UNIT x,y=$x2,$y2 moves 0}
        {MODIFY_UNIT x,y=$x2,$y2 attacks_left 1}
    [/event]
#enddef

Pickpocket

This special could also be called loot. When a unit with this attack special sucessfully hits an enemy unit, it gains a certain amount of gold - say 10.

To do this, use this code:

#define WEAPON_SPECIAL_PICKPOCKET
    [damage]
        id=pickpocket
        name="Pickpocket"
        description="When used offensively, this attack gives 10 gold to the attacker on every successful hit." 
        multiply=1
    [/damage]
#enddef

Then put this event in your scenario:

[event]
    name=attacker_hits
    first_time_only=no
    [filter]
        side=$side_number
	 canrecruit=1
    [/filter]
    [special_filter]
        weapon=pickpocket gloves
    [/special_filter]
    [gold]
        side=$side_number
	 amount=10
    [/gold]
[/event]

Then give the unit you want to have the "pickpocket" special something like this:

[object]
    silent=yes
    [effect]
        apply_to=new_attack 
	 name=pickpocket gloves
	 type=impact
	 range=melee 
	 damage=3
	 number=3 
	 [specials]
	     {WEAPON_SPECIAL_PICKPOCKET}
	 [/specials]
    [/effect]
[/object]

See Also