• 🏆 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!

Spawned units restart channel every 3-4 seconds but preplaced units of the same type do not?

Level 3
Joined
Jan 17, 2024
Messages
11
Hi, first post, go easy on me:

I have a unit (custom unit based on Makrura Prawn with only very slightly differences to mana/armor/etc., and an acquisition Range of 20000). I can preplace any number of these on the map and then run a trigger to get them all, add a starfall/channel/tranquility ability to them and they will channel it successfully for the full duration, regardless of what channel style ability it is.

If I create the same units through a trigger "Create 8 Makrura Prawn at some location facing some direction" and use the same trigger to get them all, add the ability, and issue the order, every 3-4 seconds they cancel the channel and restart channel again from the beginning (assuming the channel ability I give them has a low enough cooldown).

Why would spawned units behave this way and preplaced units behave differently?

In addition, if I do a mix (preplace half, spawn half) I can watch the preplaced ones channel correctly while the spawned ones keep interrupting themselves, so I'm really at a loss as to why this would be happening.

Any ideas?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Hello, welcome to Hive :D

So you're going to have to show us your trigger or triggers, luckily it's really easy on Hive:

Maybe you're spawning them for a different Player that uses different AI? Maybe you have another trigger interfering with their orders? Can't say for certain.
 
Level 3
Joined
Jan 17, 2024
Messages
11
Hey Uncle, long time reader first time caller lol, I've read countless amounts of your posts <3

Here's a blank map I just made that (somewhat) replicates the problem. Well, it perfectly replicates the issue, but unfortunately(?) the units I place down in the editor also have the same "bad" behavior, instead of behaving as expected. My bigger concern isn't with preplaced units working, its with spawned units not working, so this is fine.

The map contains:
1. A copy and pasted Makrura Prawn that has 100 max and initial mana
2. A copy + pasted starfall custom ability that requires no mana, has no cooldown, and has some properties changed to only target buildings and never deal damage essentially.
3. A map property that makes pink an enemy force.
4. A trigger that will spawn 8 of my custom unit when you type -spawn
  • Spawn
    • Events
      • Player - Player 1 (Red) types a chat message containing -spawn as An exact match
    • Conditions
    • Actions
      • Unit - Create 8 Makrura Prawn for Player 8 (Pink) at (Center of (Playable map area)) facing Default building facing degrees
5. A trigger that will get all units in the map, add the custom starfall, and order them to starfall.
  • Channel
    • Events
      • Player - Player 1 (Red) types a chat message containing -channel as An exact match
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Unit - Add Starfall to (Picked unit)
          • Unit - Order (Picked unit) to Night Elf Priestess Of The Moon - Starfall.
What you will see is that after 3 seconds they cancel the starfall and start over. Why is this?

Note: Yes I'm familiar with leaks and the fact that I also grabbed the player unit too :p I was just spinning something up extra fast for demo purposes.


Edit:
It also may be a good idea to state my actual goal rather than the problem I am observing.

I have a wave survival game that is attempting to periodically grab enemies, have them channel an ability that does nothing to signify they are "charging up and the player should interrupt them" and then when they finish channeling, use an ability on a player character.

I had started to give up on the channel approach because of what we are seeing here with the units never finishing the channel and always re-channeling after 3-4 seconds (its a very specific and consistent time in this dummy map and in my actual map). I instead added a cast time to the spell they would ultimately cast at the end of the channel, but I really don't like this approach because it seems very convoluted to detect when a "casting time" of a non-channeled ability is interrupted.

If we can't solve this "re-channeling" issue, which I'm sure we can, since it can be reproduced on a blank map, any suggestions about a better way to implement my goal would be a totally acceptable workaround.

(Thanks to Uncle / everyone that is active in this community, your posts over the years have helped me tremendously with this project.)

Edit/Update 2:
I've been trying to do as much debugging as I can and here are the notes from testing on the fresh test map:

Things that are interesting that I've noticed:

-Removing "Run Melee AI Scripts for Computer Players" does not solve the problem.
-Spawning a different kind of unit does not solve the problem (tried sorceress, Archmage, Paladin, Mountain King, Priestess of the Moon)
-Its interesting that the paladin for Player 1 that is unit controlled behaves correctly and carries out the channel.
-Editting the forces so that Pink is no longer set to Computer controlled "fixes the problem".
-I've always just assumed I needed to have my enemies assigned to a Computer controller rather than no controller. But now I'm wondering if they behavior would be fine with no controller. Shelfing that thought for a moment, I'd still to figure out why having a Computer controller is causing this to happen.
-I tested with Blizzard, Tranquility, Channel, all have the same behavior.
 

Attachments

  • testMap.w3m
    17.8 KB · Views: 2
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
This isn't causing the issue as far I can tell but make sure to NOT run melee AI scripts:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
I found the Makrura won't interrupt their channeling if I set their Controller to None instead of Computer. This implies it's some built in AI that's interfering (unrelated to the above trigger).

For using the Casting Time method, you can rely on a Unit Indexer and some simple logic to determine when a unit is in the "Casting Time" state or not. It should also work for Channeled abilities as well since they use the same Events:
  • Start Casting
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
    • Actions
      • Game - Display to (All players) for 5.00 seconds the text: ((Name of (Triggering unit)) + started casting)
      • Set VariableSet Is_Casting_Ability[(Custom value of (Triggering unit))] = True
  • Interrupt Casting
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • Is_Casting_Ability[(Custom value of (Triggering unit))] Equal to True
    • Actions
      • Game - Display to (All players) for 5.00 seconds the text: ((Name of (Triggering unit)) + was interrupted)
      • Set VariableSet Is_Casting_Ability[(Custom value of (Triggering unit))] = False
  • Finish Casting
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Game - Display to (All players) for 5.00 seconds the text: ((Name of (Triggering unit)) + finished casting)
      • Set VariableSet Is_Casting_Ability[(Custom value of (Triggering unit))] = False
