Warcraft III resources & community, 2003–2006 · archived

Blink Backwards a range of 200 upon taking damage

3 posts
#1

Blink Backwards a range of 200 upon taking damage

Alright, this has been bugging me to some extent.
I can't think of a way to do it, because of my lack of knowledge in the world editor in general.
If anyone has some free time, I'd greatly appreciate a map example or something.

Here's the plan:
When X takes an attack from melee, X has a Y% chance

[to blink in a the opposite direction of the attack.]


I have figured out how to trigger the first part with normal abilities, but I can not figure out the second part.

Of course, just telling me what to do will probably confuse me, but seeing the JASS code directly helps a whole bunch.
Thank you if you try to help!
#2
Let´s see...



function Trig_BackBlink_Conditions takes nothing returns boolean
    return IsUnitTypeId(GetTriggerUnit(),(hero rawcode)) and GetUnitAbilityLevel(GetTriggerUnit,(ability rawcode))<=0
endfunction

function BackBlink_Damaged takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local unit d=GetDamageSource() 
//GetDamageSourceBJ? Im not sure :s
    local location l=PolarProjectionBJ(GetUnitLoc(u),(distance),AngleBetweenPoints(GetUnitLoc(d),GetUnitLoc(u))) 
//Yes I know BJ functions suck but I dont know the X and Y maths without my JASS editor ;)
  //the target point
    if GetRandomInt(1,100)> (Chance in %) then
        return
  //don´t blink if chance failed
    endif
    call AddSpecialEffect(GetUnitX(u),GetUnitY(u),"(some blink effect path)")
    call AddSpecialEffect(GetLocationX(l),GetLocationY(l),"(some blink effect path)")
  //create the effects at source and target locations
    call SetUnitX(u,GetLocationX(l))
    call SetUnitY(u,GetLocationY(l))
 //theres an error if the new location is out of the playable map area, and also a way to check it(damn wheres my editor??? :( )
  //move the unit
    call RemoveLocation(l)
    set l=null
    set u=null
    set d=null
  //remove leaks
  //this function fires when the unit is damaged and blinks it back with specified effects
endfunction

function Trig_BackBlink_Actions takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterUnitEvent(t,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
//recheck that EVENT_... ;)
    call TriggerAddAction(t,function BackBlink_Damaged)
    set t=null
  //This function fires when a unit learns the Skill and creates a trigger which fires when the unit with the skill is damaged.
endfunction

function InitTrig_BackBlink takes nothing returns nothing
    set gg_trg_BackBlink=CreateTrigger()
    call TriggerRegisterAnyUnitEvent(gg_trg_BackBlink,EVENT_PLAYER_UNIT_HEROSKILL)  
//this is most likely not the correct EVENT_...and maybe not the right TriggerRegister function, i´m at school atm and dont have a JASS editor, will fix that;) just do this event in GUI and convert to custom text and you will get the correct functions for "a unit learns a hero skill"
call TriggerAddCondition(gg_trg_BackBlink,Condition(function Trig_BackBlink_Conditions))
call TriggerAddAction(gg_trg_BackBlink, function Trig_BackBlink_Actions)
endfunction



I think that should do it, even if not all the function names are correct (if you get compile errors, check the function names first)
#3
The Math for Polar Offsets is

for X Source + Dist * Cos( angle * bj_DEGTORAD )

for Y Source + Dist * Sin( angle * bj_DEGTORAD )

the value of bj_DEGTORAD is 180/Pi