Weird Offsets

NeuroToxin

New Member
Reaction score
46
Okay, so in my ability, Execute, heres what i have before I describe any further.

Learn Execution - [E] [Level %d].
When the warrior is attacked, and the attack brings him below 10% health, he will jump behind the target and perform an execution, dealing a percent of the targets max hp in damage, if the target has less health than him, he will kill it.

Level 1 - Deals 5% max hp
Level 2 - Deals 7% max hp
Level 3 - Deals 9% max hp
Level 4 - Deals 11% max hp

The problems are as follows.
1. I want the unit to go behind the unit (Sort of) which would mean using the angle from the caster to the unit, and if you'll look at ax2 and ay2, I tried doing that, however, it just messes up in that.
2. Also, I used a parabola in one of my other spells, and for some reason, it works sometimes, but not all the time.
3. I really want to use this spell, but I need ideas as to what I can do so that its not overpowered.
JASS:

scope Execute initializer Init
    globals
//The spell ID of the passive ability Execution, press Control + D to get it.
        private constant integer SPELLID = 'A005'
//The ability ID for Crow Form, should not need changing.
        private constant integer CROW_FORM = 'Arav'
//The effect played when a unit is executed rather than percent of hp
        private constant string EXECUTE_EFFECT = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl"
//The effect played when a target is taken a percent of his hp, rather than executed
        private constant string HIT_EFFECT = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspirittarget.mdl"
//The effect attached to the caster
        private constant string CASTER_ATTACHMENT = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
//The offset per TINTERVAL.
        private constant real OFFSET = 20
//The timer interval for the moving
        private constant real TINTERVAL = 0.03125
//The attachment point for everything
        private constant string ATTACH_POINT = "origin"
    endglobals
    
//THIS DAMAGE IS A PERCENT OF THEIR MAX LIFE!
    private function DAMAGE takes integer lvl returns real
        return .03 + (lvl * .02)
    endfunction

//Credits to AceHart for the Parabola function.
    private function GetParabolaZ takes real x, real dist, real height returns real
        return 4.*height*x*(dist-x)/(dist*dist)
    endfunction
    
    globals
        private hashtable h = InitHashtable()
    endglobals
    
    private function MoveDamage takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer hand = GetHandleId(t)
    local unit attacked = LoadUnitHandle( h, hand, 0)
    local unit attacker = LoadUnitHandle( h, hand, 1)
    local real ax = GetUnitX(attacked)
    local real ay = GetUnitY(attacked)
    local real ax1 = GetUnitX(attacker)
    local real ay1 = GetUnitY(attacker)
    local real angle = Atan2(ay1 - ay, ax1 - ax)
    local real ax2 = ax1 + 50 * Cos(angle)
    local real ay2 = ay1 + 50 * Sin(angle)
    local real dx = ax1 - ax
    local real dy = ay1 - ay
    local real dist = SquareRoot(dx * dx + dy * dy)
    local real offsetx
    local real offsety
    local real dam
    local real a = LoadReal( h, hand, 3)
    if dist >= 50 then
        set offsetx = ax + OFFSET * Cos(angle)
        set offsety = ay + OFFSET * Sin(angle)
        call SetUnitX( attacked, offsetx)
        call SetUnitY( attacked, offsety)
        call SetUnitFacing( attacked, angle * bj_RADTODEG)
        call SetUnitFlyHeight( attacked, GetParabolaZ(a, dist, 400), 0)
        call SaveReal( h, hand, 3, a - OFFSET)
    else   
        set dam = DAMAGE(GetUnitAbilityLevel(attacked, SPELLID))
        call DestroyEffect(LoadEffectHandle(h, hand, 2))
        call UnitRemoveAbility( attacked, CROW_FORM)
        call SetUnitFacing( attacked, angle + 180)
        call SetWidgetLife( attacked, GetWidgetLife(attacked) * .5)
        if GetWidgetLife(attacker) < GetWidgetLife(attacked) then
            call KillUnit( attacker)
            call DestroyEffect(AddSpecialEffectTarget( EXECUTE_EFFECT, attacker, ATTACH_POINT))
        else
            call SetWidgetLife( attacker, GetWidgetLife(attacker) - (GetUnitState(attacker, UNIT_STATE_MAX_LIFE) * dam))
            call DestroyEffect(AddSpecialEffectTarget( HIT_EFFECT, attacker, ATTACH_POINT))
        endif
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushChildHashtable( h, hand)
    endif
    endfunction
    
    private function OnAttack takes nothing returns boolean
    local unit attacker
    local unit attacked
    local real percenthp
    local timer t
    local effect e
    local integer hand
    local boolean bool1 = (GetUnitAbilityLevel(GetTriggerUnit(), SPELLID) > 0)
    local real dx
    local real dy
    local real a
    if bool1 then
        set attacker = GetAttacker()
        set attacked = GetTriggerUnit()
        set percenthp = (GetUnitState( attacked, UNIT_STATE_MAX_LIFE) * .1)
        if percenthp > GetWidgetLife(attacked) then
            set t = CreateTimer()
            set hand = GetHandleId(t)
            set dx = GetUnitX(attacker) - GetUnitX(attacked)
            set dy = GetUnitY(attacker) - GetUnitY(attacked)
            set a = SquareRoot(dx * dx + dy * dy)
            call SaveReal( h, hand, 3, a)
            call SaveUnitHandle( h, hand, 0, attacked)
            call SaveUnitHandle( h, hand, 1, attacker)
            set e = AddSpecialEffectTarget( CASTER_ATTACHMENT, attacked, ATTACH_POINT)
            call SaveEffectHandle( h, hand, 2, e)
            call UnitAddAbility( attacked, CROW_FORM)
            call TimerStart( t, TINTERVAL, true, function MoveDamage)
        endif
    endif
    return true
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition( t, Condition(function OnAttack) )
    endfunction
