• 🏆 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] Blink Backwards a range of 200 upon taking damage

Status
Not open for further replies.
Level 4
Joined
May 20, 2006
Messages
43
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!
 
Level 2
Joined
Sep 10, 2004
Messages
21
Let´s see...

JASS:
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)
 
Status
Not open for further replies.
Top