• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

AI wont cast spells

Status
Not open for further replies.
Level 2
Joined
Jul 10, 2019
Messages
9
I have read some threads before and none of them helped, so I decided to post my own;

I made a trigger which should merge 2 units to form 1, like an archer mounting a hippogryph. For further detail, the base ability is based off ''pick up archer'' and renamed to ''Amalgamation''. I want the Melee AI to cast it when the ability is researched, to form, as mentioned before, 2 Dogs into a ''Hybrid''. Why doesn't this work?

I am quite new to this, so I apologise for not knowing this. Please do not post JAVA scripts. And if any trigger contains variables, please explain them.
 

Attachments

  • Screenshot (14).png
    Screenshot (14).png
    9.4 KB · Views: 52
Level 39
Joined
Feb 27, 2007
Messages
5,024
JASS? ;) Some useful links for new mappers:
Things That Leak
How To Post Your Trigger
Event Response Myths

The reason your trigger doesn’t work is because there is no triggering unit to refer to. The trigger was triggered by a time event, so something like “expired timer” would work (though it’s not relevant to the intended effect of your trigger). What you want to do is pick all dog units owned by that ai player and order them to use the spell.
 
Level 2
Joined
Jul 10, 2019
Messages
9
The reason your trigger doesn’t work is because there is no triggering unit to refer to.

Ah, I thought you only need to refer the type of unit you want to use in the conditions. But the problem is, whenever I store the unit I want to use in a variable, the event section does not seem to detect the variable I want to use in, let's say Unit - Unit Specific Event, nor does the list mention anything about gaining an ability or upgrade. Albeit it has ''Learns a Skill'' it seems to only apply to Heroes. I probably glimced over something and did not realise it, I cannot figure out how to ''refer'' to the Dog without using regions. Cheers for the links, will definitely come in use.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
the event section does not seem to detect the variable I want to use in, let's say Unit - Unit Specific Event, nor does the list mention anything about gaining an ability or upgrade.
Look at the underlying JASS. It passes the value of the variable at the time the event is created, hence changing that variable does not change the value used by the event.

One has to use a generic (all units) event and then filter using a condition.
 
Level 2
Joined
Jul 10, 2019
Messages
9
After a bit of testing I've finally got it. +rep for the help and info to all of you


  • Merge
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • (Current research level of Amalgamation for Player 1 (Red)) Equal to 1
    • Actions
      • Set Unit_Dog = (Random unit from (Units of type Dog))
      • Unit - Order Unit_Dog to Night Elf Hippogryph - Pick Up Archer

On a side note, is there a way to refer to every player without individually trying to copy and paste the same trigger but only change the --for Player X (Colour)--?
 
Level 2
Joined
Jul 10, 2019
Messages
9
Pick all players, check if Picked Player has the research, if so order dog to combine. You’re leaking a unit group.
  • Merge
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set GroupDog = (Units of type Dog)
      • Set UnitDog = (Random unit from (Units of type Dog))
      • Set DogPoint = (Position of (Random unit from (Units owned by (Picked player) of type Dog)))
      • Set DogPoint2 = (Position of (Picked unit))
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) controller) Equal to Computer
              • (Number of units in (Units of type Dog)) Greater than 1
              • (Current research level of Amalgamation for (Picked player)) Equal to 1
            • Then - Actions
              • Unit Group - Pick every unit in GroupDog and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • UnitDog Equal to (Picked unit)
                      • (Owner of (Picked unit)) Equal to (Picked player)
                    • Then - Actions
                      • Unit - Order (Picked unit) to Right-Click (Random unit from (Units owned by (Picked player) of type Dog))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Distance between (Position of (Picked unit)) and DogPoint) Less than or equal to 900.00
                        • Then - Actions
                          • Unit - Order (Picked unit) to Night Elf Hippogryph - Pick Up Archer
                          • Custom script: call RemoveLocation(udg_DogPoint)
                          • Custom script: call RemoveLocation(udg_DogPoint2)
                        • Else - Actions
                          • Do nothing
                    • Else - Actions
                      • Do nothing
            • Else - Actions
              • Do nothing
      • Custom script: set bj_wantDestroyGroup = false
?
 
Level 9
Joined
Jul 30, 2018
Messages
445
I'm not sure how bj_wantDestroyGroup works when creating a group for a variable. Doesn't the group get destroyed right after the line is ran? Anyway, I would instead just use Custom Script: call DestroyGroup(udg_GroupDog). Also, if you are using bj_wantDestroyGroup, you don't have to set it back to false. It is automatically set false for every group and you only need to set true if you want to.

You are also leaking another group in the DogPoint variable set. And the Picked Player does not refer to any player, because you have not picked any players at that point. Same with Picked Unit.

Thirdly, I don't know either how well that "Order to right-click" works or how reliable it is. I'd instead just use the exact thing I want to happen: in this case order the unit to explicitly move there.

Fourthly, you can just click and delete all those "Do nothing". They literally do nothing and there is no point using them.

Also, is it necessarily to run this trigger so often? How is the upgrade added to the player? Maybe run this just once then, or is it something periodic that should happen all the time?

Edit: Lastly, you have to clean the leaks at the end of the trigger (or after you don't need the variable anymore) outside the ifs. Because now it will leak those groups every second if they don't pass the ifs all the way down.

Edit2:

This is like something you should do:

  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Set GroupDog = (Units owned by (Picked player) of type Dog)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Picked player) controller) Equal to Computer
            • (Number of units in GroupDog) Greater than 1
            • (Current research level of Amalgamation for (Picked player)) Equal to 1
          • Then - Actions
            • Set UnitDogA = (Random unit from GroupDog)
            • -------- The next line is to make sure that the random choosing doesn't choose the same dog again. --------
            • Unit Group - Remove UnitDogA from GroupDog
            • Set UnitDogB = (Random unit from GroupDog)
            • Unit - Order UnitDogA to Follow UnitDogB
            • Set DogPointA = (Position of UnitDogA)
            • Set DogPointB = (Position of UnitDogB)
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Distance between DogPointA and DogPointB) Less than or equal to 900.00
              • Then - Actions
                • Unit - Order UnitDogA to Night Elf Hippogryph - Pick Up Archer
              • Else - Actions
            • Custom script: call RemoveLocation(udg_DogPointA)
            • Custom script: call RemoveLocation(udg_DogPointB)
          • Else - Actions
        • Custom script: call DestroyGroup(udg_GroupDog)
Though, this is not perfect: if the player has more than two dogs, the dogs will probably just change targets all the time (because the trigger is ran so often) and basically just roll around.

To get around this you could for example add the randomly chosen dogs to a different group and not pick any units from that group on the random pick up. Or use Unit Indexer and recognize this way if the dog was already picked once.
 
Last edited:
Status
Not open for further replies.
Top