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

[Trigger] Am I doing something wrong?

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I'm making a missle spell and I can't get it to do damage when the missle comes close to a unit.

JASS:
scope Missle initializer Init

globals
    private constant real INTERVAL = 0.04
    private constant string EFFECT ="Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl"
    private constant integer DUMMY_ID = 'h000'
    private constant attacktype ATTACK_TYPE = ATTACK_TYPE_CHAOS
    private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
    private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
    private timer T = CreateTimer()
    private rect re
    private boolexpr B
endglobals

private function DAMAGE takes integer level returns real
    return I2R(50 + level * 75)
endfunction

private function Damage_Filter takes nothing returns boolean
    return (IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false) and (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.415) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false)
endfunction

struct Missle
    unit missle
    real cos
    real sin
    real d
    real r
    integer count
    integer lvl
    group g
    player o
    static Missle array Index
    static integer Total = 0
    
    static method Loop takes nothing returns nothing
        local integer i = 0
        local unit u
        local real x
        local real y
        local Missle m
        loop
            exitwhen i >= Missle.Total
            set m = Missle.Index[i]
            set m.count = m.count - 1
            set x = GetUnitX(m.missle) + m.d * m.cos
            set y = GetUnitY(m.missle) + m.d * m.sin
            if CheckPathability(x, y) then
                call SetUnitX(m.missle, x)
                call SetUnitY(m.missle, y)
            else
            call DestroyEffect(AddSpecialEffect(EFFECT, x, y))
            endif
            set re = Rect(x - m.r, y - m.r, x + m.r, y + m.r)
            call GroupEnumUnitsInRect(m.g, re, B)
            loop
                set u = FirstOfGroup(m.g)
                exitwhen u == null
                if IsUnitEnemy(u, m.o) then
                    call RemoveUnit(m.missle)
                    call DestroyEffect(AddSpecialEffect(EFFECT, x, y))
                    call UnitDamageTarget(m.missle, u, DAMAGE(m.lvl), false, true, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
                else
                call GroupRemoveUnit(m.g, u)
                endif
            endloop
            if GetUnitState(m.missle, UNIT_STATE_LIFE) <= 0.415 then
                set Missle.Total = Missle.Total - 1
                set Missle.Index[i] = Missle.Index[Missle.Total]
                call m.destroy()
            elseif m.count == 0 or not CheckPathability(x, y) then
            set Missle.Total = Missle.Total - 1
            set Missle.Index[i] = Missle.Index[Missle.Total]
            call KillUnit(m.missle)
            call RemoveUnit(m.missle)
            call DestroyEffect(AddSpecialEffect(EFFECT, x, y))
            call m.destroy()
            endif
            set i = i + 1
        endloop
        if Missle.Total == 0 then
            call PauseTimer(T)
        endif
    endmethod
    
    static method Start takes unit caster, real distance, real angle, real time, real radius, integer level returns nothing
        local Missle m = Missle.allocate()
        set m.count = R2I(time / INTERVAL)
        set m.missle = CreateUnit(GetOwningPlayer(caster), DUMMY_ID, GetUnitX(caster), GetUnitY(caster), angle)
        set m.d = 2 * distance / ( m.count + 1)
        set m.cos = Cos(angle * bj_DEGTORAD)
        set m.sin = Sin(angle * bj_DEGTORAD)
        set m.r = radius
        set m.o = GetOwningPlayer(caster)
        set m.lvl = level
        if Missle.Total == 0 then
            call TimerStart(T, INTERVAL, true, function Missle.Loop)
        endif
        set Missle.Index[Missle.Total] = m
        set Missle.Total = Missle.Total + 1
    endmethod
endstruct

private function Init takes nothing returns nothing
    set B = Filter(function Damage_Filter)
endfunction

endscope

JASS:
set re = Rect(x - m.r, y - m.r, x + m.r, y + m.r)
            call GroupEnumUnitsInRect(m.g, re, B)
            loop
                set u = FirstOfGroup(m.g)
                exitwhen u == null
                if IsUnitEnemy(u, m.o) then
                    call RemoveUnit(m.missle)
                    call DestroyEffect(AddSpecialEffect(EFFECT, x, y))
                    call UnitDamageTarget(m.missle, u, DAMAGE(m.lvl), false, true, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
                else
                call GroupRemoveUnit(m.g, u)
                endif

Thanks in advance!
 
Level 8
Joined
Jul 28, 2008
Messages
211
Wow yet another stupid mistake. Made 2 yesterday (didn't set .Total to 0 and stuff). Always happens. Thanks.

I think you confused the 2 triggers..the one that says damage part is the whole code and vise versa...
Yea and I think I made a mistake by putting Trigger instead of JASS. Actualy I was in a hurry so it doesn't suprise me.

EDIT: It does appear to hit a unit now. The funny thing is what happened...

Warcraft crashed a few seconds after I took the picture.
 

Attachments

  • LOL.jpg
    LOL.jpg
    182.9 KB · Views: 67
Last edited:
Level 8
Joined
Jul 28, 2008
Messages
211
Made the radius smaller (it was kinda hard to hit the unit) and it still lagger ALOT but at least it didn't crash. I think that a loop somewhere loops more times than I want cuz it killed a footman in 1 hit and it should deal only 125 damage (I think).

EDIT: There's something wrong with the grouping and stuff. I tried casting the spell again after that massive lag, and I saw the same effect from that screenshot on a wisp that's not even near the footman I hit with the spell.
 
Status
Not open for further replies.
Top