View Single Post
Old 11-01-2009, 08:21 PM   #26
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

I use this in a starcraft map and make protoss shields with it.
But the function that blocks the damage only fires when the unit has already been attacked one time.
here is the function:

Collapse JASS:
scope Energyshield initializer init
    function onDamage takes unit damaged, unit source, real damage returns nothing
        local real angle
        local unit u
        local integer ID = 'e001'
        
        if Basics_GetUnitRace(damaged) != PROTOSS or GetUnitState(damaged,UNIT_STATE_MANA) < 2.5 or IsUnitPaused(damaged) then
            return
        endif
        
        set angle = Atan2(GetUnitY(source)-GetUnitY(damaged),GetUnitX(source)-GetUnitX(damaged))
        if damage > GetUnitState(damaged,UNIT_STATE_MANA) then
            call SetUnitState(damaged,UNIT_STATE_LIFE,GetUnitState(damaged,UNIT_STATE_LIFE)+damage-GetUnitState(damaged,UNIT_STATE_MANA))
        else
            call SetUnitState(damaged,UNIT_STATE_LIFE,GetUnitState(damaged,UNIT_STATE_LIFE)+damage)
        endif
        call SetUnitState(damaged,UNIT_STATE_MANA,GetUnitState(damaged,UNIT_STATE_MANA)-damage)
    
        // GetUnitZ + Units fly height
        if GetUnitZ(source) - GetUnitZ(damaged) > 200. then
            set ID = 'e002'
        endif
        
        if IsUnitType(damaged,UNIT_TYPE_MECHANICAL) or IsUnitType(damaged,UNIT_TYPE_STRUCTURE) then
            set u = CreateUnit(Player(12),ID,GetUnitX(damaged)+40.*Cos(angle),GetUnitY(damaged)+40.*Sin(angle),angle*bj_RADTODEG)
            call SetUnitScale(u,1.2,1.2,1.3)
            call SetUnitFlyHeight(u,40.,0.)
        else
            set u = CreateUnit(Player(12),ID,GetUnitX(damaged)+26.*Cos(angle),GetUnitY(damaged)+26.*Sin(angle),angle*bj_RADTODEG)
        endif
        call UnitApplyTimedLife(u,'BTLF',.8)
    endfunction
    
    private function init takes nothing returns nothing
        call RegisterDamageResponse(onDamage)
    endfunction
endscope
Mr.Malte is offline   Reply With Quote