How to make one unit stop striking during an attack

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 make one unit stop striking during an attack

Postby WhiteWolf » January 5th, 2018, 8:40 pm

Hi,

Is there any way to tell, which attack is used in an event? For example, in an "attacker hits" event, is there a variable that stores the name of the attack used?
I though of running a loop, which compares all attack damages with $damage_inflicted, but that would be ambiguous - what if there's a unit with two attacks of the same damage?

Also, is there a way to somehow make a unit stop striking during the attack, (but let the opponent continue hitting back), if a certain criteria is met in the attacker hits event? But the unit should fight normally, if he's attacked again.
1.13.x solutions (add an object, then remove it) are not available, I use 1.12 :(

Best regards,
WhiteWolf
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary


Re: How to tell which attack is used in an event?

Postby WhiteWolf » January 10th, 2018, 3:09 pm

Thanks :)

Is it somehow possible to make a unit stop fighting, but let the opponent keep fighting?
For example, this is a feature that gives some bonus somewhere, but the cost is, that when a unit attacks, if a certain criteria is met, it will stop trying to hit, but the opponent will finish his attacks as normal.

I tried to zero the attack's number through [modify_unit], or through an object, but the attack went on as normal, the effects only kicked in after the attack. How can it be done, to apply the effects immediately, during the attack?
I suspect I need to use Lua - but I really don't know lua :(
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to tell which attack is used in an event?

Postby ChaosRider » January 10th, 2018, 7:14 pm

WhiteWolf wrote:Thanks :)

Is it somehow possible to make a unit stop fighting, but let the opponent keep fighting?
For example, this is a feature that gives some bonus somewhere, but the cost is, that when a unit attacks, if a certain criteria is met, it will stop trying to hit, but the opponent will finish his attacks as normal.

I tried to zero the attack's number through [modify_unit], or through an object, but the attack went on as normal, the effects only kicked in after the attack. How can it be done, to apply the effects immediately, during the attack?
I suspect I need to use Lua - but I really don't know lua :(


Check Critical Strikes mod. Use there weapon special that set strikes to 0 or chance to hit to 0.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
ChaosRider
 
Posts: 831
Joined: April 15th, 2012, 1:15 pm

Re: How to tell which attack is used in an event?

Postby WhiteWolf » January 10th, 2018, 10:32 pm

Critical Strikes mod adds the objects in an event=attack. Before the attack, so I guess it works.
I need the unit to be "reloaded" with the mod in an event=attacker/defender hits.
I tried it, it doesn't work. The attack numbers are only set to 0 after the fight took place, not during, right when the event kicks in. I do not really understand this behaviour of objects, why doesn't it kick in right when applied? I guess it's because unit attack values are "loaded" into the fight at the start, and they can't be overriden during the attack?
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to tell which attack is used in an event?

Postby mattsc » January 11th, 2018, 3:54 am

WhiteWolf wrote:I guess it's because unit attack values are "loaded" into the fight at the start, and they can't be overriden during the attack?

I believe that that interpretation is pretty much correct. What you can do to interrupt the fight is to save and kill the unit, and then reload it in an attack_end event. As an example, something along those lines is done here. That doesn't do what you want, but maybe you can use it as a model to get the desired behavior?
mattsc
 
Posts: 991
Joined: October 13th, 2010, 6:14 pm
Location: Wandering, mostly aimlessly

Re: How to tell which attack is used in an event?

Postby ChaosRider » January 11th, 2018, 7:03 pm

I'm looking or interesting skills (weapon specials, abilities) and I've found this (might be helpful for you):
Code: Select all

#define WEAPON_SPECIAL_IE_INTERRUPT
            [knockback]
                id=ie_interrupt
                name= _ "interrupt-day only"
                description=_ "When a unit is hit with an interrupting attack, combat is immediately stopped. Works only during dawn and dusk and during the day, when the sun is in the sky."
            [/knockback]
        [/specials]
    [/attack]
    [event]
        name=defender hits
        first_time_only=no
        [filter_second_attack]
            special=interrupt
        [/filter_second_attack]
        [filter]
            [filter_location]
                time_of_day_id=dawn,morning,afternoon,dusk
            [/filter_location]
        [/filter]
        [if]
       [then]
      [store_unit]
          [filter]
         find_in=second_unit
          [/filter]
          variable=target
          kill=yes
      [/store_unit]
            [/then]
        [/if]
    [/event]
    [event]
        name=attack end
        first_time_only=no
   [unstore_unit]
       variable=target
       text="interrupt"
       {COLOR_HEAL}
   [/unstore_unit]
   {CLEAR_VARIABLE target}
    [/event]
    [+attack]
        [+specials]
#enddef
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
ChaosRider
 
Posts: 831
Joined: April 15th, 2012, 1:15 pm

Re: How to tell which attack is used in an event?

