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

[JASS] UnitDamageTarget ????

Status
Not open for further replies.
Level 7
Joined
Mar 22, 2010
Messages
228
JASS:
native UnitDamageTarget takes unit whichUnit, widget target, real amount, boolean attack, boolean ranged, attacktype attackType, damagetype damageType, weapontype weaponType returns boolean

i wonder what those types are or where can i find them... :vw_wtf:

also the boolean attack and boolean ranged...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,208
This explains some of it.

The booleans are AI response related some say. I however think they are not implimented correctly and some values will cause the damage to fail. Use true for attack response and false for ranged as those are garunteed to work.

Below is a list of predifined constants that go with it. They are basically variables already initialized to a value returned from the type difiner native.
ATTACK_TYPE_CHAOS
ATTACK_TYPE_HERO
ATTACK_TYPE_MAGIC
ATTACK_TYPE_MELEE
ATTACK_TYPE_NORMAL
ATTACK_TYPE_PIERCE
ATTACK_TYPE_SIEGE
DAMAGE_TYPE_ACID
DAMAGE_TYPE_COLD
DAMAGE_TYPE_DEATH
DAMAGE_TYPE_DEFENSIVE
DAMAGE_TYPE_DEMOLITION
DAMAGE_TYPE_DISEASE
DAMAGE_TYPE_DIVINE
DAMAGE_TYPE_ENHANCED
DAMAGE_TYPE_FIRE
DAMAGE_TYPE_FORCE
DAMAGE_TYPE_LIGHTNING
DAMAGE_TYPE_MAGIC
DAMAGE_TYPE_MIND
DAMAGE_TYPE_NORMAL
DAMAGE_TYPE_PLANT
DAMAGE_TYPE_POISON
DAMAGE_TYPE_SHADOW_STRIKE
DAMAGE_TYPE_SLOW_POISON
DAMAGE_TYPE_SONIC
DAMAGE_TYPE_SPIRIT_LINK
DAMAGE_TYPE_UNIVERSAL
DAMAGE_TYPE_UNKNOWN
WEAPON_TYPE_AXE_MEDIUM_CHOP
WEAPON_TYPE_CLAW_HEAVY_SLICE
WEAPON_TYPE_CLAW_LIGHT_SLICE
WEAPON_TYPE_CLAW_MEDIUM_SLICE
WEAPON_TYPE_METAL_HEAVY_BASH
WEAPON_TYPE_METAL_HEAVY_CHOP
WEAPON_TYPE_METAL_HEAVY_SLICE
WEAPON_TYPE_METAL_HEAVY_STAB
WEAPON_TYPE_METAL_LIGHT_CHOP
WEAPON_TYPE_METAL_LIGHT_SLICE
WEAPON_TYPE_METAL_MEDIUM_BASH
WEAPON_TYPE_METAL_MEDIUM_CHOP
WEAPON_TYPE_METAL_MEDIUM_SLICE
WEAPON_TYPE_METAL_MEDIUM_STAB
WEAPON_TYPE_ROCK_HEAVY_BASH
WEAPON_TYPE_WHOKNOWS
WEAPON_TYPE_WOOD_HEAVY_BASH
WEAPON_TYPE_WOOD_HEAVY_SLICE
WEAPON_TYPE_WOOD_LIGHT_BASH
WEAPON_TYPE_WOOD_LIGHT_SLICE
WEAPON_TYPE_WOOD_LIGHT_STAB
WEAPON_TYPE_WOOD_MEDIUM_BASH
WEAPON_TYPE_WOOD_MEDIUM_SLICE
WEAPON_TYPE_WOOD_MEDIUM_STAB

Weapon type is used for sound effects (as should be obvious from the names of some of them matching weapon sounds).
 
Level 7
Joined
Mar 22, 2010
Messages
228
oh so that "whoknows" thinggy there makes a sound? oh ok.

so should it be NULL or null or WEAPON_TYPE_NULL?

EDIT: id like to show you my spell trigger so you can check it..please