endscope
 

WaterKnight

Member
Reaction score
7
@1.
JASS:
    local real ax = GetUnitX(attacked)
    local real ay = GetUnitY(attacked)
    local real ax1 = GetUnitX(attacker)
    local real ay1 = GetUnitY(attacker)
    local real angle = Atan2(ay1 - ay, ax1 - ax)

        set offsetx = ax + OFFSET * Cos(angle)
        set offsety = ay + OFFSET * Sin(angle)
        call SetUnitX( attacked, offsetx)
        call SetUnitY( attacked, offsety)
        call SetUnitFacing( attacked, angle * bj_RADTODEG)

ax/ay are the coordinates of the warrior, yet you want him to appear behind the attacker (ax1/ay1). In case he does not execute the assassination backwards, I would inverse the facing.

@2. mysterious...information?

@3. In general, it's bad when a (human) player can hurt himself by a in normality advantageous action, such as attacking the enemy. While it may be a method of restriction, the ability as you described would carry it too far. It would mean you suicide when attacking him at under 10% with lower hitpoints unless you kill him with that blow. Additionally, the ability only shows effect with the warrior falling under 10% life, so it's useless the rest of time. Now imagine there is another effect that the warrior can hurt himself with exceeding the 10% limit without a damage source/damage source already dead.

So what do you want to keep from your two-lines skill? If that is an ability of a hero in a hero-focussed map, it should actually be more manifold.
 

emjlr3

Change can be a good thing
Reaction score
395
problem is that [ljass]a[/ljass] will change, even though you store it at the start - therefore there may be times where [ljass]dist>a[/ljass], which would give you very weird results
 

NeuroToxin

New Member
Reaction score
46
But, in my other ability where I first used a parabola it just when it ended, it'd just stay at the default height. But it'd still perform the parabola to the targeted point.

WaterKnight said:
@1.
NeuroToxin said:
JASS:
local real ax = GetUnitX(attacked)
    local real ay = GetUnitY(attacked)
    local real ax1 = GetUnitX(attacker)
    local real ay1 = GetUnitY(attacker)
    local real angle = Atan2(ay1 - ay, ax1 - ax)

        set offsetx = ax + OFFSET * Cos(angle)
        set offsety = ay + OFFSET * Sin(angle)
        call SetUnitX( attacked, offsetx)
        call SetUnitY( attacked, offsety)
        call SetUnitFacing( attacked, angle * bj_RADTODEG)
