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,751
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?
 
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).
 
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
 
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.
 
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>
 
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.
 
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.
 
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. <.<
 
It didn't work. Units inside the 700.00 range couldn't use the ability.
 
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.
 
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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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