How to see if a casting unit is within range, so that a custom ability be activated?

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,732
This is the code: (Can you see this secret message?)
Code:
Show
    Events
        Unit - A unit Begins casting an ability
    Conditions
        (Casting unit) Equal to Unit[(Player number of (Triggering player))]
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyCT 
            Then - Actions
                Dialog - Show Dialog[1] for (Owner of (Casting unit))
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyT 
            Then - Actions
                Dialog - Show Dialog[2] for (Owner of (Casting unit))
            Else - Actions

This is what happens:
55816226gd6.gif


----------------------

Okay, so I added these actions in the conditions. They are boldfaced and colored.

Unit[Integer(CTshop)] and Unit[Integer(Tshop)] are the coins in the picture.
Code:
Show
    Events
        Unit - A unit Begins casting an ability
    Conditions
        (Casting unit) Equal to Unit[(Player number of (Triggering player))]
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyCT
                [COLOR="RoyalBlue"](Distance between (Position of Unit[(Integer(CTshop))]) and (Position of (Casting unit))) Less than or equal to 700.00[/COLOR]
            Then - Actions
                Dialog - Show Dialog[1] for (Owner of (Casting unit))
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyT 
                [COLOR="RoyalBlue"](Distance between (Position of Unit[(Integer(Tshop))]) and (Position of (Casting unit))) Less than or equal to 700.00[/COLOR]
            Then - Actions
                Dialog - Show Dialog[2] for (Owner of (Casting unit))
            Else - Actions

But it doesn't work like it used to be.
57952392zw6.gif



================

Question: How do you set it up, so that the custom ability can be activated only when the unit is near the coins?

Or

How do you set it up so that when someone presses the ability button, and that unit has an arrow above its head, it would pop up a prompt?
 

Alphabet

New Member
Reaction score
12
The only thing I can think of is the 'Unit[(Integer(CTshop))]' and 'Unit[(Integer(Tshop))]'. Try to replace them with the '(unitname) (number) <gen>' things (which you get by using the 'Select unit' button while determining the unit, and choosing the shops from the map).
 

Alphabet

New Member
Reaction score
12
I can't see a reason why that'd leak, and the reason I wanted you to to that was just so it'd show whether the 'Unit[(Integer (TShop))]' and 'Unit[(Integer (CTShop))]' are the problem or not. If it does work the way I suggested you to try, then you've just set the Unit and/or the TShop/CTShop variables wrong (or not at all). :p
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,732
Code:
Show
    Events
        Unit - A unit Begins casting an ability
    Conditions
        (Casting unit) Equal to Unit[(Player number of (Triggering player))]
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyCT
                (Distance between (Position of (Storage 0013 <gen>)) and (Position of (Casting unit))) Less than or equal to 700.00
            Then - Actions
                Dialog - Show Dialog[1] for (Owner of (Casting unit))
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyT 
                (Distance between (Position of (Storage 0012 <gen>)) and (Position of (Casting unit))) Less than or equal to 700.00
            Then - Actions
                Dialog - Show Dialog[2] for (Owner of (Casting unit))
            Else - Actions

It doesn't work.
 

Psiblade94122

In need of sleep
Reaction score
138
instead of useing the ct shop thing, cant you change it to target of casting unit? <i dont know the base ability of your dummy skill>
 

Alphabet

New Member
Reaction score
12
Well, if you need to use that particular condition you could add an action to show a message which contains the distance between the units, and see what value it gives. Maybe there's some kind of problem with that range.

But there are also different ways of making this. Here's 3 I can think of right now:
1) Use a region and the boolean comparsion 'Unit - Unit In Region'.
2) Give the shops some dummy auras and use the boolean comparsion 'Unit - Unit Has Specific Buff'.
3) Change the terrain type at the area you want them to be able to use the skill at, and use the Terrain-type comparsion.
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,732
instead of useing the ct shop thing, cant you change it to target of casting unit? <i dont know the base ability of your dummy skill>

There's no target of the casting ability. The dummy ability is just used to make the pop up menu appear.

Alphabet said:
But there are also different ways of making this. Here's 3 I can think of right now:
1) Use a region and the boolean comparsion 'Unit - Unit In Region'.
2) Give the shops some dummy auras and use the boolean comparsion 'Unit - Unit Has Specific Buff'.
3) Change the terrain type at the area you want them to be able to use the skill at, and use the Terrain-type comparsion.

1. I don't want a rectangle region for the Buying conditions to be activated. It seems unnatural.
2. Does the Arrow above the unit's head counts as a buff? If so, how do you suppose a trigger can be done like that, along with the dialog pop-up? I tried it once, and it doesn't seems to match my expectations.
3. That would definitely give away everything in the map. The coins were put there as a reference in the editor. The models will be changed to "NONE" once everything is finished.
 

Alphabet

New Member
Reaction score
12
2. Does the Arrow above the unit's head counts as a buff?
Well, it doesn't exactly count as a buff. However you can probably make a buff that attaches an arrow overhead the unit.

And figured out there's one more way that should do the job (it functions in the almost same way as your original one):
Code:
Optional
    Events
        Unit - A unit Finishes casting an ability
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to BuyCT
            Then - Actions
                Unit Group - Pick every unit in (Units within 700.00 of (Position of Unit[(Integer(CTshop))]) matching ((Matching unit) Equal to (Triggering unit))) and do (Actions)
                    Loop - Actions
                        Dialog - Show Dialog[1] for (Owner of (Triggering unit))
            Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Ability being cast) Equal to BuyT
                    Then - Actions
                        Unit Group - Pick every unit in (Units within 700.00 of Unit[(Integer(Tshop))] matching ((Matching unit) Equal to (Triggering unit))) and do (Actions)
                            Loop - Actions
                                Dialog - Show Dialog[2] for (Owner of (Triggering unit))
                    Else - Actions
The leaks caused by making those unit groops should be easily fixed.
Uh, I start to feel like a spammer since I've written so many unuseful messages to this thread. <.<
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,732
It didn't work. Units inside the 700.00 range couldn't use the ability.
 

Alphabet

New Member
Reaction score
12
I just tested this:
Code:
Optional
    Events
        Unit - A unit Finishes casting an ability
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Ability being cast) Equal to Flame Strike
            Then - Actions
                Unit Group - Pick every unit in (Units within 512.00 of (Position of Peasant 0000 <gen>) matching ((Matching unit) Equal to (Casting unit))) and do (Actions)
                    Loop - Actions
                        Game - Display to (All players) the text: s
            Else - Actions
It worked as I thought it would, displayed the text "s". So the problem probably is that you've mixed the units (so that CTShop is actually the TShop and vice versa) or the Dialog[1] is not working.
So try these two steps:
1) Replace the '(Position of Unit[(Integer(CTshop))])' with '(Position of Unit[(Integer(Tshop))])'.
2) Add an action to display a message after showing the dialog.
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,732
No, it's none of those above. Figured there's a coding issue in NewGen, I moved the trigger to a new spot, disabled and turned it off initially. Then I created a new trigger and match it to look like the code above. Then it worked. Both outside and inside of the range given.

Okay, it looks like this:
a5920a782f.gif


So, I think it is working, not sure if it's going to be permanent. The text message is the distance between the unit and the coin.

So, if anything comes up, I'll post a new thread. Right now, +rep for your efforts.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top