How can two abilities stop each other?

Klin

Member
Hi,

I want two abilities being able to stop each other.
So when Ability 1 is active, Ability 2 can activate and stop Ability 1.
Normally one would accomplish that simply by putting the Ability 2 over Ability 1.

But what if I want also that Ability 1 can stop Ability 2 if it's active?

Thanks for any ideas!
 

GreedyMerchant

New member
Sorry, I just reread this and I believe you actually wanna look into interrupt source. It's mentioned briefly on the magic page of the online documentation but I'm sure you can find more information about it in the offline documentation.

 

ChristianWiele

Moderator
Staff member
Are you talking about standard abilities, or your own abilities? For the latter you can implement
Code:
 public override bool ShouldBlockAbilityStart(Ability startingAbility)
method to decide whether an ability is allowed to start while another is running. The newly starting ability can then stop the running one.
 

Klin

Member
Are you talking about standard abilities, or your own abilities? For the latter you can implement
Code:
 public override bool ShouldBlockAbilityStart(Ability startingAbility)
method to decide whether an ability is allowed to start while another is running. The newly starting ability can then stop the running one.
Hi Christian,
thanks for your reply.

You gave the right hint. I tried this method but it wouldn't work. Now I simply made one ability concurrent and it works perfectly fine this way.
 
Last edited:

Klin

Member
Sorry I marked the thread allready as solved but I ran into a problem.

I have basically the same situation as explained above but now I can't use the concurrent functionality and I can't figure out how to use the described methods.

So I have ability_1, which is on top.
I have ability_2, which is on the bottom.
I want to stop ability_1, when I press the key for ability_2.

I tried multiple ways, here is one of them I thought should work:

ability_1 (top, running)
C#:
        public override bool ShouldBlockAbilityStart(Ability startingAbility)
        {
            if (startingAbility is ability_2)
            return false;
        }

ability_2 (buttom, should start and stop ability_1)
C#:
        public override bool ShouldStopActiveAbility(Ability activeAbility)
        {
            if(activeAbility is ability_1)
            return true;
        }

I put debugs inside the methods, they are not even called when I try to start.
In ability_2, "CanStartAbility()" returns true when I press the button.

Would you mind giving me those 2 lines of code and where to put them, would be much appreciated.

Thanks a lot for helping out!
 

ChristianWiele

Moderator
Staff member
I see. The problem is that the priority prevents the ShouldBlockAbilityStart / ShouldStopActiveAbility from being called on the second ability. As a workaround you could stop the first ability in the CanStartAbility of the second. Justin will think about a more elegant solution.
 

Klin

Member
Ahh ok thats a good idea. I used an event to notify ability1 to stop. Works perfectly fine for the moment. thanks a lot!
 
Top