JASS:
//TESH.scrollpos=33
//TESH.alwaysfold=0
function Trig_Lightning_Strike_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local unit d
    local integer rank = GetUnitAbilityLevel( caster, 'Cal0' )
    local integer level = GetUnitLevel( caster )
    local integer leveltarget = GetUnitLevel(target)
    local integer agi = GetHeroAgi(target, true)
    local integer str = GetHeroStr(caster, true)
    local integer int = GetHeroInt(target, true)
    local integer int_caster = GetHeroInt(caster, true)
    local integer i = 1
    local real roll
    local real dodge = ((agi / ( leveltarget * 100 )) * 100)
    local real crit = ((str / ( level * 100 )) * 100)
    local real resistance = ((int / ( leveltarget * 125 )) + 1)
    local real chance = (20 + (10 * rank))
    local real damage_min = (((int_caster + (50 * rank))) * ((rank - 0.50)))
    local real damage_max = (((int_caster + (50 * rank))) * ((rank + 0.50)))
    local real damage
    local texttag t_d
    local texttag t_da
    
    if target != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif
    
    set damage = (GetRandomReal(damage_min, damage_max) / resistance)
    
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Dodge: " + R2S(dodge))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Min: " + R2S(damage_min))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Max: " + R2S(damage_max))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Damage: " + R2S(damage))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Crit Chance: " + R2S(crit))
// i am so freaky wondering why crit chance says 0.0000 tho is should be 15(look at     local real crit = ((str / ( level * 100 )) * 100) 
// my hero's str is 15 so that should explain everything
    
    //DODGE -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    set roll = GetRandomReal(0.00, 100.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Dodge Roll: " + R2S(roll))
    if roll <= dodge then
        set t_d = CreateTextTag()
        call SetTextTagFadepoint(t_d, 3)
        call SetTextTagLifespan(t_d, 4)
        call SetTextTagPermanent(t_d, false)
        call SetTextTagVelocity(t_d, 64, 90)
        call SetTextTagPosUnit(t_d, target, 0)
        call SetTextTagText(t_d, "Dodge!", 15)        
        return
//this stupid texttag dont work :(
    endif
    
    //CHANCE
    set roll = GetRandomReal(0.00, 100.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Stun Roll: " + R2S(roll))
    if roll <= chance then
        set d = CreateUnit(GetOwningPlayer(caster), 'Cdu0', GetUnitX(target), GetUnitY(target), 0.00)
        call UnitApplyTimedLife(d, 'BTLF', 1.00)
        call UnitAddAbility(d, 'Cds0')
        call SetUnitAbilityLevel(d, 'Cds0', rank)
        call IssueTargetOrder(d, "thunderbolt", target)
    endif
    
    //Critical Chance
    set roll = GetRandomReal(0.00, 0.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Crit Roll: " + R2S(roll))
    if roll <= crit then
        set i = 2
    endif
    
    //Damage
    call UnitDamageTarget(caster, target, (damage*i), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    set t_da = CreateTextTag()
    call SetTextTagFadepoint(t_da, 3)
    call SetTextTagLifespan(t_da, 4)
    call SetTextTagPermanent(t_da, false)
    call SetTextTagVelocity(t_da, 64, 90)
    call SetTextTagPosUnit(t_da, target, 0)
    call SetTextTagText(t_da, ("-") + (R2S( damage * i )), 15.00)
endfunction

function Trig_Lightning_Strike_Condtions takes nothing returns boolean
    return GetSpellAbilityId() == 'Cal0' and GetUnitTypeId(GetSpellAbilityUnit()) == 'Chd0'
endfunction 

//===========================================================================
function InitTrig_Lightning_Strike takes nothing returns nothing
    set gg_trg_Lightning_Strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Lightning_Strike, Condition(function Trig_Lightning_Strike_Condtions) )
    call TriggerAddAction( gg_trg_Lightning_Strike, function Trig_Lightning_Strike_Actions )
endfunction
 
Level 7
Joined
Mar 22, 2010
Messages
228
oh so that "whoknows" thinggy there makes a sound? oh ok.

so should it be NULL or null or WEAPON_TYPE_NULL?

EDIT: id like to show you my spell trigger so you can check it..please

JASS:
//TESH.scrollpos=33
//TESH.alwaysfold=0
function Trig_Lightning_Strike_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local unit d
    local integer rank = GetUnitAbilityLevel( caster, 'Cal0' )
    local integer level = GetUnitLevel( caster )
    local integer leveltarget = GetUnitLevel(target)
    local integer agi = GetHeroAgi(target, true)
    local integer str = GetHeroStr(caster, true)
    local integer int = GetHeroInt(target, true)
    local integer int_caster = GetHeroInt(caster, true)
    local integer i = 1
    local real roll
    local real dodge = ((agi / ( leveltarget * 100 )) * 100)
    local real crit = ((str / ( level * 100 )) * 100)
    local real resistance = ((int / ( leveltarget * 125 )) + 1)
    local real chance = (20 + (10 * rank))
    local real damage_min = (((int_caster + (50 * rank))) * ((rank - 0.50)))
    local real damage_max = (((int_caster + (50 * rank))) * ((rank + 0.50)))
    local real damage
    local texttag t_d
    local texttag t_da
    
    if target != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif
    
    set damage = (GetRandomReal(damage_min, damage_max) / resistance)
    
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Dodge: " + R2S(dodge))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Min: " + R2S(damage_min))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Max: " + R2S(damage_max))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Damage: " + R2S(damage))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Crit Chance: " + R2S(crit))
// i am so freaky wondering why crit chance says 0.0000 tho is should be 15(look at     local real crit = ((str / ( level * 100 )) * 100) 
// my hero's str is 15 so that should explain everything
    
    //DODGE -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    set roll = GetRandomReal(0.00, 100.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Dodge Roll: " + R2S(roll))
    if roll <= dodge then
        set t_d = CreateTextTag()
        call SetTextTagFadepoint(t_d, 3)
        call SetTextTagLifespan(t_d, 4)
        call SetTextTagPermanent(t_d, false)
        call SetTextTagVelocity(t_d, 64, 90)
        call SetTextTagPosUnit(t_d, target, 0)
        call SetTextTagText(t_d, "Dodge!", 15)        
        return
