Abilities clause

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
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Abilities clause

Post by hermestrismi »

Hi.
It has been months since the last time I had been here.
Anyway. I created a [dummy] ability, with an event inside its macro, and I used it for both [unit_type] and [modifications] (to add it to another unit) but for some reasons the ability works for the unit_type but only shows its name and description when I used it inside any new created unit (via [unit] [modifications]

Code: Select all

#define ABILITY_EXPLOSION_DEATH
[dummy]
id=explo_death
name=_"explosion"
description=_".."
[/dummy]
[/abilities]
[event]
...
[/event]
[+abilities]
And for the unit

Code: Select all

[unit]
...
[modifications]
[object]
[effect]
apply_to=new_ability
[abilities]
{ABILITY_EXPLOSION_DEATH}
[/abilities]
[/effect]
[/object]
[/modifications]
[/unit]
I think that the problem is related to [+abilities] so i need to be sure how to implent it correcrly
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Abilities clause

Post by Toranks »

You don't need to use [+abilities], use:

Code: Select all

[abilities]
MACRO>
keys of ability
[/abilities]
[abilities]
<MACRO
[/abilities]
or

Code: Select all

MACRO>
[abilities]
keys of ability
[/abilities]
<MACRO
[+abilities] is for:

Code: Select all

[abilities]
some keys
[/abilities]
MACRO>
[+abilities]
more keys of the SAME ability, or the same keys which will replace the previous keys with the new values
[/abilities]
<MACRO
User avatar
Ravana
Forum Moderator
Posts: 3019
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Abilities clause

Post by Ravana »

You cant support both modifications and unit_type at the same time. In order to place [event] under [unit] you need to handle

[/abilities]
[/effect]
[/object]
[/modifications]

In order to place [event] under [unit_type] you need to handle

[/abilities]

So macro for first use case would have

[/dummy]
[/abilities]
[/effect]
[/object]
[/modifications]
[event]
...
[/event]
[+modifications]
[+object]
[+effect]
[+abilities]
User avatar
Ravana
Forum Moderator
Posts: 3019
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Abilities clause

Post by Ravana »

Toranks wrote: June 20th, 2023, 3:10 am You don't need to use [+abilities], use:

Code: Select all

[abilities]
MACRO>
keys of ability
[/abilities]
[abilities]
<MACRO
[/abilities]
or

Code: Select all

MACRO>
[abilities]
keys of ability
[/abilities]
<MACRO
[+abilities] is for:

Code: Select all

[abilities]
some keys
[/abilities]
MACRO>
[+abilities]
more keys of the SAME ability, or the same keys which will replace the previous keys with the new values
[/abilities]
<MACRO
You only describe first point of https://wiki.wesnoth.org/SyntaxWML#Tag_Amendment_Syntax. Ability macros rely on second point, weapon special macros on third point too.
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Abilities clause

Post by hermestrismi »

Ravana wrote: June 20th, 2023, 6:32 am
Toranks wrote: June 20th, 2023, 3:10 am You don't need to use [+abilities], use:

Code: Select all

[abilities]
MACRO>
keys of ability
[/abilities]
[abilities]
<MACRO
[/abilities]
or

Code: Select all

MACRO>
[abilities]
keys of ability
[/abilities]
<MACRO
[+abilities] is for:

Code: Select all

[abilities]
some keys
[/abilities]
MACRO>
[+abilities]
more keys of the SAME ability, or the same keys which will replace the previous keys with the new values
[/abilities]
<MACRO
You only describe first point of https://wiki.wesnoth.org/SyntaxWML#Tag_Amendment_Syntax. Ability macros rely on second point, weapon special macros on third point too.
I tried many ways to implent it but still the same problem
Ps: I took this ability from RotL in case there is a problem with the event
the macro file

Code: Select all

#define ABILITY_POISONING
   [dummy]
      id=ROLpoisoning
      name= _ "poisoning"
      description= _ "When this unit is destroyed, a toxic gas is unleashed, poisoning all surrounding enemy units in the process. Non-living units are immune."
[/dummy]
[/abilities]
[/effect]
[/object]
[/modifications]
[event]
   name=die
   first_time_only=no
    [filter]
        ability=ROLpoisoning
    [/filter]
    [store_unit]
        [filter]
            [filter_adjacent]
                x,y=$x1,$y1
            [/filter_adjacent]
			[not]
				[filter_wml]
					[status]
						not_living="yes"
					[/status]
				[/filter_wml]
			[/not]
			[and]
			   [not]
				  side=$unit.side
			   [/not]
			[/and]
        [/filter]
       
        variable=units
		kill=no
    [/store_unit]
    {FOREACH units i}
      [set_variable]
         name=units[$i].status.poisoned
         value=yes
      [/set_variable]
      [unstore_unit]
          variable=units[$i]
          find_vacant=no
          text= _ "poisoned"
          {COLOR_HARM}
      [/unstore_unit]
    {NEXT i}
           [kill]
                x,y=$x1,$y1
           [/kill]   
[/event]
[+modifications]
[+object]
[+effect]
[+abilities]
#enddef
the modified unit

Code: Select all

    [event]
        name=prestart
		[unit]
			id=CortonNecromancertest
			name= _ "Corton"
			type=Dark Adept
			x=5
			y=39
			side=1
		    [modifications]
            [object]
                [effect]
                    apply_to=new_ability
					    [abilities]
							{ABILITY_POISONING}
						[/abilities]
                [/effect]
            [/object]
			[/modifications]
		[/unit]
    [/event]
    
the result: the unit have only the ability's name.
PS2: playing wesnoth for yeeeeaars and I realised only now that an ability cannot added to both modifications and unit_type loooool
User avatar
Ravana
Forum Moderator
Posts: 3019
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Abilities clause

Post by Ravana »

As https://wiki.wesnoth.org/SingleUnitWML says A [unit][event] requires a non-empty id= attribute.
User avatar
Ravana
Forum Moderator
Posts: 3019
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Abilities clause

Post by Ravana »

I tested that this successfully poisons units. (wesnoth -p your code snippets, remove wrapping pre event for easier testing, update x,y to be on map, add id)

Code: Select all

# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
	[unit]
		id="CortonNecromancertest"
		name=_"Corton"
		side=1
		type="Dark Adept"
		x=14
		y=21
		[modifications]
			[object]
				[effect]
					apply_to="new_ability"
					[abilities]
						[dummy]
							description=_"When this unit is destroyed, a toxic gas is unleashed, poisoning all surrounding enemy units in the process. Non-living units are immune."
							id="ROLpoisoning"
							name=_"poisoning"
						[/dummy]
					[/abilities]
				[/effect]
			[/object]
		[/modifications]
		[event]
			first_time_only=no
			name="die"
			id="_"
			[filter]
				ability="ROLpoisoning"
			[/filter]
			[store_unit]
				kill=no
				variable="units"
				[filter]
					[filter_adjacent]
						x="$x1"
						y="$y1"
					[/filter_adjacent]
					[not]
						[filter_wml]
							[status]
								not_living=yes
							[/status]
						[/filter_wml]
					[/not]
					[and]
						[not]
							side="$unit.side"
						[/not]
					[/and]
				[/filter]
			[/store_unit]
			[set_variable]
				name="i"
				value=0
			[/set_variable]
			[while]
				[variable]
					less_than="$units.length"
					name="i"
				[/variable]
				[do]
					[set_variable]
						name="units[$i].status.poisoned"
						value=yes
					[/set_variable]
					[unstore_unit]
						color="255,0,0"
						find_vacant=no
						text=_"poisoned"
						variable="units[$i]"
					[/unstore_unit]
					[set_variable]
						add=1
						name="i"
					[/set_variable]
				[/do]
			[/while]
			[clear_variable]
				name="i"
			[/clear_variable]
			[kill]
				x="$x1"
				y="$y1"
			[/kill]
		[/event]
	[/unit]

User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Abilities clause

Post by hermestrismi »

Ravana wrote: June 20th, 2023, 4:35 pm I tested that this successfully poisons units. (wesnoth -p your code snippets, remove wrapping pre event for easier testing, update x,y to be on map, add id)

Code: Select all

# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
	[unit]
		id="CortonNecromancertest"
		name=_"Corton"
		side=1
		type="Dark Adept"
		x=14
		y=21
		[modifications]
			[object]
				[effect]
					apply_to="new_ability"
					[abilities]
						[dummy]
							description=_"When this unit is destroyed, a toxic gas is unleashed, poisoning all surrounding enemy units in the process. Non-living units are immune."
							id="ROLpoisoning"
							name=_"poisoning"
						[/dummy]
					[/abilities]
				[/effect]
			[/object]
		[/modifications]
		[event]
			first_time_only=no
			name="die"
			id="_"
			[filter]
				ability="ROLpoisoning"
			[/filter]
			[store_unit]
				kill=no
				variable="units"
				[filter]
					[filter_adjacent]
						x="$x1"
						y="$y1"
					[/filter_adjacent]
					[not]
						[filter_wml]
							[status]
								not_living=yes
							[/status]
						[/filter_wml]
					[/not]
					[and]
						[not]
							side="$unit.side"
						[/not]
					[/and]
				[/filter]
			[/store_unit]
			[set_variable]
				name="i"
				value=0
			[/set_variable]
			[while]
				[variable]
					less_than="$units.length"
					name="i"
				[/variable]
				[do]
					[set_variable]
						name="units[$i].status.poisoned"
						value=yes
					[/set_variable]
					[unstore_unit]
						color="255,0,0"
						find_vacant=no
						text=_"poisoned"
						variable="units[$i]"
					[/unstore_unit]
					[set_variable]
						add=1
						name="i"
					[/set_variable]
				[/do]
			[/while]
			[clear_variable]
				name="i"
			[/clear_variable]
			[kill]
				x="$x1"
				y="$y1"
			[/kill]
		[/event]
	[/unit]

thank you
Post Reply