ax/ay are the coordinates of the warrior, yet you want him to appear behind the attacker (ax1/ay1). In case he does not execute the assassination backwards, I would inverse the facing.

That wasn't the problem, its a great suggestion, but its not the problem, the problem, is that, if I add 100 more towards the angle, then I try to make him to there, then it just screws up and jumps everywhere.
 

emjlr3

Change can be a good thing
Reaction score
395
i would do something like this

JASS:
private struct execute
    unit u
    unit targ
    timer t
    real ticks=0.
    
    // Config:
    static constant real                   time                = 1. // time of jump in seconds
    static constant real                   interval            = .04 // timer interval in seconds
    static constant real                   height              = 400. // height of jump
    static constant integer                anim                = 5 // animation during jump
    static constant real                   scale               = 2. // animation scale during jump
    static constant real                   defscale            = 1. // default animation scale
    static constant real                   offset              = 50. // distance offset to land behind target
    static constant integer                fly                 = 'amrf' // fly trick
    
    method destroy takes nothing returns nothing
        // recycle timer
        call ReleaseTimer(.t)
        // restore default fly height to jumper
        call SetUnitFlyHeight(.u,GetUnitDefaultFlyHeight(.u),0.)
        // stop jump animation
        call QueueUnitAnimation(.u,"stand ready")
        // restore animation time scale
        call SetUnitTimeScale(.u,.defscale,.defscale,.defscale)
    endmethod
    static method getParabolaZ takes real x, real dist, real height returns real
        return 4.*height*x*(dist-x)/(dist*dist)
    endmethod
    static method periodic takes nothing returns nothing
        local thistype this=GetTimerData(GetExpiredTimer())
        local real x=GetUnitX(.u)
        local real y=GetUnitY(.u)
        local real xt=GetUnitX(.targ)
        local real yt=GetUnitY(.targ)
        local real ang=Atan2(yt-y,xt-x)
        local real dist
        local real move
        
        // keep jumper facing target, even when it jumps behind...
        call SetUnitFacing(.u,ang)
        if .ticks==0. then
            // first iteration, use a neat animation
            // and adjust time scale so the animation finishes after 1 second
            // usually must do this here because at first cast it often doesn't work
            // and cancels the animation
            // might not be an issue if the jumper is being attacked though, instead of casting an ability
            call SetUnitAnimationByIndex(.u,.anim)
            call SetUnitTimeScale(.u,scale,.scale,.scale)
        endif
        
        // update % of jump done
        set .ticks=.ticks+.interval
        // game over checks
        if not UnitAlive(.targ) or not UnitAlive(.u) or .ticks>=.time then            
            call .destroy()
        else       
            // distance to 50. behind the target
            set dist=SquareRoot(Pow(x-xt,2)+Pow(y-yt,2))+.offset
            // linear move speed dependant on dist and % of parabola left
            set move=dist/((.time-.ticks)/.interval)
            call SetUnitX(.u,x+move*Cos(ang))
            call SetUnitY(.u,y+move*Sin(ang))
            // instead of some movedistance, I use ticks as a counter for the % of the parabola done
            // in this, its easy to keep track of, even though I introduce the limitation
            // of a constant jump time of 1 second, but hey, atleast it works
            call SetUnitFlyHeight(.u,thistype.getParabolaZ(.ticks,.time,.height),0.)
        endif
    endmethod
    static method create takes nothing returns thistype
        local thistype this=thistype.allocate()
        
        set .u=GetTriggerUnit()
        set .targ=GetAttacker()
        set .t=NewTimer()
        call SetTimerData(.t,this)
        call TimerStart(.t,.interval,true,function thistype.periodic)
        
        // add and remove fly trick from jumper, so he can fly
        // and we don't see the ability afterwards
        call UnitAddAbility(.u,.fly)
        call UnitRemoveAbility(.u,.fly)
        
        return this
    endmethod
endstruct


un-tested, un-compiled

should work though, the only limitation being that there is now a set jump duration, as opposed to a set move distance (though you can always change this dependent on original jump distance, or level, or whatever)

sometimes if i coded something, and it just plum doesn't work, I just start from scratch and try again - it often works the second time, and you usually save time in the long run

may want to keep track of who is jumping, so they don't try to jump more than once at a time
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top