how to change a side of an attacked unit

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
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

how to change a side of an attacked unit

Post by Aldarisvet »

Hi!

I wrote the code for my hero unit, a Silver Mage with a plague staff, recently I published sprites of lvl4 Silver Archmage with the staff - viewtopic.php?f=23&t=43112&start=75#p617116
The idea is that by attacking with the staff of any undead unit it goes under control of the hero.

Code: Select all


#define UNDEAD_CONTROL
    [event]
        name=attack
        first_time_only=no

	[filter_attack]
	name=plague staff
	[/filter_attack]

        [filter]
            type=Velendar Dread Mage
        [/filter]

        [filter_second]
            race=undead
        [/filter_second]
        $second_unit.side=1
    [/event]
#enddef
I guess the filterig is correct, the problem may be in adressing the side of the attacked unit. Help me please!
facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
User avatar
Kwandulin
Art Contributor
Posts: 362
Joined: March 30th, 2014, 7:35 am
Location: Germany

Re: how to change a side of an attacked unit

Post by Kwandulin »

Code: Select all

#define UNDEAD_CONTROL
[event]
        name=attack
        first_time_only=no

        [filter_attack]
                name=plague staff
        [/filter_attack]

        [filter]
                type=Velendar Dread Mage
        [/filter]

        [filter_second]
                race=undead
        [/filter_second]
        [modify_unit]
                [filter]
                        x,y=$x2,$y2
                [/filter
                side=1
        [/modify_unit]
[/event]
#enddef
You need [modify_unit] (or anything equivalent) to change the side of the attacked unit. You can't just put side=X in the event. I didn't test the code, but it should work theoretically
User avatar
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Post by Aldarisvet »

Thank you very much for the fast help!
There was a missing ']' symbol after '[/filter' in your code but that was not a problem at all.
In the end I made it as weapon special that can be added to other weapon specials of the plague staff (magical and plague in my case).
Probably I should put some sound inside the event because this attack ends with changing the side of the target without any animations.

Code: Select all

#define WEAPON_SPECIAL_UNDEAD_CONTROL
    [attacks]
	id=undead_control
	name= _ "undead control"
        description= _ "On offense the staff permanently puts an undead target under control of the attacker."
        apply_to=self
        active_on=offense
    [/attacks]
    # wmlxgettext: [specials]
    [/specials]
    # wmlxgettext: [attack]
    [/attack]
    [event]
        name=attack
        first_time_only=no

	[filter_attack]
	name=plague staff
	[/filter_attack]


        [filter_second]
            race=undead
        [/filter_second]
        [modify_unit]
                [filter]
                        x,y=$x2,$y2
                [/filter]
                side=1
        [/modify_unit]
    [/event]
    [+attack]
    # wmlxgettext: [/attack]
    [+specials]
    # wmlxgettext: [/specials]
#enddef

facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
Wayirr
Posts: 90
Joined: February 11th, 2012, 3:42 pm

Re: how to change a side of an attacked unit

Post by Wayirr »

I can see a potential problem if plague staff has several attacks and it works on first attempt. Will battle with two units of same side continue?
Also it's better not to hardcode side, so maybe replace 1 with $unit.side ? I didn't test it though.
User avatar
IIIO_METAL
Posts: 202
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: how to change a side of an attacked unit

Post by IIIO_METAL »

Wayirr wrote:Will battle with two units of same side continue?
Also it's better not to hardcode side, so maybe replace 1 with $unit.side ? I didn't test it though.
I have tried making ability close to that. At that time the battle was terminated halfway.
[modify_unit] did as follows so as not to limit the side of the user.

Code: Select all

[modify_unit]
    [filter]
        id=$second_unit.id
    [/filter]
    side=$unit.side
[/modify_unit]
Creator of "Mountain Witch" & "Castle of evil spirit"
User avatar
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Post by Aldarisvet »

Wayirr wrote:I can see a potential problem if plague staff has several attacks and it works on first attempt. Will battle with two units of same side continue?
Also it's better not to hardcode side, so maybe replace 1 with $unit.side ? I didn't test it though.
The battle between units of the same side not even begins. The side changes and that is all.
I think I will put fake battle animations to show one fake melee attack with the staff.
And if the attacked unit is not undead, it is attacked by the normal way.

I know that there are much more complicated things like 'domination' from "Besiged druids" where attacked unit goes to the side of the player just for 1 turn or something like that. My ability changes the side of the attacked undead permanenty which looks as great advantage. But this not so given in that scenario there would be no ability to recruit normally, so this would be the way to 'recruit' from the enemy, he-he.
Last edited by Aldarisvet on October 4th, 2017, 5:39 pm, edited 1 time in total.
facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
User avatar
IIIO_METAL
Posts: 202
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: how to change a side of an attacked unit

Post by IIIO_METAL »

Aldarisvet wrote:I think I will put fake battle animations to show one fake melee attack with the staff.
Using "name = attacker hits", the effect becomes active once you hit. Then you do not need extra animation.But since the attack must be hit, the probability of success is not 100%.
Creator of "Mountain Witch" & "Castle of evil spirit"
User avatar
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Post by Aldarisvet »

While making fake attack animation inside the previous code I used this:

Code: Select all

        [animate_unit]
            flag=attack
            [filter]
                        x,y=$x1,$y1
            [/filter]
            [filter_second]
                        x,y=$x2,$y2
            [/filter_second]
            [primary_attack]
                name=plague staff
            [/primary_attack]
            hits=yes
        [/animate_unit]
The problem is that it attacks not in the destination of the target, but in the destination that the attacking unit had previosuly.
I was using animated fake battles in my campaign earlier (with decreasing HP it looks totally like real battles) and was resolving this problem by modifying destination of the attacking unit.
But here, inside event macros I do not know the destination!
So I really wonder, why [filter_second] do not work to determine the target and the destination of the attack? Help me please.
facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
User avatar
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Post by Aldarisvet »

Heh, no one answered about this bug with the direction of the attack in "[animate_unit] flag=attack".
But I found the solution. Thank to Faelord's campaign Amaranthine Stone. There are lot of useful code there. He is using [harm unit] tag to create animations of fake battles. It works in that way that primary unit is harmed unit and secondary is the attacker. However you have to use 'amount' parameter here (the amount of damage that will be done) so I decided that the undead unit that would be attacked by Velendar would lose 1 HP alongside joining to Velendar.
Also, as suggested, I added 'side=$unit.side' instead 'side=1' while modifying side of the attacked undead unit.

So here is the final code.

Code: Select all


#define WEAPON_SPECIAL_UNDEAD_CONTROL
    [attacks]
	id=undead_control
	name= _ "undead control"
        description= _ "On offense the staff permanently puts an undead target under control of the attacker."
        apply_to=self
        active_on=offense
    [/attacks]
    # wmlxgettext: [specials]
    [/specials]
    # wmlxgettext: [attack]
    [/attack]
    [event]
        name=attack
        first_time_only=no

	[filter_attack]
	name=plague staff
	[/filter_attack]


        [filter_second]
            race=undead
        [/filter_second]


        [harm_unit]
            [filter]
                        x,y=$x2,$y2
            [/filter]
            [filter_second]
                        x,y=$x1,$y1
            [/filter_second]
            [primary_attack]
                name=plague staff
            [/primary_attack]
    	amount=1
    	kill=no
    	animate=yes
        [/harm_unit]

        [modify_unit]
                [filter]
                        x,y=$x2,$y2
                [/filter]
                side=$unit.side
        [/modify_unit]



    [/event]
    [+attack]
    # wmlxgettext: [/attack]
    [+specials]
    # wmlxgettext: [/specials]
#enddef

facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
User avatar
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

conditional unit transforming

Post by Aldarisvet »

Hi!

I need some help.
I had an event inside which a unit transforms its type. Actually it changes a silver staff of the hero to the plague staff, that is all. The problem that to the moment a hero can be of level 3 or at level 4 so he should be transformed to accordingly.

Here is the code. What is the mistake here? Without [if] it transforms well, but to only one type. With this code it level up the unit instead of transforming.

Code: Select all

[transform_unit]
id=velendar3

	[if]
    	[variable]
    		name=$unit.level
    		numerical_equals=3
    	[/variable]
    [then]
	transform_to=Velendar Dread Mage
    [/then]
	[else]
	transform_to=Velendar Dread ArchMage
	[/else]
	[/if]
[/transform_unit]
facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: how to change a side of an attacked unit

Post by Choicerer »

Hi.

Code: Select all

[variable]
    	name=$unit.level
   	numerical_equals=3
[/variable]
should read

Code: Select all

[variable]
    	name=unit.level
   	numerical_equals=3
[/variable]
Why? Because $ is the dereferencing sign, it grabs a value from a variable. So if you write $unit.level you are setting the name to be 3 or whatever the unit level is. But since you are testing for a variable called unit.level, not 3, you don't want the value of that variable, but the name.

EDIT: That's not all. You cannot insert a conditional into the [tranfsorm] tag or any other tag of this sort. You need to do:

Code: Select all

[if]
    [variable]
    		name=unit.level
    		numerical_equals=3
    [/variable]
    [then]
            [transform_unit]
                    id=velendar3
	            transform_to=Velendar Dread Mage
           [/transform_unit]
    [/then]
    [else]
            [transform_unit]
                    id=velendar3
	            transform_to=Velendar Dread ArchMage
           [/transform_unit]
    [/else]
[/if]
User avatar
Aldarisvet
Translator
Posts: 836
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Post by Aldarisvet »

Thank you for the fast answer, I tried your code but this is not working properly.
While testing with level3 silver mage It it transformed to level4 dread silver mage not level3 dread silver mage.
Obviously because in condition the engine does not know about which unit this is all is about.
That was the reason I put [if] into [transform_unit] tag, so the id of the unit is specified there.

How I should specify in [variable] the id of the unit I am adressing?
Last edited by Aldarisvet on May 28th, 2018, 6:48 pm, edited 1 time in total.
facebook.com/wesnothian/ - everyday something new about Wesnoth
My campaign:A Whim of Fate, also see it's prequel Zombies:Introduction
Art thread:Mostly frankenstains
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: how to change a side of an attacked unit

Post by Choicerer »

What event are you calling this from? The unit variable is used in unit-related events, not action tags like this one.
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Re: how to change a side of an attacked unit

Post by Eagle_11 »

have you tried velendar3.level, also dont write the level 4 as an [else] to this [if] but as another [if] block.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: how to change a side of an attacked unit

Post by Choicerer »

That will not work in WML, unless you declare a WML arrray called that.
You can't use conditional tags inside of command tags, they only accept specific arguments.
Last edited by Choicerer on May 28th, 2018, 7:02 pm, edited 2 times in total.
Post Reply