//this stupid texttag dont work :(
    endif
    
    //CHANCE
    set roll = GetRandomReal(0.00, 100.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Stun Roll: " + R2S(roll))
    if roll <= chance then
        set d = CreateUnit(GetOwningPlayer(caster), 'Cdu0', GetUnitX(target), GetUnitY(target), 0.00)
        call UnitApplyTimedLife(d, 'BTLF', 1.00)
        call UnitAddAbility(d, 'Cds0')
        call SetUnitAbilityLevel(d, 'Cds0', rank)
        call IssueTargetOrder(d, "thunderbolt", target)
    endif
    
    //Critical Chance
    set roll = GetRandomReal(0.00, 0.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Crit Roll: " + R2S(roll))
    if roll <= crit then
        set i = 2
    endif
    
    //Damage
    call UnitDamageTarget(caster, target, (damage*i), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    set t_da = CreateTextTag()
    call SetTextTagFadepoint(t_da, 3)
    call SetTextTagLifespan(t_da, 4)
    call SetTextTagPermanent(t_da, false)
    call SetTextTagVelocity(t_da, 64, 90)
    call SetTextTagPosUnit(t_da, target, 0)
    call SetTextTagText(t_da, ("-") + (R2S( damage * i )), 15.00)
endfunction

function Trig_Lightning_Strike_Condtions takes nothing returns boolean
    return GetSpellAbilityId() == 'Cal0' and GetUnitTypeId(GetSpellAbilityUnit()) == 'Chd0'
endfunction 

//===========================================================================
function InitTrig_Lightning_Strike takes nothing returns nothing
    set gg_trg_Lightning_Strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Lightning_Strike, Condition(function Trig_Lightning_Strike_Condtions) )
    call TriggerAddAction( gg_trg_Lightning_Strike, function Trig_Lightning_Strike_Actions )
endfunction

what am i gonna do with my trigger?
the trigger is a spell and has a 30% chance to stun a unit. but its not working..
 
first, use null instead of WTWK

2nd, use GetTriggerUnit() rather than GetSpellAbilityUnit()

3rd, please tell us what's not working... does it deal the damage, show the texttag? etc...

I suggest that you try to add debug messages first to see up to which line of the code is run...

this won't work:
JASS:
if target != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif
/*
target is a unit while UNIT_TYPE_HERO is a UNIT_TYPE so it will return a type mismatch
 it should be
*/

if IsUnitType(target) != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif

/*

 I also suggest setting d to null at the top, because sometimes uninitialized variables cause errors...
*/
 
Level 7
Joined
Mar 22, 2010
Messages
228
it always make "crit" as 0.000 tho it has its own calculation

those texttags dont work

those are the errors i have seen so far...
 
for the texttags, maybe you also need to initialize them at the same line you created those variables...

I think str / (level*100) is always almost zero... or at least close to zero... how much strength does the unit has???

and try replacing GetSpellAbilityUnit() with GetTriggerUnit()


btw, the line I stated at the above post didn't give you a compile error?
 
Level 7
Joined
Mar 22, 2010
Messages
228
first, use null instead of WTWK

2nd, use GetTriggerUnit() rather than GetSpellAbilityUnit()

3rd, please tell us what's not working... does it deal the damage, show the texttag? etc...

I suggest that you try to add debug messages first to see up to which line of the code is run...

this won't work:
JASS:
if target != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif
/*
target is a unit while UNIT_TYPE_HERO is a UNIT_TYPE so it will return a type mismatch
 it should be
*/

if IsUnitType(target) != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif

/*

 I also suggest setting d to null at the top, because sometimes uninitialized variables cause errors...
*/

without this
JASS:
IsUnitType
the if still works..
it gives 75 dodge to non-hero units..

and for the crit one, my hero's STR is 15.. try calculate it

about the texttag, how am i gonna do that?
 

Attachments

  • Dawn of PVP.w3x
    99.9 KB · Views: 110
Level 7
Joined
Mar 22, 2010
Messages
228
JASS:
//TESH.scrollpos=33
//TESH.alwaysfold=0
function Trig_Lightning_Strike_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local unit d = null
    local integer rank = GetUnitAbilityLevel( caster, 'Cal0' )
    local integer level = GetUnitLevel( caster )
    local integer leveltarget = GetUnitLevel(target)
    local integer agi = GetHeroAgi(target, true)
    local integer str = GetHeroStr(caster, true)
    local integer int = GetHeroInt(target, true)
    local integer int_caster = GetHeroInt(caster, true)
    local integer i = 1
    local real roll
    local real dodge = ((agi / ( leveltarget * 100 )) * 100)
    local real crit = ((I2R(str) / ( I2R(level) * 100 )) * 100)
    local real resistance = ((int / ( leveltarget * 125 )) + 1)
    local real chance = (20 + (10 * rank))
    local real damage_min = (((int_caster + (50 * rank))) * ((rank - 0.50)))
    local real damage_max = (((int_caster + (50 * rank))) * ((rank + 0.50)))
    local real damage
    local texttag t_d = null
    local texttag t_da = null
    
    if IsUnitType(target) != UNIT_TYPE_HERO then
        set dodge = 75
        set resistance = 1.15
    endif
    
    set damage = (GetRandomReal(damage_min, damage_max) / resistance)
    
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Dodge: " + R2S(dodge))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Min: " + R2S(damage_min))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Max: " + R2S(damage_max))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Damage: " + R2S(damage))
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Crit Chance: " + R2S(crit))
// i am so freaky wondering why crit chance says 0.0000 tho is should be 15(look at     local real crit = ((str / ( level * 100 )) * 100)
// my hero's str is 15 so that should explain everything
    
    //DODGE -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    set roll = GetRandomReal(0.00, 100.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Dodge Roll: " + R2S(roll))
    if roll <= dodge then
        set t_d = CreateTextTag()
        call SetTextTagFadepoint(t_d, 3)
        call SetTextTagLifespan(t_d, 4)
        call SetTextTagPermanent(t_d, false)
        call SetTextTagVelocity(t_d, 64, 90)
        call SetTextTagPosUnit(t_d, target, 0)
        call SetTextTagText(t_d, "Dodge!", 15)        
        return
