wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-05-2009, 07:37 AM   #1
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default IsUnitInvulnerable

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.

Collapse 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
Attached Files
File Type: w3x IsUnitInvulnerable.w3x (14.5 KB, 37 views)

Last edited by DioD : 01-06-2009 at 04:20 AM.
DioD is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-05-2009, 03:08 PM   #2
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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

Last edited by Rising_Dusk : 01-05-2009 at 03:08 PM.
Rising_Dusk is offline   Reply With Quote
Old 01-05-2009, 03:26 PM   #3
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Rising_Dusk
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.
If the name is the only issue to make it approvable... then I've took the freedom of modify it.

Ups!! approved
moyack is offline   Reply With Quote
Old 01-05-2009, 04:02 PM   #4
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

I will update naming and demomap as soon as fix some wierd problem with logical part.

I cant understand what is wrong here:

Collapse 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:

Collapse 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
DioD is offline   Reply With Quote
Old 01-05-2009, 04:24 PM   #5
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 01-05-2009, 05:10 PM   #6
Zerzax
Zerzy
 
Zerzax's Avatar
 
Join Date: Mar 2008
Posts: 708

Submissions (2)

Zerzax is a jewel in the rough (192)Zerzax is a jewel in the rough (192)Zerzax is a jewel in the rough (192)

2008 Spell olympics - Fire - SilverSpell Making Session 13 WinnerSpell Making Session 12 Winner

Send a message via AIM to Zerzax Send a message via MSN to Zerzax
Default

How about using Get/SetWidgetLife DioD? Shorter, easier to code.
__________________
Some Quotes of Worthy Wisdom:

1. Die - D2 Barbarian
2. Time to Die - D2 Barbarian
3. Too Much Baggage! - D1 Warrior
4. I Gotta Pawn Some of This Stuff! - D1 Warrior
Zerzax is offline   Reply With Quote
Old 01-05-2009, 05:17 PM   #7
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

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"
DioD is offline   Reply With Quote
Old 01-06-2009, 04:22 AM   #8
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

Fixed and updated.
DioD is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 10:43 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services