• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Upgrade / Replace Created unit trigger Help

Status
Not open for further replies.
Level 1
Joined
May 7, 2011
Messages
3
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! =]
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
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:
http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
 
Level 1
Joined
May 7, 2011
Messages
3
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?
 
Level 1
Joined
May 7, 2011
Messages
3
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 =]
 
Level 8
Joined
Jan 8, 2010
Messages
493
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.
Top