• 🏆 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!

[vJASS] Someone expierienced with xemissile?

Status
Not open for further replies.
Level 2
Joined
Apr 29, 2013
Messages
21
Hello,

I've a problem using xemissile. Rather it doesn't do damage :(.
JASS:
struct barrel extends xemissile
    static constant string EFFECT = "war3mapImported\\RollingKegMissle.mdx"
    static constant real SCALE = 1.
   
    static constant real VELOCITY = 600.
   
    static constant real ZSTART = 60.
    static constant real ZEND = 60.
   
    unit caster
    real targetx
    real targety
    
    method onHit takes nothing returns nothing
        call DoDmgAoE(.caster, .targetx, .targety, 300., 75., 25., 'A014', 0., .1, DMG_Magic, 0.)
    endmethod
   
    static method create takes unit caster,real tx,real ty returns thistype
        local thistype tt = thistype.allocate(GetWidgetX(caster), GetWidgetY(caster), thistype.ZSTART, tx, ty, thistype.ZEND)
        if (tt > 0) then
            set tt.fxpath = thistype.EFFECT
            set tt.scale = thistype.SCALE
            call tt.launch(thistype.VELOCITY, 0.)
            set tt.caster = caster
            set tt.targetx = tx
            set tt.targety = ty
        endif
        return tt
    endmethod
   
    method onDestroy takes nothing returns nothing
       
    endmethod
endstruct

I don't think that it's my Damagesystems fault but maybe I'm wrong so I'll post that code as well.

JASS:
library Damage requires ExtendedFunctions, UnitFuncs
    //Base Functions
    
    globals
        constant integer DMG_Physical = 0
        constant integer DMG_Magic    = 1
        constant integer DMG_Absolute = 2
    endglobals
    
    private function GetArmor takes unit u returns real
        local real life = GetWidgetLife(u)
        local real temp = life
        local real red
        if(life <= 30.) then
            call SetWidgetLife(u, 30.)
            set temp = 30.
        endif
        set udg_NotRec = true
        call UnitDamageTarget(u, u, 10., true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null)
        set red = (10.-temp+GetWidgetLife(u))/10.
        call SetWidgetLife(u, life)
        if(red > 1.) then
            return 1.
        else
            return red
        endif
    endfunction
    
    private function GetResistence takes unit u returns real
        local integer i = GetHeroAgi(u, true)
        if(IsUnitType(u, UNIT_TYPE_STRUCTURE)) then
            return .75
        else
            if(i > 0) then
                return (.02 * i) / (.02 * i + 1)
            else
                return 2 - Pow(0.94, i)
            endif
        endif
    endfunction
    
    function DamageTarget takes unit c,unit t,real d,integer m returns nothing
        local real life = GetWidgetLife(t)
        local real red = 0.
        local real realdmg = 0.
        if(m == DMG_Physical) then
            set red = GetArmor(t)
            set realdmg = d * (1 - red)
        elseif(m == DMG_Magic) then
            set red = GetResistence(t)
            set realdmg = d * (1 - red)
        else
            set realdmg = d
        endif
        if(realdmg < 1.) then
            return
        endif
        if(life <= realdmg) then
            call KillUnit(t)
            call OnUnitDmg(c, t, realdmg, m)                // <-----UnitFuncs
            call OnUnitDeath(c, t)                              // <-----UnitFuncs
        else
            call SetWidgetLife(t, life - realdmg)
            call OnUnitDmg(c, t, realdmg, m)                // <-----UnitFuncs
            call SetAssist(c, t)                                  // <-----UnitFuncs
        endif
    endfunction
    
    function DoDmgAoE takes unit c,real x,real y,real r,real b,real d,integer i,real adv,real apv,integer m,real h returns nothing
        local integer p = GetPlayerId(GetOwningPlayer(c))
        local integer ap = GetHeroInt(c, true)
        local integer ad = GetHeroStr(c, true)
        local real z = GetUnitAbilityLevel(c, i)
        //
        local group g = GetUnitsInRangeOfLocAll(r, Location(x, y))
        local integer I = 0
        local integer G = CountUnitsInGroup(g)
        local unit U
        //
        set z = b + z * d
        if(m != DMG_Absolute) then
            set z = z + apv * ap + adv * ad
        endif
        set udg_HealEx = h
        loop
            exitwhen I > G
            set U = FirstOfGroup(g)
            if(Check_Target(c, U)) then
                call DamageTarget(c, U, z, m)
            endif
            call GroupRemoveUnit(g, U)
            set I = I + 1
        endloop
        call DestroyGroup(g)
        set U = null
        set udg_HealEx = 0.
        call DestroyGroup(g)
    endfunction
    
endlibrary

thanks in advance for help


Edit: Sry for using space for nothing... found the mistake myself
 
Last edited:
Level 18
Joined
Sep 14, 2012
Messages
3,413
Even if you managed to find the solution I just wanted to suggest a proper FoG loop :
JASS:
local unit u 
local group g = CreateGroup()
call GroupEnumUnitsInRange(g, x, y, range, null)
loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
    // DO whatever you want to do
endloop
call DestroyGroup(g)
set g = null
//No need to set u to null since it is already null because of the exitwhen
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
A loop using FirstOfGroup should look like this
JASS:
        globals
            private group GROUP = CreateGroup()
        endglobals
JASS:
        local unit u
        /*
        *   Pick all units in range using coordinates (x and y)
        */
        call GroupEnumUnitsInRange(GROUP, x, y, aoe, null)
        loop
            set u = FirstOfGroup(GROUP)
            /*
            *   Will exit if the group is empty
            */
            exitwhen u == null
            call GroupRemoveUnit(GROUP, u)
            //code?
            
        endloop
 
Status
Not open for further replies.
Top