Healing + strengthening all units of a side at once

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.
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Healing + strengthening all units of a side at once

Post by revansurik »

Been a while since I last was here ^_^

So, there's this effect I want to apply in a scenario of my campaign where all units of two given sides get healed in 10hp, strengthened by 25% and their resistances increased by 50%. This effect is supposed to last only a few turns, and at every turn when the variable ascendant_spells equals 1, the effect is "renewed" (it was the only way I knew without having the effect last till the scenario's end).
I tried using [object], but it's not working. Am I doing something wrong, or is the intended effect simply not possible?

Code: Select all

   
   [event]
        name=new turn
		first_time_only=no
		[if]
            [variable]
                name=ascendant_spells
                numerical_equals=1
            [/variable]
			[then]

        [object]
            id=ascendants_spells
			take_only_once=no
            duration=turn end
            silent=yes
            [filter]
                side=1,3,5,6
            [/filter]

			[effect]
				apply_to=resistance
				replace=no
				[resistance]
					blade=-50
					pierce=-50
					impact=-50
				[/resistance]
			[/effect]
			[effect]
				apply_to=attack
				increase_damage=25%
			[/effect]
			[effect]
				apply_to=hitpoints
				increase=10
				violate_maximum=no
			[/effect]
		[/object]
		[/then]
		[/if]
    [/event]
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Healing + strengthening all units of a side at once

Post by Lord-Knightmare »

Am I doing something wrong, or is the intended effect simply not possible?
The Wiki wrote: The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed).
Here is my recommendation for a possible solution:
  • in a new turn event, store all units matching your SUF into a variable array
  • Take a [foreach] loop with the array variable and apply [do] your Superbly Unbalanced Overkill Buff object to each of the units stored.
  • Unstore all units with find_vacant=no and then clear the variable array.
Additionally, the [heal_unit][/heal_unit] is better than the object healing method.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Healing + strengthening all units of a side at once

Post by vghetto »

Don't know if this will work. Try putting the object (without the filter) inside [modify_unit] + [filter]
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Re: Healing + strengthening all units of a side at once

Post by revansurik »

Lord-Knightmare wrote: March 2nd, 2021, 7:59 pm Here is my recommendation for a possible solution:
  • in a new turn event, store all units matching your SUF into a variable array
  • Take a [foreach] loop with the array variable and apply [do] your Superbly Unbalanced Overkill Buff object to each of the units stored.
  • Unstore all units with find_vacant=no and then clear the variable array.
Additionally, the [heal_unit][/heal_unit] is better than the object healing method.
Like this?
edit: Forgot to add the unstore bit, but how would I unstore all units right at their respective locations?

Code: Select all

		
		
		    [store_unit]
                [filter]
                    side=1
                    type=(all the unit IDs from the sides to be affected)
                [/filter]

                kill=no
                variable=spell_units
            [/store_unit]
		
		[foreach]
          		variable=spell_units
			[do]

			[object]
				id=ascendants_spells
				take_only_once=no
				duration=turn end
				silent=yes
				[filter]
					side=1,3,5,6
				[/filter]

				[effect]
					apply_to=resistance
					replace=no
					[resistance]
						blade=-50
						pierce=-50
						impact=-50
					[/resistance]
				[/effect]
				[effect]
					apply_to=attack
					increase_damage=25%
				[/effect]
			[/object]
		[/do]
		[/foreach]

            {CLEAR_VARIABLE spell_units}
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Healing + strengthening all units of a side at once

Post by Lord-Knightmare »

This should work.

Code: Select all

[store_unit]
    [filter]
        side=1,3,5,6
        type=Weaver, Scribe, Gatekeeper, Courier, Seeker, Aragwaith Swordsman
    [/filter]

    kill=no
    variable=spell_units
[/store_unit]
		
[foreach]
    variable=spell_units
    [do]

        [object]
            id=ascendants_spells
            take_only_once=no
            duration=turn end
            silent=yes
            [filter]
                id=spell_units[$i].id 
            [/filter]

            [effect]
                apply_to=resistance
                replace=no
                [resistance]
                    blade=-50
                    pierce=-50
                    impact=-50
                [/resistance]
            [/effect]
            [effect]
                apply_to=attack
                increase_damage=25%
            [/effect]
        [/object]
    [/do]
[/foreach]

[unstore_unit]
    variable=spell_units
    find_vacant=no
[/unstore_unit]

{CLEAR_VARIABLE spell_units}
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
IIIO_METAL
Posts: 202
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: Healing + strengthening all units of a side at once

Post by IIIO_METAL »

Change "duration = turn end" to "duration = forever" and apply the object only once. Then, use [remove_object] when the effect expires. I often use this method.
Creator of "Mountain Witch" & "Castle of evil spirit"
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Re: Healing + strengthening all units of a side at once

Post by revansurik »

Lord-Knightmare wrote: March 3rd, 2021, 3:03 am This should work.
There's a 'missing array' error... what should I write in 'array'? the wiki isn't very detailed about that...
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Healing + strengthening all units of a side at once

Post by Lord-Knightmare »

revansurik wrote: March 3rd, 2021, 4:41 am
Lord-Knightmare wrote: March 3rd, 2021, 3:03 am This should work.
There's a 'missing array' error... what should I write in 'array'? the wiki isn't very detailed about that...
It should be the array= key and not variable=.

Code: Select all

[foreach]
    array="spell_units"
    # rest of the code
[/foreach]
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Re: Healing + strengthening all units of a side at once

Post by revansurik »