//this stupid texttag dont work :(
    endif
    
    //CHANCE
    set roll = GetRandomReal(0.00, 100.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Stun Roll: " + R2S(roll))
    if roll <= chance then
        set d = CreateUnit(GetOwningPlayer(caster), 'Cdu0', GetUnitX(target), GetUnitY(target), 0.00)
        call UnitApplyTimedLife(d, 'BTLF', 1.00)
        call UnitAddAbility(d, 'Cds0')
        call SetUnitAbilityLevel(d, 'Cds0', rank)
        call IssueTargetOrder(d, "thunderbolt", target)
    endif
    
    //Critical Chance
    set roll = GetRandomReal(0.00, 0.00)
    call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "Crit Roll: " + R2S(roll))
    if roll <= crit then
        set i = 2
    endif
    
    //Damage
    call UnitDamageTarget(caster, target, (damage*i), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    set t_da = CreateTextTag()
    call SetTextTagFadepoint(t_da, 3)
    call SetTextTagLifespan(t_da, 4)
    call SetTextTagPermanent(t_da, false)
    call SetTextTagVelocity(t_da, 64, 90)
    call SetTextTagPosUnit(t_da, target, 0)
    call SetTextTagText(t_da, ("-") + (R2S( damage * i )), 15.00)
endfunction

function Trig_Lightning_Strike_Condtions takes nothing returns boolean
    return GetSpellAbilityId() == 'Cal0' and GetUnitTypeId(GetSpellAbilityUnit()) == 'Chd0'
endfunction 

//===========================================================================
function InitTrig_Lightning_Strike takes nothing returns nothing
    set gg_trg_Lightning_Strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Lightning_Strike, Condition(function Trig_Lightning_Strike_Condtions) )
    call TriggerAddAction( gg_trg_Lightning_Strike, function Trig_Lightning_Strike_Actions )
