• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Help fixing a "replace unit" trigger

Status
Not open for further replies.
Level 1
Joined
Dec 4, 2019
Messages
7
So the basic idea is that i want HERO UNITS to be able to "upgrade" their class into a more advanced form, i.e. a militia unit into a footman. I used the base units and turned them into hero units, and wrote a script that stores their str/agi/int, sets level to 1, replaces the unit, then restores those stats to the new level 1 unit.

The idea is that choosing to level a unit up with its "base" form before upgrading to a higher class will result in a unit with more total stats (since they're retained at level 1), compared to a unit that upgraded at level 1. Each upgrade also has more hero skills to pick from, making them stronger and more versatile.

Here's the thing.. SOMETIMES it works perfectly. Gives me a new advanced unit, level 1, copied stats. More often, however, it seems to just replace the unit with an identical level 1 copy of the same unit with zero stats (default is zero for these units), but that knows one of its hero skills already.

There are far more units than listed here (a total of 4 base evolvable units, warrior/mage/priest/archer) but i cut most of them out to make it more readable here. Each unit type has an identical script.


  • UpgradeSkillCast
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Upgrade
    • Actions
      • Set UpgradingUnit = (Casting unit)
      • Set UpgradingHeroBaseStr = (Strength of UpgradingUnit (Exclude bonuses))
      • Set UpgradingHeroBaseInt = (Intelligence of UpgradingUnit (Exclude bonuses))
      • Set UpgradingHeroBaseAgi = (Agility of UpgradingUnit (Exclude bonuses))
      • Hero - Set UpgradingUnit Hero-level to 1, Hide level-up graphics
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Militia
        • Then - Actions
          • Unit - Replace UpgradingUnit with a Footman using The new unit's max life and mana
          • Set UpgradingUnit = (Last replaced unit)
          • Game - Display to (All players) the text: Footman
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Footman
        • Then - Actions
          • Unit - Replace UpgradingUnit with a Captain using The new unit's max life and mana
          • Set UpgradingUnit = (Last replaced unit)
          • Game - Display to (All players) the text: Captain
        • Else - Actions
          • Do nothing
      • Hero - Modify Strength of UpgradingUnit: Set to UpgradingHeroBaseStr
      • Hero - Modify Agility of UpgradingUnit: Set to UpgradingHeroBaseAgi
      • Hero - Modify Intelligence of UpgradingUnit: Set to UpgradingHeroBaseInt

Any suggestions? Feel free to mock my insanity or give me a "why don't you just..." instead. Since hero units dont have an "upgrades to" option in the editor like buildings do, i had to resort to this.

Thanks in advance!
 
Level 1
Joined
Dec 4, 2019
Messages
7
That would only meet a single part of the goal. Using that method, the level would not reset to 1 and it would not unlearn skills. I havent tried, but i assume the base stats wouldnt carry over either.

I may be able to use that as a base for an entirely differently written trigger though... if nobody has better advice or other fixes I'll try rewriting it using that base later when I'm home.
 
Level 9
Joined
Jul 30, 2018
Messages
445
Maybe use the event "A unit begins casting an ability" and then store the stats to variables and then make another trigger with the event "A unit finishes casting an ability" and the set the level to 1 and apply the stats? Could be a bit messy and for MUI you might need unit indexing just in case, but those are good to have anyway.
 
Level 1
Joined
Dec 4, 2019
Messages
7
@Sabe that's not a bad idea. I dislike using two triggers to accomplish a single task, but splitting it into two might be the way to go just to get it to WORK.

I'm not SUPER worried about it being MUI at the moment, since i would likely be the only person to play it (for a long time yet) and would know better than to cast it with two units, but i can easily tweak it to fix that if i make it public down the road.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
I see. I assumed you wanted to keep those things as most developers do. I believe Chaos morphing a hero into another hero automatically ‘consumes’ the first’s base stats so that could work, but I believe that also includes bonuses. In that case straight replacing the unit with a trigger is your best option.

Two notes:
  • Finishes casting only occurs after a spell is fully cast or a channel fully completes (not stopped prematurely). Usually one uses ”starts the effect of” for spell cast events, though if the upgrade is a channeled spell then what you’ve done is correct.
  • Try to use “Triggering Unit” whenever possible instead of the more specific things like “casting unit”. Some of them do not work or are wonky after waits:Event Response Myths
As for why it occasionally doesn’t work: I don’t know. There’s no pattern to when it does or does not function properly? Not when a particular type upgrades? Since there are many types that upgrade into other types, I suggest doing something like this:

  • Set UpgradeCount = (UpgradeCount + 1)
  • Set UpgradeFrom[UpgradeCount] = Militia
  • Set UpgradeTo[UpgradeCount] = Footman
  • Set UpgradeCount = (UpgradeCount + 1)
  • Set UpgradeFrom[UpgradeCount] = Footman
  • Set UpgradeTo[UpgradeCount] = Captain
  • // etc.
  • Set UpgradeUnit = (Triggering Unit)
  • Set UpgradeType = (Unit type of UpgradeUnit)
  • For each (Integer A) from 1 to UpgradeCount do (Actions)
    • Loop - Actions
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • UpgradeType equal to UpgradeFrom[(Integer A)]
        • Then - Actions
          • Set UpgradeType = UpgradeTo[(Integer A)]
          • Custom script: exitwhen true //leaves the loop early
        • Else - Actions
  • Hero - Set level of UpgradeUnit to 1
  • Unit - Replace UpgradeUnit with a UpgradeType using the new unit’s max life and mana
  • Set UpgradeUnit = (Last replaced unit)
 
Level 1
Joined
Dec 4, 2019
Messages
7
@Pyrogasm it seems to work best at level 1, almost perfectly reliable. Once the hero-unit is level 3 or so and has, for example, bash and evasion, it almost always fails. I've been using "channel" as the base ability since it's easy to customize the spell, if that has anything to do with the trouble.

As far as retaining the stats, i basically want the new unit to have identical str/agi/int as the pre-evolution. So say all three forms have a base of zero strength and gain two per level, if someone levels a militia to level 5 first then upgrading will have 10 strength at level 1 as the new unit. If they choose to go straight to the upgrade at level 1 instead, their advanced unit will have lower potential than one they invested in at lower tiers. If "bonuses" means books but NOT equipped items, then i DO want bonuses to carry over as well.

Also i thought "triggering unit" was more leaky than specifying so i don't use it. If that's not true then that'll make building this stuff a lot easier XD
 
Status
Not open for further replies.
Top