Postby WhiteWolf » January 11th, 2018, 10:35 pm

I've kept experimenting with adding an object at the beginning of the attack, that kicks in with a formula for filter_opponent, but I gave up.

However, I found a workaround with interrupting the battle :) Namely, I start counting the strikes that the opponent has left at the beginning. If the criteria is met, fight is interrupted in way similar to the ones you described, and then the remaining strikes from the opponent are done manually with animate_unit and harm_unit.
Probably not elegant, but it works more or less as I intended :)
The only compromises are that chance-to-hit is completely lost, I hardwired it for 30%. I can reason for this when introducing the mechanics in the game, so for this context, it's not such a big problem. There is also loss of information on the actual damage to be done, luckily harm_unit can take resistance and time of day into accout (it's not in the code yet, my bad), but extra-extra-custom modifiers are lost.

Here's the about final code if anyone's interested:
Spoiler:


Thanks :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby Sapient » January 12th, 2018, 5:11 am

You seem to be missing some code, for example, the fire_event. It is possible to pass along weapon data with fire_event, by the way.

I have a suggestion... I am not 100% sure this will work, but have you tried removing all the unit's attacks when the special hits? Worth a try anyway.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Developer
 
Posts: 4381
Joined: November 26th, 2005, 7:41 am

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 12th, 2018, 7:04 pm

The fire events are in another file. I made a post about the combat events a while ago: https://forums.wesnoth.org/viewtopic.php?f=12&t=44574&p=601967&hilit=combat#p601967 :) They come in handy, when it doesn't matter who's the attacker and who's the defender.

OK, here's the full code :)
Spoiler:


The code still loses the information on weapon specials. I'll hardwire 'magic' and 'marksman', because they are rather frequent, but other chance-to-hit-modifiers will be lost, and the hardwired 30% chance-to-hit for the leftover attacks will be applied.

I tried removing all attacks, but the attack continues as normal, the object that removes the attacks only kicks in after the attack. :(


Yes, I see now, that primary/secondary attack can be passed along, but how exactly? (no example on the wikipage) Would it be
Code: Select all
[fire_event]
    [primary_attack]
        weapon=$weapon....? sounds dull

Or do I need to declare every attribute I want to pass, like damage=$weapon.damage, type=$weapon.tpye, etc?
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby octalot » January 13th, 2018, 3:14 am

The [petrifies] special is handled by the by the engine, and immediately stops the combat. It's also built in to the combat UI, in the pre-combat stats the hp bar will be shown as grey if a unit will get petrified. It seems that nothing in the mainline units or mainline campaigns uses this weapon special.

In Ageless_Era/data/EoMa_data/sculpt.cfg there's events that trigger after the combat, used by the level 3 Medusa Witch. For her, the petrify ability has been reduced to "sculpts", with the victim automatically unpetrified in a later turn by these events.
I've been on a long Wesbreak for most of 2016.
octalot
 
Posts: 73
Joined: July 17th, 2010, 7:40 pm

Re: How to make one unit stop striking during an attack

Postby Sapient » January 13th, 2018, 1:54 pm

WhiteWolf wrote:I tried removing all attacks, but the attack continues as normal, the object that removes the attacks only kicks in after the attack. :(


Oh, that's too bad. I have a couple of other ideas. I may experiment with it a bit on my own.

WhiteWolf wrote:Yes, I see now, that primary/secondary attack can be passed along, but how exactly? (no example on the wikipage) ... do I need to declare every attribute I want to pass, like damage=$weapon.damage, type=$weapon.tpye, etc?


This is where [insert_tag] comes in handy:

Code: Select all
[fire_event]
    [insert_tag]
        name=primary_attack
        variable=weapon


Note: there is currently a proposal to make this the default behavior for fire_event (passing along all the relevant context, unless overridden).
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Developer
 
Posts: 4381
Joined: November 26th, 2005, 7:41 am

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 13th, 2018, 6:12 pm

octalot wrote:The [petrifies] special"

OK, petrifying and unpetrifying would have a similar effect, stopping the attack, but the other unit would not continue striking. Petrified units can't be striked at as far as I know :) So as I understand, it's the same as storing the unit, then unstoring it in an attack end. :(

Sapient wrote:I may experiment with it a bit on my own.

Let me know if you find anything :)


This is where [insert_tag] comes in handy:

That's cool, thanks :D
Oh, and thanks for renaming the topic - I quite forgot about that :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby Celtic_Minstrel » January 14th, 2018, 3:55 pm

You should be able to get the proper base chance to hit by using [store_unit_defense], I think?
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 848
Joined: August 3rd, 2012, 11:26 pm

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 15th, 2018, 10:24 am

Sounds cool, but I use 1.12 for the campaign where I'd like the effect :( 1.14 should solve it then :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 351
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Next

Return to WML Workshop

Who is online

Users browsing this forum: No registered users and 3 guests