endfunction

i applied all changes to my spell trigger...
i'll check if it will work..
 
Level 7
Joined
Mar 22, 2010
Messages
228
change 100 to 100.00

JASS:
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local unit d = null
    local integer rank = GetUnitAbilityLevel( caster, 'Cal0' )
    local integer level = GetUnitLevel( caster )
    local integer leveltarget = GetUnitLevel(target)
    local integer agi = GetHeroAgi(target, true)
    local integer str = GetHeroStr(caster, true)
    local integer int = GetHeroInt(target, true)
    local integer int_caster = GetHeroInt(caster, true)
    local integer i = 1
    local real roll
    local real dodge = ((I2R(agi) / ( I2R(leveltarget) * 100.0 )) * 100.0)
    local real crit = ((I2R(str) / ( I2R(level) * 100.0 )) * 100.0)
    local real resistance = ((I2R(int) / ( I2R(leveltarget) * 125.0 )) + 1.0)
    local real chance = (20 + (10 * rank))
    local real damage_min = (((I2R(int_caster) + (50.0 * rank))) * ((rank - 0.50)))
    local real damage_max = (((I2R(int_caster) + (50.0 * rank))) * ((rank + 0.50)))
    local real damage
    local texttag t_d = null
    local texttag t_da = null

done..ill try if it will work

JASS:
IsUnitType(target)
gives me error
 
Level 7
Joined
Mar 22, 2010
Messages
228
Crit computation: Works
Dodge Texttag: Dont Work
Damage Texttag: Dont Work
Create Dummy: Dont Work

the local integer level works fine..
may i know the difference between GetUnitLevel and GetUnitHero?
 