Lord-Knightmare wrote: March 3rd, 2021, 4:45 am
revansurik wrote: March 3rd, 2021, 4:41 am
Lord-Knightmare wrote: March 3rd, 2021, 3:03 am This should work.
There's a 'missing array' error... what should I write in 'array'? the wiki isn't very detailed about that...
It should be the array= key and not variable=.

Code: Select all

[foreach]
    array="spell_units"
    # rest of the code
[/foreach]
The healing works now, but the units' attack and resistance are unaffected... :hmm:
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
User avatar
IIIO_METAL
Posts: 202
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: Healing + strengthening all units of a side at once

Post by IIIO_METAL »

attack seems to need a key to filter.
resistance doesn't seem to need 'replace = no'.
It worked.

Code: Select all

[effect]
    apply_to=resistance
    [resistance]
        blade=-50
        pierce=-50
        impact=-50
    [/resistance]
[/effect]
[effect]
    apply_to=attack
    range="melee"
    increase_damage=100%
[/effect]
[effect]
    apply_to=attack
    range="ranged"
    increase_damage=100%
[/effect]
Creator of "Mountain Witch" & "Castle of evil spirit"
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Re: Healing + strengthening all units of a side at once

Post by revansurik »

IIIO_METAL wrote: March 3rd, 2021, 1:17 pm attack seems to need a key to filter.
resistance doesn't seem to need 'replace = no'.
It worked.

Code: Select all

[effect]
    apply_to=resistance
    [resistance]
        blade=-50
        pierce=-50
        impact=-50
    [/resistance]
[/effect]
[effect]
    apply_to=attack
    range="melee"
    increase_damage=100%
[/effect]
[effect]
    apply_to=attack
    range="ranged"
    increase_damage=100%
[/effect]
Still not working for me (neither the attack increase, nor the resistance increase) :augh:
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
User avatar
IIIO_METAL
Posts: 202
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: Healing + strengthening all units of a side at once

Post by IIIO_METAL »

I tried a little different code written by Lord-Knightmare. The result with the 1.15 version is successful.
Changed part
object filter: id = $spell_units[$i].id|
[unstore_unit]: Delete

Code: Select all

[store_unit]
    [filter]
        side=1
    [/filter]
    kill=no
    variable = spell_units
[/store_unit]
		
[foreach]
    array = spell_units
    [do]
        [object]
            id=ascendants_spells
            take_only_once=no
            duration=turn end
            silent=yes
            [filter]
                id = $spell_units[$i].id|
            [/filter]
            [effect]
                apply_to=resistance
                [resistance]
                    blade=-50
                    pierce=-50
                    impact=-50
                [/resistance]
            [/effect]
            [effect]
                apply_to=attack
		range="melee"
                increase_damage=25%
            [/effect]
            [effect]
                apply_to=attack
		range="ranged"
                increase_damage=25%
            [/effect]
            [effect]
                 apply_to=hitpoints
                 increase=10
                 violate_maximum=no
            [/effect]
        [/object]
    [/do]
[/foreach]

{CLEAR_VARIABLE spell_units}
Creator of "Mountain Witch" & "Castle of evil spirit"
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Re: Healing + strengthening all units of a side at once

Post by revansurik »

IIIO_METAL wrote: March 4th, 2021, 4:34 am I tried a little different code written by Lord-Knightmare. The result with the 1.15 version is successful.
Changed part
object filter: id = $spell_units[$i].id|
NOW it worked! :mrgreen:
Thanks so much to both of you! ^_^
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Healing + strengthening all units of a side at once

Post by Celtic_Minstrel »

revansurik wrote: March 2nd, 2021, 7:37 pm I tried using [object], but it's not working. Am I doing something wrong, or is the intended effect simply not possible?
Using [object] is correct, but since you want it to apply to everyone who matches the filter, it needs to be used inside [modify_unit], like this:

Code: Select all

   
[event]
	name=new turn
	first_time_only=no
	[if]
		[variable]
			name=ascendant_spells
			numerical_equals=1
		[/variable]
		[then]
			[modify_unit]
				[filter]
					side=1,3,5,6
				[/filter]
		        	[object]
					duration=turn end
					[effect]
						apply_to=resistance
						replace=no
						[resistance]
							blade=-50
							pierce=-50
							impact=-50
						[/resistance]
					[/effect]
					[effect]
						apply_to=attack
						increase_damage=25%
					[/effect]
					[effect]
						apply_to=hitpoints
						increase=10
						violate_maximum=no
					[/effect]
				[/object]
			[/modify_unit]
		[/then]
	[/if]
[/event]
IIIO_METAL wrote: March 3rd, 2021, 4:00 am Change "duration = turn end" to "duration = forever" and apply the object only once. Then, use [remove_object] when the effect expires. I often use this method.
This is also a good idea. You need an id= in the [object] to support this.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
revansurik
Posts: 604
Joined: October 17th, 2012, 11:40 pm
Location: Brazil
Contact:

Re: Healing + strengthening all units of a side at once

Post by revansurik »

Celtic_Minstrel wrote: March 4th, 2021, 1:57 pm
revansurik wrote: March 2nd, 2021, 7:37 pm I tried using [object], but it's not working. Am I doing something wrong, or is the intended effect simply not possible?
Using [object] is correct, but since you want it to apply to everyone who matches the filter, it needs to be used inside [modify_unit], like this:
Well, that code did work even though I didn't use [modify_unit]... Though now that I think about it I only tested in 1.15; maybe 1.14 would require that...
Author of the Dragon Trilogy.

If you enjoyed A Song of Fire, War of the Jewel, Aria of the Dragon-Slayer and Soldier of Wesnoth, you may like my new project: Star of Chaos, a science-fiction mystery/adventure intended to be a trilogy
;-)
Post Reply