How to calculate a unit's armor with a skill.

Status
Not open for further replies.
Level 1
Joined
Jul 8, 2012
Messages
5
JASS:
library GetDefense initializer Init

globals
      constant real Armor_Def = 0.06
      constant integer Ability_Def = 'A000'//Skill ID
      hashtable HT = null
endglobals     

function TimerDef takes nothing returns nothing
     local timer Timer = GetExpiredTimer()
     local integer ParentKey = GetHandleId(Timer)
     local unit Unit = LoadUnitHandle(HT,ParentKey,1)
     local real Life = LoadReal(HT,ParentKey,2)
     call SetUnitLifeBJ( Unit, ( Life ) )
     call DestroyTimer(Timer)
     set Timer = null
     set Unit = null
endfunction    
    
function ShowDef takes nothing returns nothing
     local unit Unit = GetTriggerUnit()
     local integer ParentKey = GetHandleId(Unit)
     local unit Source = LoadUnitHandle(HT,ParentKey,1)
     local real Life = LoadReal(HT,ParentKey,2)
     local real Damage = GetEventDamage()
     local real Constant = 100/(Armor_Def*100)
     local real Percent = Damage/10
     local real Defense = Constant*(1-Percent)/Percent
     local timer Timer = CreateTimer()
     //call BJDebugMsg( I2S(ParentKey) )
     if GetEventDamageSource() == Source then   
        call DisplayTextToPlayer( GetOwningPlayer(Source), 0, 0, R2S(Defense) )
        call SaveReal(HT,GetHandleId(Timer),2,Life)
        call SaveUnitHandle(HT,GetHandleId(Timer),1,Unit)
        call TimerStart(Timer,0.01,false,function TimerDef)
        call DestroyTrigger(GetTriggeringTrigger())
     endif
     set Timer = null
     set Unit = null
     set Source = null
endfunction

function GetDef takes nothing returns nothing
     local unit Unit = GetTriggerUnit()
     local unit Target = GetSpellTargetUnit()
     local real Life = GetUnitState(Target, UNIT_STATE_LIFE)
     local trigger Trg = CreateTrigger()
     local integer ParentKey = GetHandleId(Target)
     if GetSpellAbilityId() == Ability_Def and Life > 10 then
        //call BJDebugMsg( I2S(ParentKey ))
        call SaveUnitHandle(HT,ParentKey,1,Unit)
        call SaveReal(HT,ParentKey,2,Life)
        call TriggerRegisterUnitEvent( Trg, Target, EVENT_UNIT_DAMAGED )
        call TriggerAddAction( Trg, function ShowDef )
        call UnitDamageTarget( Unit, Target, 10.00, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
     endif
     set Unit = null
     set Target = null
     set Trg = null
endfunction

function Init takes nothing returns nothing
      local trigger Trg = CreateTrigger()
      call FlushParentHashtable( HT )
      set HT = InitHashtable()
      call TriggerRegisterAnyUnitEventBJ( Trg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
      call TriggerAddAction( Trg, function GetDef )
      set Trg = null
endfunction

endlibrary
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
call SetUnitLifeBJ( Unit, ( life ) ) -> call SetUnitState( Unit, UNIT_STATE_LIFE, (life) )
also instead of doing //call BJDebugMsg coudnt you do debug call BJDebugMsg?
other than that i don't see anything bad
but well There are better ppl here :D
 
Status
Not open for further replies.
Top