GetUnitLevel returns the level of the unit... But heroes have two levels, Unit Level and Hero Level... Hero Level is the one that gets upgraded... using GetUnitLevel on heroes would (at least I think based on its name) return the UnitLevel of the hero, for most heroes that is 5 (that's the default on the object data)...

I'm not fund of using texttags so I don't know what else could be the problem with that...
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
constant native IsUnitType takes unit whichUnit, unittype whichUnitType returns boolean
so it should be:
if (IsUnitType(target,UNIT_TYPE_HERO)) then

I'm not fund of using texttags
should be:
I'm not fond of using texttags
 
Last edited:
Level 7
Joined
Mar 22, 2010
Messages
228
i will only change GetUnitLevel to GetHeroLevel..i wont do calculations below because if the target is not a hero, it will automatically change the dodge and resistance to a fixed value..

correct me if im wrong

and about the CreateUnit?
 
Level 7
Joined
Mar 22, 2010
Messages
228
but if you change it to GetHeroLevel I think it would return zero if the target is not a hero...

CreateUnit is fine, and there's no such thing as CreateHero... ^_^

if it goes zero it will still be covered by:
JASS:
    if target != UNIT_TYPE_HERO then
        set dodge = 15
        set resistance = 1.15
    endif

if it works fine why does it doesnt show up any dummy? even i changed the dummy's model to a visible one..
 
Level 7
Joined
Mar 22, 2010
Messages
228
its now all messed up..
the trigger doesnt work anymore..
its like the rawcodes of the condition is not correct BUT IT IS CORRECT..

try my map..
 

Attachments

  • Dawn of PVP.w3x
    99.9 KB · Views: 70
Level 22
Joined
Sep 24, 2005
Messages
4,821
The problem might be in your formulae, re-wrote your script in vjass and re-implemented a different formulae for chances. Didn't touch the texttags, I lack time , need to sleep. I used your test map as the testing environment.

Here's the script, copy this directly to your map if you want to test it;
JASS:
scope LightningStrike initializer onInit


private struct spell
    
endstruct

globals
    private constant integer    SPELL_ID           = 'Cal0'
    private constant integer    DUMMY_CASTER_ID    = 'cdu0'
    private constant integer    DUMMY_CASTER_SPELL = 'cds0'
    private constant string     DUMMY_CASTER_ORDER = "thunderbolt"
endglobals



private function action takes nothing returns nothing
    
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local unit dummyCaster = null
    
    //  Unit Level data
    local integer targetLevel = 0
    local integer casterLevel = GetHeroLevel( caster )
    local integer spellLevel  = GetUnitAbilityLevel( caster, SPELL_ID )
    
    //  Unit stats data
    
    //  caster
    local integer casterSTR = GetHeroStr( caster, true )
    local integer casterAGI = GetHeroAgi( caster, true )
    local integer casterINT = GetHeroInt( caster, true )
    
    // target
    local integer targetSTR = 0
    local integer targetAGI = 0
    local integer targetINT = 0

    local real dice = 0.0
    
    local real chanceMiss = 0.0
    local real chanceCrit = 0.0
    local real resistance = 0.0
    local real chanceStun = 0.20 + spellLevel * 0.10
    
    // Damage data
    
    local real damage    = 0.0
    local integer damageMin = 0
    local integer damageMax = 0
    
    
    local texttag t_d = null
    local texttag t_da = null
    
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action executed.")
    
    if IsUnitType( target, UNIT_TYPE_HERO ) then
        
        set targetSTR = GetHeroStr( target, true )
        set targetAGI = GetHeroAgi( target, true )
        set targetINT = GetHeroInt( target, true )
                
        set chanceCrit = 0.15 + I2R( casterSTR - targetSTR ) / I2R( targetSTR )
        set chanceMiss = 0.05 + I2R( casterAGI - targetAGI ) / I2R( targetAGI )
        set resistance = 0.05 + I2R( targetINT - casterINT ) / I2R( casterINT )
        
        set damageMin = 50 + casterINT * 10 / 2
        set damageMax = damageMin + damageMin / 2
        
        set damage = I2R( GetRandomInt( damageMin, damageMax ) )
        set damage = damage * ( 1.0 - resistance )
        
    else
        
        set targetLevel = GetUnitLevel( target ) * 0.02
        
        set chanceCrit = 0.50 - targetLevel
        set chanceMiss = 0.05 + targetLevel
        set resistance = 0.05 + targetLevel
        
        set damageMin = 50
        set damageMax = 75
        
        set damage = I2R( GetRandomInt( damageMin, damageMax ) )
        set damage = damage * ( 1.0 - resistance )
        
    endif

    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "chance to miss: " + R2S(chanceMiss))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "chance to stun: " + R2S(chanceStun))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "minimum damage: " + R2S(damageMin))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "maximum damage: " + R2S(damageMax))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "damage: " + R2S(damage))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "critical hit chance: " + R2S(chanceCrit))
    
    set dice = GetRandomReal( 0.0, 1.0 )
    
    if ( chanceMiss < dice ) then
        
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: damaging target["+GetUnitName(target)+"].")
        
        set dice = GetRandomReal( 0.0,1.0 )
        
        if chanceCrit > dice then
            debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: critical damage will be dealt.")
            set damage = damage * 2
        endif
        
        call UnitDamageTarget(caster, target, damage, true, false, null, null, null) 
            
        set dice = GetRandomReal( 0.0, 1.0 )
        //debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: dice value is " + R2S(dice) )
        //debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: stun chance is " + R2S(chanceStun) )
        
        if ( chanceStun > dice ) then
                    
            debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: will stun target.")
            set dummyCaster = CreateUnit(GetTriggerPlayer(), DUMMY_CASTER_ID, GetUnitX(target), GetUnitY(target), 0.00)
            call UnitApplyTimedLife (dummyCaster, 'BTLF', 1.00)
            call UnitAddAbility     (dummyCaster, DUMMY_CASTER_SPELL)
            call SetUnitAbilityLevel(dummyCaster, DUMMY_CASTER_SPELL, spellLevel)
            call IssueTargetOrder   (dummyCaster, "thunderbolt", target)
        
        endif
    

    endif
    
    set caster = null
    set target = null
    set dummyCaster = null
endfunction

