| 01-05-2009, 06:37 AM | #1 |
v1.1 This function is alternative to: http://www.wc3campaigns.net/showthread.php?t=103889 This function will detect any kind of invulnerability on unit. v1.1: Fixed function and locals naming. Fixed minor logical errors. Updated demomap. JASS:function IsUnitInvulnerable takes unit Unit returns boolean local real Health_Current = GetWidgetLife(Unit) local real Mana_Current = GetUnitState(Unit,UNIT_STATE_MANA) local boolean Check_Health call SetWidgetLife(Unit,Health_Current + 0.001) if Health_Current != GetWidgetLife(Unit) then call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null) set Check_Health = (GetWidgetLife(Unit) == Health_Current + 0.001) else call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null) set Check_Health = (GetWidgetLife(Unit) == Health_Current) call SetWidgetLife(Unit,Health_Current) endif if Check_Health then return not (GetUnitState(Unit,UNIT_STATE_MANA) != Mana_Current) endif return Check_Health endfunction |
| 01-05-2009, 02:08 PM | #2 |
I don't like your naming convention. I am not going to accept a function called "SingleFunc_CheckInvulnerable." Also, I see that this one accounts for the Mana Shield case, making it bulletproof. Just rename it to "IsUnitInvulnerable" since that is the naming convention; people will not use both your function and his library in the same map. Once that is done I'll approve this. |
| 01-05-2009, 02:26 PM | #3 | |
Quote:
Ups!! approved |
| 01-05-2009, 03:02 PM | #4 |
I will update naming and demomap as soon as fix some wierd problem with logical part. I cant understand what is wrong here: JASS:function B2Sx takes boolean Boolean returns nothing if Boolean then call BJDebugMsg("|cffccffccTrue|r") else call BJDebugMsg("|cffffccccFalse|r") endif endfunction call B2Sx(not (0.999 != 1.000)) call B2Sx((0.999 == 1.000)) Return is: FALSE TRUE Anyone can tell me what is wrong? Complete code with debug strings: JASS:function IsUnitInvulnerable takes unit Unit returns boolean local real Health_Current = GetUnitState(Unit,UNIT_STATE_LIFE) local real Mana_Current = GetUnitState(Unit,UNIT_STATE_MANA) local boolean Check_Health = false if Health_Current == GetUnitState(Unit,UNIT_STATE_MAX_LIFE) then call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null) set Check_Health = (GetUnitState(Unit,UNIT_STATE_LIFE) == Health_Current) call SetUnitState(Unit,UNIT_STATE_LIFE,Health_Current) else call SetUnitState(Unit,UNIT_STATE_LIFE,Health_Current + 0.001) call UnitDamageTarget(Unit,Unit,0.001,false,true,null,null,null) set Check_Health = (GetUnitState(Unit,UNIT_STATE_LIFE) == Health_Current + 0.001) endif call B2Sx(not (GetUnitState(Unit,UNIT_STATE_MANA) != Mana_Current)) call B2Sx((GetUnitState(Unit,UNIT_STATE_MANA) == Mana_Current)) call B2Sx(not (0.999 != 1.000)) call B2Sx((0.999 == 1.000)) if Check_Health then return not (GetUnitState(Unit,UNIT_STATE_MANA) != Mana_Current) endif return Check_Health endfunction |
| 01-05-2009, 03:24 PM | #5 |
It must be an internal issue with the way WC3 handles real values. It's not very robust or sturdy is what it boils down to. Your code appears to work in all specified cases in the testmap I have, though. |
| 01-05-2009, 04:10 PM | #6 |
How about using Get/SetWidgetLife DioD? Shorter, easier to code. |
| 01-05-2009, 04:17 PM | #7 |
There is some fun with WidgetLife and units with negative regeneration. I will check again and optimize code as much as possible after got this "real rounding bug" |
| 01-06-2009, 03:22 AM | #8 |
Fixed and updated. |
