HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

SetUnitState() question

01-11-2006, 12:38 PM#1
Daminon
I am familiar with this native but I wonder if it has no effect if the real vaule is greater than the unit's max vaule of the given state. Of course I know that you can't change the max vaule of a state by doing this but if I want to trigger heal on a unit and the differens between max life and current life is less than the heal vaule, wont it have any effect then? I have tested this and it seems to work until the heal vaule is "too high".

Example:
A unit has 100 max life and its current life is 60.
I set the life to currnet life + 25. This changes the current life to 85.
Then I do it again but it doesn't seem to have any effect. The unit doesn't get full life.

01-11-2006, 12:45 PM#2
iNfraNe
Well, if it doesnt work then just check if its current life + your life addition is higher than his maxlife and adjust what you want to add.
01-11-2006, 01:11 PM#3
Nantuko Husk
you cal use

SetWidgetLife ( widget whichWidget , real newlife )

newlife can be above his Max health. I dont belive it will cause any problems.

ALSO :
Collapse JASS:
call SetUnitState ( u , some unitstate , value  )


    constant unitstate UNIT_STATE_LIFE                          = ConvertUnitState(0)
    constant unitstate UNIT_STATE_MAX_LIFE                      = ConvertUnitState(1)
    constant unitstate UNIT_STATE_MANA                          = ConvertUnitState(2)
    constant unitstate UNIT_STATE_MAX_MANA                      = ConvertUnitState(3)
01-11-2006, 01:15 PM#4
iNfraNe
native SetUnitState takes unit whichUnit, unitstate whichUnitState, real newVal returns nothing

You did forget the newval there.. obviously.
01-11-2006, 01:19 PM#5
Nantuko Husk
Yes , I forgot that but I edited my post though
01-11-2006, 08:02 PM#6
Daminon
Quote:
Originally Posted by iNfraNe
Well, if it doesnt work then just check if its current life + your life addition is higher than his maxlife and adjust what you want to add.

Collapse JASS:
    //H = healing vaule
                
    if (H > GetUnitState(C, UNIT_STATE_MAX_LIFE) - GetUnitState(C, UNIT_STATE_LIFE)) then
        set H = GetUnitState(C, UNIT_STATE_MAX_LIFE) - GetUnitState(C, UNIT_STATE_LIFE)    
        //Now H is set to the missing amount of life.
    endif
     
    //And now H is added to the current life, which should resoult in full health.           
    call SetUnitState(C, UNIT_STATE_LIFE, GetUnitState(C, UNIT_STATE_LIFE) + H)    

    //But it doesn't. The unit still won't be healed.

Quote:
Originally Posted by Nantuko_Husk
you cal use

SetWidgetLife ( widget whichWidget , real newlife )

newlife can be above his Max health. I dont belive it will cause any problems.

Collapse JASS:
    call SetWidgetLife(C, GetUnitState(C, UNIT_STATE_LIFE) + H)


Neither did this work.
01-11-2006, 08:10 PM#7
Nantuko Husk
If I got it right :

when the units max live - current life gets below H then heal the unit ?

try this

Collapse JASS:
    if (H < GetUnitState(C, UNIT_STATE_MAX_LIFE) - GetUnitState(C, UNIT_STATE_LIFE)) then
        set H = GetUnitState(C, UNIT_STATE_MAX_LIFE) - GetUnitState(C, UNIT_STATE_LIFE)    
        //Now H is set to the missing amount of life.
    endif
01-11-2006, 08:31 PM#8
iNfraNe
thats just not what he wants. The first script should be working. Did you try filling it up with BJDebugMsg ? always a good way to find errors.
01-11-2006, 08:49 PM#9
ShadowDragon
Wouldn't it be simpler to just do:

