• 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.

easier/better/smarter way to do this?

Status
Not open for further replies.
Level 3
Joined
Feb 6, 2009
Messages
50
Is there an easier way to cause a unit to replace another unit when at a certain percent of health?

instead of
a unit is attacked

if attacked unit = unit type x

if attacked unit health = to y%
than replace unit x with unit z using new units max.
else do nothing

I am going to have at least 3 unit x's on my map, they will be replaced 3 times
There will be another unit type using the same trigger set up, and it will be replaced 4 times.

is there a better way to do this? I imagine using this form will cause problems (especially with it constantly checking to see if trigger becomes true ever due to many other attacks going on)

If you know a Jass trick that works better please fill free to tell, I just started learning the Jass system yesterday (which it reminds me a little of C++...I think thats the one I used to use XD lol, I have used three of four of them , and its been a hell of a long time since I have used any of them)
 
Level 3
Joined
Feb 6, 2009
Messages
50
hmmm...I suppose I could look into another method on my own, I have an idea, I doubt it will work, it'll require more work than that simple method, and is less likely to succeed, but I will try it anyways! Hurray for variables!
 
Level 3
Joined
Feb 6, 2009
Messages
50
Im not sure why I was going to do an if than else function...must have been tired...but anyways what I have done so far is
a unit is attacked

attacked unit = unit x
health of attacked unit = maxhp/2

replace unit with unit y


Really the only thing I don't like is the fact that it checks everytime a unit is attacked. It may not run, but Ill have like 12 or more different triggers checking at once, because I have multiple functions like this, I really just wasn't sure if this would affect the game or not, like slow it down or cause some kind of problems.
 
You could use a Damage Detection system, but the way you wrote it is the simplest way.
You can combine multiple triggers with the same events by using If\Then\Elses.
eg.
  • Example Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Unit - Hide (Attacking unit)
and
  • Replace
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Percentage life of (Attacked unit)) Less than 30.00
    • Actions
      • Unit - Replace (Attacked unit) with a Footman using The old unit's relative life and mana
Can be combined into:
  • Replace
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Unit - Hide (Attacking unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of (Attacked unit)) Less than 30.00
        • Then - Actions
          • Unit - Replace (Attacked unit) with a Footman using The old unit's relative life and mana
        • Else - Actions
Oh, and an easier/better/smarter way to display triggers is using [ TRIGGER ] tags. [ /TRIGGER ](remove spaces next to the brackets and apply around your triggers, which you can use copy as text from the WE).
 
Level 13
Joined
May 11, 2008
Messages
1,198
if u have a finite # of units...you mentioned 3 and then 4 for something similiar...you should tag the units. like..create the units, then make them be global variables.

instead of is a unit attacked...i think you can do if specific unit is damaged...and those variables...the units tagged will be the ones...i think that's much better.

feel free to look in my map...it's pretty much all jass. there should be some neat tricks for you to pick up in there. if you have any questions, feel free to pm me.
 
Level 3
Joined
Feb 6, 2009
Messages
50
well The finite number of units is this; only two start on the map, the last sets are spawned and either added to variables for other things or are affected by the whole unit type of attacked unit is equal to unit x.


I guess I will just leave it as is, thank you all for the help!
Ive noticed most of my questions are easily answered if I would only pay attention...Ive nearly asked three other questions today that I answered on my own XD
 
Level 13
Joined
May 11, 2008
Messages
1,198
hah, yeah i remember when i was first starting i had questions that i would sometimes ask and then figure out on my own anyway...

let me give you a bit of advice what helped me the most:
i really recommend as you are a beginner to test other people's maps and then check their map code. it's very instructive.
 
Level 3
Joined
Feb 6, 2009
Messages
50
Only a begginer in jass really...i already check other peoples codes...its just been a few years since I have maped so I am a little (very) rusty.
 
Status
Not open for further replies.
Top