• 🏆 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!

Hotseat (Representation Trigger/s)

Status
Not open for further replies.
Level 20
Joined
Feb 24, 2009
Messages
2,999
Hi this is my first time asking for help on the hiveworkshop, I'm working on a hotseat wc3 map for me and a group of friends who often play hotseat games together and want to try something new.

I'm making progress... but i've reached a hurdle I can't jump.

See i'm trying to make it so that 1 unit has 10hp and represents 10men.

So if this unit with 10hp attacks a unit with 7hp then a battle will take place in a desginated zone between 10 and 7 men respectively.

I've nailed this.

What i can't seem to do no-matter what I try or how well i think i've done it, is get an accurate trigger to set the original 10hp model's health to the right the amount to represent units lost.

So i can't for e.g.

in a 10 on 7 battle (the 7 lose 2 men).

Make the 7hp representative unit go down to 5, accurately...

I've tried many things with variables (integer/real to integer convert to real) and all sorts of calculations and timings etc...

I've managed to get things close but not accurate enough.

So for e.g. a unit has been given 1hp more than its supposed to, or doesn't spawn the exact amount of men... I believe this is to do with it being inaccurate and ending up with a decimal HP reading.



***Looking back at that, I really hope someone understands what I mean and has any suggestions? :hohum:

Please it would mean a lot to me! Thanks in advance! :cute:
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
what about something like this:

  • Trig 1
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Footman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Dying unit)) Equal to Player 1 (Red)
        • Then - Actions
          • Set Life_of_peasent = (Life_of_peasent - 1.00)
          • Unit - Set life of Peasant 0000 <gen> to Life_of_peasent
        • Else - Actions
with other conditions and such... but it's somewhat the same...
Life_of_peasent = 10 default

*give us a example and we do the rest
 
Level 20
Joined
Feb 24, 2009
Messages
2,999
Hey thanks for replying so soon =)



Hashjie your idea might actually work! But instead of:

Unit-Type = Footmen, I would have to do
unit type = unit type of Life_Of_Peaseant (Unit Variable).

So that it would work in all cases with all units.

I'll try it now...

But as for the e.g. I have it here...

Sorry no idea how to make it appear in post without an upload to somewhere, so i stuck them here:

HTML:
http://torchwing.webs.com/apps/photos/album?albumid=5768569

Thanks Again :thumbs_up:
 
Level 18
Joined
Mar 13, 2009
Messages
1,411
To post a trigger you can just right click the trigger and do Copy as text. The paste it here and put
  • in front and
behind it.

Having a look at the trigger now :)

Edit: Ugh... well that shows how to post a trigger...

Put [*Trigger] in front of it
and [*/Trigger] behind it
Skip the *'s

Accidentally made my own text into a trigger D:

Checking: I am wondering about a little thing. If you unally the players won't the other 2 units (that represent a group) attack eachother too?

If you have the attacked unit and the attacking unit under a unit variable you could set their health to the number of units after the battle. Let me make a little trigger to show you :p
 
Level 20
Joined
Feb 24, 2009
Messages
2,999
LoL, thanks Billy - :D but on that note I seem to have solved it, I took Hashjie's basic idea and edited like so:

  • life set attacked unit
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to (Unit-type of ATTACKEDUNIT)
      • (Owner of (Dying unit)) Equal to (Owner of ATTACKEDUNIT)
    • Actions
      • Wait 1.00 seconds
      • Unit - Set life of ATTACKEDUNIT to (ATTACKEDUnitHealth - 1.00)
      • Set ATTACKEDUnitHealth = (Life of ATTACKEDUNIT)
Edit: Thanks alot all for your help =) Oh Its not essential but if anyone knows much about leaking (stumps me?) i'm guessing my triggers are very leaky? ? ?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Hey thanks for replying so soon =)



Hashjie your idea might actually work! But instead of:

Unit-Type = Footmen, I would have to do
unit type = unit type of Life_Of_Peaseant (Unit Variable).

So that it would work in all cases with all units.

I'll try it now...

But as for the e.g. I have it here...

Sorry no idea how to make it appear in post without an upload to somewhere, so i stuck them here:

HTML:
http://torchwing.webs.com/apps/photos/album?albumid=5768569

Thanks Again :thumbs_up:

first of all: it wasn't a unit but a real variable which I had set to 10 in a init trigger (or just in the variable editor)

I'm not sure if it works as a unit variable, I'm gonna check that now...

I'm also gonna figure a way out how to remove 1 life without setting the variable to 10, but attached to the life of the unit...
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
LoL, thanks Billy - :D but on that note I seem to have solved it, I took Hashjie's basic idea and edited like so:

  • life set attacked unit
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to (Unit-type of ATTACKEDUNIT)
      • (Owner of (Dying unit)) Equal to (Owner of ATTACKEDUNIT)
    • Actions
      • Wait 1.00 seconds
      • Unit - Set life of ATTACKEDUNIT to (ATTACKEDUnitHealth - 1.00)
      • Set ATTACKEDUnitHealth = (Life of ATTACKEDUNIT)
