• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] Upgrade / Replace Created unit trigger Help

Status
Not open for further replies.

ReaperDTC

R

ReaperDTC

Hi, newbie to forums here, I signed up a while back but never got around to posting, but i have found that just reading these was a massive help. At the moment though, I cant find anything like what I'm trying to do, so thought I ought to actually ask.

What I'm aiming for is the following:
1. Barracks trains Swordsmen normally.
2. Barracks also offers upgrade called 'Generals'
3. When 'Generals' is researched, there is a 25% chance of creating a General (Mounted Swordsman) instead of the Regular Swordsman.

Is this possible? So far i have:

The Replace unit trigger (To deal with actually replacing the unit when its created, i think this works fine. This trigger is set to 'Initially disabled')

  • Upgrade Swordsmen
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Swordsman
    • Actions
      • Set CaptainSpawn = (Random integer number between 1 and 4)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CaptainSpawn Equal to 4
        • Then - Actions
          • Unit - Remove (Trained unit) from the game
          • Unit - Create 1 Swordsman for Player 1 (Red) at (Position of (Trained unit)) facing Default building facing degrees
        • Else - Actions
          • Do nothing

and this, the trigger to activate the first trigger. (I think this is the problem, not even sure if that variable is the right thing, but I couldn't think of anything else that would work)

  • Research Upgrade Swordsmen
    • Events
      • Unit - A unit Finishes an upgrade
    • Conditions
      • (Researched tech-type) Equal to Generals
    • Actions
      • Trigger - Turn on Upgrade Swordsmen <gen>
The basic idea is that the Generals would be just like regular swordsmen, but faster and with only half the HP (200 instead of 400), but when killed they spawn a swordsmen (I.E Dismount.)
Just something I'm building as part of a Blood Elf race in a map I'm making.

Any Ideas would be appreciated =] Cheers in advance! =]
 
The problem is that you remove the unit and then try to create another at the removed unit's position. Because the unit is removed, the location call will fail. Try using Unit - replace unit instead.

Also get rid of the do nothing, and you don't need to set the chance into a variable.

Fix the leak:
https://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
 
Thanks for the replies folks.

I'm looking at the leak now. I've only ever make maps for myself in the past (thinking about releasing this one somewhere if its any good) and not really looked into the whole leak thing before, even though I've seen it talked about a lot.

On the subject of it not working, The unit spawning isn't the problem, if i set the trigger to initially on, it works. The problem I'm having is getting it to only work after the upgrade.

Any more ideas?
 
Wow, that simple... I'm an idiot =]
Yep, all working great now, Looks like this:

  • Research Upgrade Swordsmen
    • Events
      • Unit - A unit Finishes research
    • Conditions
      • (Researched tech-type) Equal to Generals
    • Actions
      • Trigger - Turn on Upgrade Swordsmen <gen>
and

  • Upgrade Swordsmen
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Swordsman
    • Actions
      • Set CaptainSpawn = (Random integer number between 1 and 4)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CaptainSpawn Equal to 4
        • Then - Actions
          • Set TempPoint = (Position of (Trained unit))
          • Unit - Remove (Trained unit) from the game
          • Unit - Create 1 Swordsman for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_TempPoint)
        • Else - Actions
Thanks a lot, hopefully I'll pick up on these things easier in the future =]
 
you pick up easily on leaks. and i already had my 3rd (stupid) map when i found out about those.

oh and something about Maker said that you don't have to put the chance on a variable, you can just do something like:

If - Conditions
(Random integer number between 1 and 4) Equal to 4
Then - Actions

instead of using

Set CaptainSpawn = (Random Integer between 1 and 4)
If - Conditions
(Captain Spawn) Equal To 4
Then - Actions

well, goodluck then :D
 
Status
Not open for further replies.
Back
Top