Collapse JASS:
call SetUnitState(C, UNIT_STATE_LIFE, RMinBJ(GetUnitState(C, UNIT_STATE_LIFE) + H,GetUnitState(C,UNIT_STATE_MAX_LIFE))
01-11-2006, 09:18 PM#10
iNfraNe
which is the same thing but using a function that does the if's for you.
01-11-2006, 10:31 PM#11
Vexorian
perhaps It changed with last patch for some dumb reasons, but I swear that if you set anything's life to something freater than its max life it just made it the max life.

I will check it out, it could be something else

Edit:
Trigger:
test
Collapse Events
Player - Player 1 (Red) skips a cinematic sequence
Conditions
Collapse Actions
Unit - Set life of Mountain King 0000 <gen> to 10000.00

placed a mountain king with 125 hp and ~500 max life, and he got healed. The Set Life action of GUI calls SetUnitState, so it could be something else with your trigger, make messages display the name of the unit you are healing and the value of H
01-12-2006, 09:50 PM#12
Daminon
@Nantuko, the thing is just that a unit shall be healed. The differece calculation is just incase if it doesn't work when H is greater than current life. And if it is then H will be (max life) - (current life). And setting the units current life + H should resoult in full life.

Quote:
Originally Posted by Vexorian
perhaps
Edit:
Trigger:
test
Collapse Events
Player - Player 1 (Red) skips a cinematic sequence
Conditions
Collapse Actions
Unit - Set life of Mountain King 0000 <gen> to 10000.00

placed a mountain king with 125 hp and ~500 max life, and he got healed. The Set Life action of GUI calls SetUnitState, so it could be something else with your trigger, make messages display the name of the unit you are healing and the value of H
I tested this GUI thing and I got the same resoult as you, it worked. I don't really see why the unit's name
is needed so I skipped displaying that.


The abilitys' purpose is to convert damage to healing.
This time I used a unit that dealed 10 to 10 damage, the hero had 0 armor nad no health regeneration. So I know that the damage always is 10.
Collapse JASS:
//Da == damage dealed. Then H is calculated from Da. H will be used several times later.
set H = Da // + Da * HealFactor(Level) This is how the ability is supposed to work. But I let Da be unchanged so that the effect would be like evaison, no damage is taken and no heal.

call DisplayTextToForce(GetPlayersAll(),"H: " + R2S(H)) //The correct vaule of H was shown in the game (10).

                
call SetUnitState(C, UNIT_STATE_LIFE, GetUnitState(C, UNIT_STATE_LIFE) + H)

//I even tried this. But of course it didn't work.
call SetUnitState(C, UNIT_STATE_LIFE, GetUnitState(C, UNIT_STATE_LIFE) + GetEventDamage() * 2)

Another interesting thing I did was to se the heros life(925) to 916. The difference is 9 and remember that the unit dealed 10 damage. But instead of taking no damage, the life become 915 after the first attack but stayed the same after the next attacks like it should have done in the first attack. But as you see the unit dealed 1 damage but onlly on first attack.
I also tested to set the heroes to life to 925 - 19 = 906 and let the hero be attacked two times. The first time the healing was 906 + 10 = 916, BUT it become 915 instead. And then the second attack should resoult in full life, 925 since 915 + 10 = 925. Guess if it did, awnser: no. This thing is really strange.
01-13-2006, 12:48 AM#13
Vexorian
That's the source of all your problem, the unit is damaged event happens BEFORE the unit loses its health.

To make damage blocking I always end up using a 0 seconds timer and doing the healing when the timer expires, the problem is when the unit gets so many damage that it will die, for those cases I have to use an ability that gives +10000 hp then remove it after the healing

---
I said display the unit's name just in case. It could be that you were using a variable or something that was returning null or another unit
01-13-2006, 06:47 AM#14
Daminon
I see. Hm, I will test this 0.00 timer thing. Thanks everyone for helping.

Edit:
I tested and it works perfectly! But wouldn't TriggerSleepAction(0.0) work as good as a timer with 0.0 interval?
01-13-2006, 01:32 PM#15
Vexorian
TriggerSleepAction(0) waits like 0.25 and then it waits till all the other threads are sleeping. takes a while compared to a 0 seconds timer