• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] UnitDamageTarget ????

Status
Not open for further replies.
Level 7
Joined
Mar 22, 2010
Messages
228
whenever i hit save i get two sets of syntax errors. the 1st one has almost 5k errors and the 2nd error has 60+ i think..

EDIT: i have the latest version which is 0.2.A.B

i edited the script given to me...

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


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, "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 )
        
        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, "action: damaging target["+GetUnitName(target)+"].")
        
        set dice = GetRandomReal( 0.0,1.0 )
        
        if chanceCrit > dice then
            debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "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, "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, DUMMY_CASTER_ORDER, target)
        
        endif
    

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

function condition takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID and GetUnitTypeId(GetTriggerUnit()) == 'Chd0'
endfunction 

function InitTrig_Lightning_Strike 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, "onInit: successful!")
endfunction

i removed the scope

i found some mistakes on his script like the globals..i think that shouldnt be inside the scope and the SCOPE_PREFIX, it was recognized as a variable

those were my observations

no syntax errors anymore
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Try using this one:

JASS:
scope LightningStrike initializer onInit

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
    
    // units & spell data
    local unit      caster      = GetTriggerUnit()
    local unit      target      = GetSpellTargetUnit()
    local unit      dummyCaster = null
    
    local integer   spellLevel  = GetUnitAbilityLevel( caster, SPELL_ID )

    //  probability data
    local real      dice        = 0.0
    
    local real      value       = 0.0
    local real      accuracy    = 0.0
    local real      resistance  = 0.0
    local real      chanceCrit  = 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
    
    // text tag data
    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
        
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"target type: HERO")
        
        // --------------------------------------------------
        // Calculate the chance of dealing critical damage.
        // --------------------------------------------------
        set value = I2R( GetHeroStr( caster, true ) - GetHeroStr( target, true ) ) / I2R( GetHeroStr( target, true ) )
        
        // if the value is below 0.0 then clip it to 0.0
        if ( value < -0.50 ) then
            set value = -0.50
        elseif ( value > 0.50 ) then
            set value = 0.50
        endif
        
        set chanceCrit = 0.50 + value
        
        // --------------------------------------------------
        // Calculate the accuracy of the spell based on the caster's agility.
        // --------------------------------------------------
        set value = I2R( GetHeroAgi( caster, true ) - GetHeroAgi( target, true ) ) / I2R( GetHeroAgi( target, true ) )
        
        // if the value is below 0.0 then clip it to 0.0
        if ( value < -0.50 ) then
            set value = -0.50
        elseif ( value > 0.50 ) then
            set value = 0.50
        endif
        
        set accuracy = 0.50 + value
        
        // --------------------------------------------------
        // Calculate the spell resistance based on the caster's intelligence.
        // --------------------------------------------------
        set value = I2R( GetHeroInt( caster, true ) - GetHeroInt( target, true ) ) / I2R( GetHeroInt( target, true ) )
        
        // if the value is below 0.0 then clip it to 0.0
        if ( value < -0.10 ) then
            set value = -0.10
        endif
        set resistance = 0.10 + value
        
        
        // --------------------------------------------------
        // Calculate the damage to be dealt. This is just temporary.
        // --------------------------------------------------
        set damageMin = 50 + GetHeroInt( caster, true ) * 10 / 2
        set damageMax = damageMin + damageMin / 2
        
        set damage = I2R( GetRandomInt( damageMin, damageMax ) )
        set damage = damage * ( 1.0 - resistance )
        
    else
    
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"target type: NORMAL")
        
        set value = I2R( GetUnitLevel( target ) ) * 0.10
        
        set chanceCrit = 1.00 - value
        
        if ( chanceCrit < 0.20 ) then
            set chanceCrit = 0.20
        endif
        
        set accuracy   = 1.00 - value
        
        if ( accuracy < 0.20 ) then
            set accuracy = 0.20
        endif
        
        set resistance = 0.05 + value
        
        if ( resistance > 1.00 ) then
            set resistance = 1.00
        endif
        
        set damageMin = 50
        set damageMax = 75
        
        set damage = I2R( GetRandomInt( damageMin, damageMax ) )
        set damage = damage * ( 1.0 - resistance )
        
    endif
    
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: ACCURACY: "            + R2S(accuracy*100)     + "%"   )
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: CHANCE[STUN]: "        + R2S(chanceStun*100)   + "%"   )
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: CHANCE[CRITICAL]: "    + R2S(chanceCrit*100)   + "%"   )
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: DAMAGE MIN: "          + R2S(damageMin)                )
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: DAMAGE MAX: "          + R2S(damageMax)                )
    debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: ACTUAL DAMAGE: "       + R2S(damage)                   )
    
    set dice = I2R( GetRandomInt( 0, 100 ) ) / 100
    
    if ( accuracy > dice ) then
        
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: damaging target["+GetUnitName(target)+"].")
        
        set dice = I2R( GetRandomInt( 0, 100 ) ) / 100
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "action: critical dice: " + R2S(dice) )
        if ( chanceCrit > dice ) then
            set damage = damage * 1.5
            debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "|cffffcc00damage is critical: " + R2S(damage))
        endif
        
        call UnitDamageTarget(caster, target, damage, true, false, null, null, null) 
            
        set dice = I2R( GetRandomInt( 0, 100 ) ) / 100
        
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: stun dice " + R2S(dice) )
        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
    
    debug else
        debug call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, SCOPE_PREFIX+"action: the spell missed.")
    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

I tried saving the script you provided and it yielded no errors.
 
Last edited:
Level 22
Joined
Sep 24, 2005
Messages
4,821
Don't use the syntax check dude, it only checks jass syntax, not vjass syntax. Save the map, jasshelper will intercept the save and compile the script.
 
Level 7
Joined
Mar 22, 2010
Messages
228
still it doesnt work..download my map and see it for yourself man..
 

Attachments

  • Dawn of PVP.w3x
    101.3 KB · Views: 48
Level 22
Joined
Sep 24, 2005
Messages
4,821
What doesn't work for you? It works for me.
Here's your map, I re-compiled it on my JNGP, and it works. If you want to test it open it but do not save it or use the trigger editor, click the test map button immediately after opening it.
 

Attachments

  • Dawn of PVP[checked].w3x
    100.9 KB · Views: 58
Level 7
Joined
Mar 22, 2010
Messages
228
it worked now..but i will change some of the formula so that it will fit my game settings..thank you very much +rep to those who helped.
 
Status
Not open for further replies.
Top