This works because of the execution order of the Events and our usage of the Is_Casting_Ability boolean variable. A unit that is casting will always run the "Stops casting" Event, which can complicate things since it'll run when the ability is interrupted OR successful. So to account for this we rely on the Is_Casting_Ability boolean to see if the unit has finished casting or not when this Stop occurs. If the boolean is TRUE when it Stops then we know it was interrupted. If the boolean is FALSE when it Stops then we know it had already finished casting.

The main issue with the Casting Time method is getting the spell animations to play. You could probably get it to work by queuing up a bunch of "spell" animations a frame after the Begins channeling event occurs.

Wait 0.01 seconds -> Play "spell" animation -> For loop from 1 to 10: Queue "spell" animation.

This would tell the unit to play it's spell animation and then each time it's finished it should play another spell animation, up to 10 times (based on loop range). It should automatically fix it's animation once interrupted or finished casting. If not, you'll need to reset it's queue/animations yourself.
 

Attachments

  • Test Map 2.w3m
    19.1 KB · Views: 1
Last edited:
Level 3
Joined
Jan 17, 2024
Messages
11
Thank you so much. I'll explore having NONE as the controller and see what negative impacts it has to my game. I never put much thought into not having Computer as the controller, although now that I think about it I don't think I am relying on the Computer to do anything at all since its a wave survival game with logic controlled through triggers....

As for the Casting implementation, it was complete user error on my part, the trigger I had to detect "stopped casting" was copy and pasted from a trigger that was not initially on, so it wasn't detecting the stopped casting because it wasn't running 🫠.

I did however notice that after I stun a unit that is in the casting animation, it will immediately restart the casting animation after. Switching to NONE as the controller I'm guessing will fix this as well, but I'll have to see if I can salvage converting my map to use None. I did a quick test and it was not promising since I previously had Brown (neutrals on my map) and Pink (enemies) in Force 2, and setting the controller to NONE removes them from the forces altogether. (As well as the fact that I have triggers that check Player Controller Comparisons of User vs. Computer, but that can always be fixed...

Thanks again, I'll explore the options. Doesn't seem like we'll figure out why the channel repeats its command every 3-4 seconds when controlled by a Computer.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Thank you so much. I'll explore having NONE as the controller and see what negative impacts it has to my game. I never put much thought into not having Computer as the controller, although now that I think about it I don't think I am relying on the Computer to do anything at all since its a wave survival game with logic controlled through triggers....

As for the Casting implementation, it was complete user error on my part, the trigger I had to detect "stopped casting" was copy and pasted from a trigger that was not initially on, so it wasn't detecting the stopped casting because it wasn't running 🫠.

I did however notice that after I stun a unit that is in the casting animation, it will immediately restart the casting animation after. Switching to NONE as the controller I'm guessing will fix this as well, but I'll have to see if I can salvage converting my map to use None. I did a quick test and it was not promising since I previously had Brown (neutrals on my map) and Pink (enemies) in Force 2, and setting the controller to NONE removes them from the forces altogether. (As well as the fact that I have triggers that check Player Controller Comparisons of User vs. Computer, but that can always be fixed...

Thanks again, I'll explore the options. Doesn't seem like we'll figure out why the channel repeats its command every 3-4 seconds when controlled by a Computer.
You should try relying on the Channel ability. There's a good chance that this ability will play nicely since it shouldn't have any hardcoded AI logic. For example, Tranquility has requirements for when it should be used, I imagine something along the lines of "X nearby damaged allied units". If these requirements aren't met then it could screw with the AI, "Why am I casting Tranquility when we're all at full hp? I should stop".

Regarding the stun + repeat issue, you can solve this by either issuing a "stop" order or putting the ability on cooldown in response to the "Stops casting" event. Or maybe both. This way the ability will actually be interrupted and potentially unusable for a short while.
 
Last edited:
Level 3
Joined
Jan 17, 2024
Messages
11
Thanks, I thought I tried that on my test map and observed the same problem as the other channels I tested (Blizzard/Starfall/Tranq) but it could be to improperly using all the related fields (follow through, casting, duration, etc.).

I have things working now with my casting implementation. After detecting a stopped casting event I just issue a Stop command it and it resets the unit back to normal behavior instead of it retrying another cast.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Thanks, I thought I tried that on my test map and observed the same problem as the other channels I tested (Blizzard/Starfall/Tranq) but it could be to improperly using all the related fields (follow through, casting, duration, etc.).

I have things working now with my casting implementation. After detecting a stopped casting event I just issue a Stop command it and it resets the unit back to normal behavior instead of it retrying another cast.
Edit: Perhaps a special Base Order Id on Channel would work, dunno. Anyway, the casting time thingy should work fine.
 
Level 21
Joined
Dec 3, 2020
Messages
524
I'm pretty sure the Makruras stop channeling Starfall because they have no (enemy) targets the ability can hit.
Setting their player to Neutral in player settings is 1 way to do it but know that a Neutral player's units will only use auto-cast abilities on their own and the rest of the abilities have to be triggered.
 
Top