private function condition takes nothing returns boolean
    debug local boolean b=GetSpellAbilityId() == SPELL_ID
    debug if b then
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"condition executed.")
    debug endif
    return GetSpellAbilityId() == SPELL_ID// and GetUnitTypeId(GetTriggerUnit()) == 'Chd0'
endfunction 

public function onInit takes nothing returns nothing
    local trigger t=CreateTrigger()
    
    call TriggerAddAction               ( t, function action )
    call TriggerAddCondition            ( t, Condition(function condition) )
    call TriggerRegisterAnyUnitEventBJ  ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"onInit: successful!")
endfunction

endscope

function InitTrig_Lightning_Strike takes nothing returns nothing
endfunction
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,208
chobibo, you forgot to null the local units which will cause their handle indicies to leak if they ever get killed (and then removed).

You also recalculate targetLevel * 0.02 times where it could be cached into a local.

damage - damage * resistance
could also be written as
damage * ( 1. - resistance )
which could be faster depending on compiler (how it caches intermitent results and how fast constats are).
 
Level 7
Joined
Mar 22, 2010
Messages
228
:goblin_jawdrop::goblin_jawdrop::goblin_jawdrop::goblin_wtf::goblin_wtf::goblin_wtf:

1. how am i gonna put it to vJass?
2. whats a "private"
3. whats a "scope"
4. whats a "public"
5. why there is a "debug" in every text display calls?

im so confused..i have to study this script well.!!!:goblin_cry:
 
scope/library is something like a class
private is to make the object private to the scope or library
public adds the name of the scope/library to the object name
JASS:
scope A
   
  public function B
   
  //now to call B you need to type call A_B()
  /*basically, public makes prefixing automated so that you won't need to prefix the functions urself... its for avoiding name redeclaration

*/
endscope

debug makes it such that the text is only displayed while on debug mode...
 
Level 7
Joined
Mar 22, 2010
Messages
228
The problem might be in your formulae, re-wrote your script in vjass and re-implemented a different formulae for chances. Didn't touch the texttags, I lack time , need to sleep. I used your test map as the testing environment.

Here's the script, copy this directly to your map if you want to test it;
JASS:
scope LightningStrike initializer onInit


private struct spell
    
endstruct

globals
    private constant integer    SPELL_ID           = 'Cal0'
    private constant integer    DUMMY_CASTER_ID    = 'cdu0'
    private constant integer    DUMMY_CASTER_SPELL = 'cds0'
    private constant string     DUMMY_CASTER_ORDER = "thunderbolt"
endglobals