Edit: Thanks alot all for your help =) Oh Its not essential but if anyone knows much about leaking (stumps me?) i'm guessing my triggers are very leaky? ? ?

this is leakless...

except for the fact it has a wait (I hate waits even though I use them myself)
you can definitly use this :)

but does this solve your problem?
 
Level 20
Joined
Feb 24, 2009
Messages
2,999
If you have the attacked unit and the attacking unit under a unit variable you could set their health to the number of units after the battle. Let me make a little trigger to show you :p

Sure if you want, although thats the first thing I tried - I believe all my calculations and set-up was correct but Wc3/WE just didn't seem to want to calculate and apply it!

No idea why =/ for e.g. it wouldn't take 1 unit remaining as health off the unit.
But it would do a percentage calculation e.g. take *remaining units (1)*% off.

Which obviously killed a 10hp unit =(
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Sure if you want, although thats the first thing I tried - I believe all my calculations and set-up was correct but Wc3/WE just didn't seem to want to calculate and apply it!

No idea why =/ for e.g. it wouldn't take 1 unit remaining as health off the unit.
But it would do a percentage calculation e.g. take *remaining units (1)*% off.

Which obviously killed a 10hp unit =(

I'd love to try too :)
some obstacles are my favourites...
 
Level 20
Joined
Feb 24, 2009
Messages
2,999
this is leakless...

except for the fact it has a wait (I hate waits even though I use them myself)
you can definitly use this :)

but does this solve your problem?

It does =)

Only thing dodgy now is the "COMBAT" trigger, the really long one - is their anyway to simplify it? Or split it into many triggers? As its probably really leaky and is also a pain to go through if I were to ever need to change it in the future :sad:
 
Level 18
Joined
Mar 13, 2009
Messages
1,411
Was busy doing this so I might have missed some things :p

I made this trigger:
  • Unit Health
    • Events
      • Time - BattleTime expires
    • Conditions
    • Actions
      • -------- AttackPlayer and DefendPlayer are stored in the other trigger. --------
      • Set UnitGroupAttack = (Units in Battlefield <gen> owned by AttackingPlayer)
      • Set UnitGroupDefend = (Units in Battlefield <gen> owned by DefendingPlayer)
      • Set AttackNumber = (Number of units in UnitGroupAttack)
      • Set DefendNumber = (Number of units in UnitGroupDefend)
      • -------- AttackUnit and DefendUnit are stored in the other trigger. --------
      • Unit - Set life of ATTACKINGUNIT to (Real(AttackNumber))
      • Unit - Set life of ATTACKEDUNIT to (Real(DefendNumber))
      • Custom script: call DestroyGroup (udg_UnitGroupAttack)
      • Custom script: call DestroyGroup (udg_UnitGroupDefend)
About that combat trigger I had the idea that if you made the players unallied the 2 other units that are not in the battle would kill each other :p

Edit: removed those unit group leaks :p
 
Level 20
Joined
Feb 24, 2009
Messages
2,999
Was busy doing this so I might have missed some things :p

I made this trigger:
  • Unit Health
    • Events
      • Time - BattleTime expires
    • Conditions
    • Actions
      • -------- AttackPlayer and DefendPlayer are stored in the other trigger. --------
      • Set UnitGroupAttack = (Units in Battlefield <gen> owned by AttackingPlayer)
      • Set UnitGroupDefend = (Units in Battlefield <gen> owned by DefendingPlayer)
      • Set AttackNumber = (Number of units in UnitGroupAttack)
      • Set DefendNumber = (Number of units in UnitGroupDefend)
      • -------- AttackUnit and DefendUnit are stored in the other trigger. --------
      • Unit - Set life of AttackUnit to (Real(AttackNumber))
      • Unit - Set life of DefendUnit to (Real(DefendNumber))
About that combat trigger I had the idea that if you made the players unallied the 2 other units that are not in the battle would kill each other :p

That might work. . . but we do already have something that does also =)

Thanks Anyway =D

Oh yes i replied earlier the two units (representing ones) are paused, can't move/attack.


EDIT:*I might actually try this because it might allow for a smaller/simpler "COMBAT" trigger ;D
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
this also works:

  • footman life
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Peasant
    • Actions
      • Unit Group - Add (Dying unit) to Calculating_units
      • Set convert_real_to_int = ((Integer((Life of Footman 0005 <gen>))) - (Number of units in Calculating_units))
      • Unit - Set life of Footman 0005 <gen> to (Real(convert_real_to_int))
      • Unit Group - Remove (Dying unit) from Calculating_units
example map:
http://www.hiveworkshop.com/forums/pastebin.php?id=ekzidh

just select your footman and watch the peasents die :cool:
 
Level 18
Joined
Mar 13, 2009
Messages
1,411
Ye like I said I was kinda slow responding :p

