1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Help fixing a "replace unit" trigger

Discussion in 'Triggers & Scripts' started by Shadowwake19, Dec 4, 2019 at 1:58 AM.

  1. Shadowwake19

    Shadowwake19

    Joined:
    Wednesday
    Messages:
    6
    Resources:
    0
    Resources:
    0
    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!
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,151
    Resources:
    1
    Spells:
    1
    Resources:
    1
  3. Shadowwake19

    Shadowwake19

    Joined:
    Wednesday
    Messages:
    6
    Resources:
    0
    Resources:
    0
    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.
     
  4. Sabe

    Sabe

    Joined:
    Jul 30, 2018
    Messages:
    282
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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.
     
  5. Shadowwake19

    Shadowwake19

    Joined:
    Wednesday
    Messages:
    6
    Resources:
    0
    Resources:
    0
    @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.
     
  6. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,151
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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)
     
  7. Shadowwake19

    Shadowwake19

    Joined:
    Wednesday
    Messages:
    6
    Resources:
    0
    Resources:
    0
    @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