private function action takes nothing returns nothing
    
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local unit dummyCaster = null
    
    //  Unit Level data
    local integer targetLevel = 0
    local integer casterLevel = GetHeroLevel( caster )
    local integer spellLevel  = GetUnitAbilityLevel( caster, SPELL_ID )
    
    //  Unit stats data
    
    //  caster
    local integer casterSTR = GetHeroStr( caster, true )
    local integer casterAGI = GetHeroAgi( caster, true )
    local integer casterINT = GetHeroInt( caster, true )
    
    // target
    local integer targetSTR = 0
    local integer targetAGI = 0
    local integer targetINT = 0

    local real dice = 0.0
    
    local real chanceMiss = 0.0
    local real chanceCrit = 0.0
    local real resistance = 0.0
    local real chanceStun = 0.20 + spellLevel * 0.10
    
    // Damage data
    
    local real damage    = 0.0
    local integer damageMin = 0
    local integer damageMax = 0
    
    
    local texttag t_d = null
    local texttag t_da = null
    
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action executed.")
    
    if IsUnitType( target, UNIT_TYPE_HERO ) then
        
        set targetSTR = GetHeroStr( target, true )
        set targetAGI = GetHeroAgi( target, true )
        set targetINT = GetHeroInt( target, true )
                
        set chanceCrit = 0.15 + I2R( casterSTR - targetSTR ) / I2R( targetSTR )
        set chanceMiss = 0.05 + I2R( casterAGI - targetAGI ) / I2R( targetAGI )
        set resistance = 0.05 + I2R( targetINT - casterINT ) / I2R( casterINT )
        
        set damageMin = 50 + casterINT * 10 / 2
        set damageMax = damageMin + damageMin / 2
        
        set damage = I2R( GetRandomInt( damageMin, damageMax ) )
        set damage = damage * ( 1.0 - resistance )
        
    else
        
        set targetLevel = GetUnitLevel( target ) * 0.02
        
        set chanceCrit = 0.50 - targetLevel
        set chanceMiss = 0.05 + targetLevel
        set resistance = 0.05 + targetLevel
        
        set damageMin = 50
        set damageMax = 75
        
        set damage = I2R( GetRandomInt( damageMin, damageMax ) )
        set damage = damage * ( 1.0 - resistance )
        
    endif

    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "chance to miss: " + R2S(chanceMiss))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "chance to stun: " + R2S(chanceStun))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "minimum damage: " + R2S(damageMin))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "maximum damage: " + R2S(damageMax))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "damage: " + R2S(damage))
    debug call DisplayTextToPlayer( GetOwningPlayer(caster), 0, 0, "critical hit chance: " + R2S(chanceCrit))
    
    set dice = GetRandomReal( 0.0, 1.0 )
    
    if ( chanceMiss < dice ) then
        
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: damaging target["+GetUnitName(target)+"].")
        
        set dice = GetRandomReal( 0.0,1.0 )
        
        if chanceCrit > dice then
            debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: critical damage will be dealt.")
            set damage = damage * 2
        endif
        
        call UnitDamageTarget(caster, target, damage, true, false, null, null, null) 
            
        set dice = GetRandomReal( 0.0, 1.0 )
        //debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: dice value is " + R2S(dice) )
        //debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: stun chance is " + R2S(chanceStun) )
        
        if ( chanceStun > dice ) then
                    
            debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: will stun target.")
            set dummyCaster = CreateUnit(GetTriggerPlayer(), DUMMY_CASTER_ID, GetUnitX(target), GetUnitY(target), 0.00)
            call UnitApplyTimedLife (dummyCaster, 'BTLF', 1.00)
            call UnitAddAbility     (dummyCaster, DUMMY_CASTER_SPELL)
            call SetUnitAbilityLevel(dummyCaster, DUMMY_CASTER_SPELL, spellLevel)
            call IssueTargetOrder   (dummyCaster, "thunderbolt", target)
        
        endif
    

    endif
    
    set caster = null
    set target = null
    set dummyCaster = null
endfunction

private function condition takes nothing returns boolean
    debug local boolean b=GetSpellAbilityId() == SPELL_ID
    debug if b then
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"condition executed.")
    debug endif
    return GetSpellAbilityId() == SPELL_ID// and GetUnitTypeId(GetTriggerUnit()) == 'Chd0'
endfunction 

public function onInit takes nothing returns nothing
    local trigger t=CreateTrigger()
    
    call TriggerAddAction               ( t, function action )
    call TriggerAddCondition            ( t, Condition(function condition) )
    call TriggerRegisterAnyUnitEventBJ  ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"onInit: successful!")
endfunction

endscope

function InitTrig_Lightning_Strike takes nothing returns nothing
endfunction

dude your formulas arent that good..
JASS:
        set chanceMiss = 0.05 + I2R( casterAGI - targetAGI ) / I2R( targetAGI )
with that, a hero with lower AGI attacking a hero with higher AGI will always miss. calculate it and assume own stats to see.

CORRECT ME IF IM WORNG



//----------------------------------------------
EDIT: i cant test map due to errors..
//----------------------------------------------
 
hmmm...

0.05 + (10-100)/100 => .05 + (-90/100) => .05 -.9 = -.85 < 0

so it will miss...

.05 + (10-200)/200 => .05 + (-190/200) => .05 - .95 = -.9 < 0

miss again...

.05 + (190-200)/200 => .05 + (-10/200) => .05 - .05 = 0

miss

so its like this... if the agility of the target is greater than the agility of the user by 5*(target agility/100), it will miss...


anyway, I think it as just an example, so just change it urself...
 
Level 7
Joined
Mar 22, 2010
Messages
228
i was not able to test the map...
 

Attachments

  • error.jpg
    error.jpg
    128.1 KB · Views: 75
Level 22
Joined
Sep 24, 2005
Messages
4,821
Yes, and that was intended. Also, I just gave a functional example and it need not be the one you must use, just as Adiktus mentioned.

Please don't misunderstand what I said about your formulae, I was just trying to point out that your spell might not be working because of it, I was not implying that it was bad or anything negative. Still, I'd like to apologize.

I'll still edit the formula to meet your needs and edit this post to add a test map. (compiled on the most recent version of JassNewGen)
 
Status
Not open for further replies.
Top