Note: I edited my trigger a bit.
  • Unit Health
    • Events
      • Time - BattleTime expires
    • Conditions
    • Actions
      • -------- AttackPlayer and DefendPlayer are stored in the other trigger. --------
      • Set UnitGroupAttack = (Units in Battlefield <gen> owned by AttackingPlayer)
      • Set UnitGroupDefend = (Units in Battlefield <gen> owned by DefendingPlayer)
      • Set AttackNumber = (Number of units in UnitGroupAttack)
      • Set DefendNumber = (Number of units in UnitGroupDefend)
      • -------- ATTACKINGUNIT and ATTACKEDUNIT are stored in the other trigger. --------
      • Unit - Set life of ATTACKINGUNIT to (Real(AttackNumber))
      • Unit - Set life of ATTACKEDUNIT to (Real(DefendNumber))
      • Custom script: call DestroyGroup (udg_UnitGroupAttack)
      • Custom script: call DestroyGroup (udg_UnitGroupDefend)
I am kinda used to doing things like this this way now, because for my own map I had something that counted units and it had bugs by triggering it the other way.

@ Hashjie: I am not talking about Valley of Honor how it is now, but how it was a long time ago (the trigger with the problem doesn't exist anymore ;P ... the old Reinforcements spell if you wanted to know it)
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
@ Hashjie: I am not talking about Valley of Honor how it is now, but how it was a long time ago (the trigger with the problem doesn't exist anymore ;P)

wait, when did you talk about it 0.o??
 
Level 18
Joined
Mar 13, 2009
Messages
1,411
wait, when did you talk about it 0.o??

I am kinda used to doing things like this this way now, because for my own map I had something that counted units and it had bugs by triggering it the other way.

Was (I think) before you joined me in my map project so it isn't of any use now ;P
I made an old spell that counted units the Unit Dies > lower number way, but it got buggy with units that used timers.
 
Level 6
Joined
Sep 5, 2007
Messages
264
If you had the two side's units put into variables when the battle begins, then you could just use a periodic update... EG:

For this example I'll say that there is 10 vs 7 units, that the units are stored in variable arrays (units_1 & units_2), that there are integer variables that say how many are on each side (units_1_count & units_2_count), and that the trigger updates every 0.05 seconds... The attacking player is "Player 1" and the attacked player is "Player 2"
JASS:
local real life_1
local real life_1_max
local real life_2
local real life_2_max

local integer i = 0

local real hero_1_max_life = GetUnitState(udg_ATTACKINGUNIT, UNIT_STATE_MAX_LIFE)
local real hero_2_max_life = GetUnitState(udg_ATTACKEDUNIT, UNIT_STATE_MAX_LIFE)

local real percent_1
local real percent_2

loop
   exitwhen (i > udg_units_1_count)
   if (udg_units_1[i] != NULL) then
      set real life_1 = real life_1 + GetUnitState(udg_units_1[i], UNIT_STATE_LIFE)
      set real life_1_max = real life_1_max + GetUnitState(udg_units_1[i], UNIT_STATE_MAX_LIFE)
   endif
   set i = i + 1
endloop

set i = 0
loop
   exitwhen (i > udg_units_2_count)
   if (udg_units_2[i] != NULL) then
      set real life_2 = real life_2 + GetUnitState(udg_units_2[i], UNIT_STATE_LIFE)
      set real life_2_max = real life_2_max + GetUnitState(udg_units_2[i], UNIT_STATE_MAX_LIFE)
   endif
   set i = i + 1
endloop

So far we have found out the current health of each side, and the maximum health of each side... so we find a percentage (current divided by max) and multiply it by "Hero" unit's max-health:
JASS:
   if (life_1_max > 0) then     // This is to stop a possible division by zero
      set percent_1 = life_1 / life_1
   else
      set percent_1 = 0
   endif

   call SetUnitState(udg_ATTACKINGUNIT, UNIT_STATE_LIFE, percent_1 * hero_1_max_life)

   if (life_2_max > 0) then     // This is to stop a possible division by zero
      set percent_2 = life_2 / life_2
   else
      set percent_2 = 0
   endif

   call SetUnitState(udg_ATTACKEDUNIT, UNIT_STATE_LIFE, percent_2 * hero_2_max_life)

By doing it this way, you won't leak and it'll be a smooth health drop in the "Hero's" hp instead of a sudden drop. :thumbs_up:
 
Level 20
Joined
Feb 24, 2009
Messages
2,999
:nw: sorry, I don't understand JASS :confused:

I'll stick to what i've got - but rep for trying :razz:

Thanks!

And what I meant billy was if a representative unit attacks another representative unit then battle occurs.

What I plan to look into in the future is that units within "x" (x = a distance) get dragged into the battle as well!

So battles are bigger and unit placement/movement is worth paying attention to. (and to allow more than 2 player hotseat battles).

Otherwise one uber unit will always win 1on1 battles.

But perhaps that mindboggler is for another day! Unless anyone has any bright ideas on hand while the thread is still fresh :thumbs_up:
 
Status
Not open for further replies.
Top