Dealing Damage Based On Range

Bribe

vJass errors are legion
Reaction score
67
You cannot detect collision of a missile, so you'll need a custom projectiles system. Also, distance is like this:

x1=Caster x; y1=Caster y

x2=spell target x; y2=spell target y

Distance=SqaureRoot((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)

40% of that is Distance*0.40
 

Crazy_Dead

New Member
Reaction score
24
I didnt want to detect collision.. I want to detect distance traveled to a target.
And then, i want to deal 30/35/40% of that range in damage. ;)
 

Bribe

vJass errors are legion
Reaction score
67
So you basically want it every time a unit is about to attack? Or is it in response to a spell?

If it's a spell, you can use what I gave you. Here, I'll put it in JASS:

JASS:

local real x1 = GetUnitX(GetTriggerUnit())
local real y1 = GetUnitY(GetTriggerUnit())
local real x2 = GetSpellTargetX()
local real y2 = GetSpellTargetY()
local real Distance = SquareRoot((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
local real Damage = 0.40*Distance

call UnitDamageTarget(GetTriggerUnit(),GetSpellTargetUnit(),Damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)

// if you are responding to a "Unit Attacked" event use:

local real x1 = GetUnitX(GetAttacker())
local real y1 = GetUnitY(GetAttacker())
local real x2 = GetUnitX(GetTriggerUnit())
local real y2 = GetUnitY(GetTriggerUnit())
local real Distance = SquareRoot((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
local real Damage = 0.40*Distance

call UnitDamageTarget(GetAttacker(),GetTriggerUnit(),Damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
 

Jedi

New Member
Reaction score
63
Impetus damage depends on distance between caster and target when it hit, hope you know that.

You have to use a dummy, or projectile system or whatever they are if you want to detect travelled distance.
 

Crazy_Dead

New Member
Reaction score
24
Impetus damage depends on distance between caster and target when it hit, hope you know that.

You have to use a dummy, or projectile system or whatever they are if you want to detect travelled distance.

Go closer with that Dummy.
Explain*
 

Jedi

New Member
Reaction score
63
Maybe,
You can create a dummy and start a timer.When dummy is hit the target, pause the timer and find travelled distance(You will probably move dummy with triggers, maybe you can find it's speed with compare with a storm bolt projectile :D)
 

Bribe

vJass errors are legion
Reaction score
67
Impetus damage depends on distance between caster and target when it hit

That's collision.

If you want, I can build you this from Berbanog's missile system that I linked, only it will require you to import both Vector as well as the Projectile system. Vector is a very common library by the well-grounded Anitarf (you'll find him on WC3C.net), and Projectile is the best missile system I've ever seen.
 

Bribe

vJass errors are legion
Reaction score
67
Done:

JASS:


//! zinc
library RangeDamage requires Projectile
{
    constant integer SPELL_ID = 'A000'  ;
    constant integer DUMMY_ID = 'n000'  ;   /* Dummy must be the "Dummy.mdx" model file from XE */
    
    constant string SkinPath = "Abilities\\Weapons\\DemonHunterMissile\\DemonHunterMissile.mdl";
    
    location loc = Location(0.,0.);
    
    
    struct data extends projectile
    {
        effect skin; vector o;

        method onFinish()
        {
            real damage=0.4* SquareRoot((o.x-x)*(o.x-x)+(o.y-y)*(o.y-y));
            UnitDamageTarget(source,target,damage,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS);
            DestroyEffect(skin); o.destroy();
        }
    
        
        static method NewMissile (unit u,unit v)
        {
    /* Setup vectors */
            thistype this; vector
                from = vector.create(GetWidgetX(u),GetWidgetY(u),0.),
                dest = vector.create(GetWidgetX(v),GetWidgetY(v),0.);
            
            MoveLocation(loc,from.x,from.y);
            UnitAddAbility(u,'Amrf'); UnitRemoveAbility(u,'Amrf');
            from.z= GetLocationZ(loc) +60. +GetUnitFlyHeight(u);
            //
            MoveLocation(loc,dest.x,dest.y);
            UnitAddAbility(v,'Amrf'); UnitRemoveAbility(v,'Amrf');
            dest.z=GetLocationZ(loc) +GetUnitFlyHeight(v);
            
    /* Create Missile */
            this = create(CreateUnit(GetTriggerPlayer(),DUMMY_ID,from.x,from.y,GetUnitFacing(u)));
            
    /* Configure settings */
            o = from; toRemove = true; source = u; target = v;
            //
            activeUnitCollision = false; activeDestCollision = false; activeTargetFollow = true;
            
    /* Attach the missile "skin" */
            skin = AddSpecialEffectTarget(SkinPath,toUnit,"origin");
            //
            doLaunch(from,dest,900.,0.15); dest.destroy();
        }
        
        
        static method Conditions()-> boolean
        {
            if (GetSpellAbilityId()==SPELL_ID)
            //
                NewMissile(GetTriggerUnit(),GetSpellTargetUnit());
            //
            return false;
        }
        
        
        static method onInit()
        {
            trigger t=CreateTrigger();
            TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT);
            TriggerAddCondition(t,Condition(static method thistype.Conditions));
        }
    }
}
//! endzinc
 

Bribe

vJass errors are legion
Reaction score
67
You said you already have the dummy. It doesn't need XE collider to use the dummy, as the dummy is just a model. I use it in blank test maps all the time with no libraries.
 

Crazy_Dead

New Member
Reaction score
24
Can you make this in an demo map, i cant get it work.
Should i create a dummy, with Locust, and invul and that Model?
 

Bribe

vJass errors are legion
Reaction score
67
Locust is auto-invul. That 'n000' is yours to change freely, as well as the spell id, to whatever you need them to be. Technically, the dummy doesn't even have to be the dummy.mdx model, you could change its model to the missile-effect and totally remove the special effect I made there. It's up to you.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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