how to change a side of an attacked unit

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.

how to change a side of an attacked unit

Postby Aldarisvet » October 1st, 2017, 10:42 am

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 Zombies:Introduction single map campaign
Art thread:Mostly frankenstains
User avatar
Aldarisvet
Translator
 
Posts: 606
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Postby Kwandulin » October 1st, 2017, 10:50 am

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
Kwandulin
Art Contributor
 
Posts: 268
Joined: March 30th, 2014, 7:35 am
Location: Germany

Re: how to change a side of an attacked unit

Postby Aldarisvet » October 1st, 2017, 4:23 pm

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 Zombies:Introduction single map campaign
Art thread:Mostly frankenstains
User avatar
Aldarisvet
Translator
 
Posts: 606
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Postby Wayirr » October 3rd, 2017, 3:55 am

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.
Wayirr
 
Posts: 56
Joined: February 11th, 2012, 3:42 pm

Re: how to change a side of an attacked unit

Postby IIIO_METAL » October 3rd, 2017, 8:43 am

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
IIIO_METAL
 
Posts: 82
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: how to change a side of an attacked unit

Postby Aldarisvet » October 3rd, 2017, 9:15 am

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 Zombies:Introduction single map campaign
Art thread:Mostly frankenstains
User avatar
Aldarisvet
Translator
 
Posts: 606
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia

Re: how to change a side of an attacked unit

Postby IIIO_METAL » October 3rd, 2017, 9:32 am

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
IIIO_METAL
 
Posts: 82
Joined: January 18th, 2017, 5:03 pm
Location: japan

Re: how to change a side of an attacked unit

Postby Aldarisvet » October 16th, 2017, 6:03 pm

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 Zombies:Introduction single map campaign
Art thread:Mostly frankenstains
User avatar
Aldarisvet
Translator
 
Posts: 606
Joined: February 23rd, 2015, 2:39 pm
Location: Moscow, Russia


Return to WML Workshop

Who is online

Users browsing this forum: Yandex [Bot] and 2 guests