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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top