• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Any know what happens?

Status
Not open for further replies.
Level 8
Joined
Dec 30, 2011
Messages
134
I'm new on vJASS and I'm working on it to understand, but I have a problem and I don't know what is the solution!
JASS:
scope FoTK initializer Init
//**************************************************************************
//Start of setup
//**************************************************************************
globals
    constant integer abilityHero    = 'A000'//Rawcode of the hero ability
    constant integer abilitySlow    = 'A001'//Rawcode of the slow ability
    constant integer dummyCaster    = 'u001'//Rawcode of the missile dummy
    constant integer dummyMissile   = 'u000'//Rawcode of the caster dummy
    constant string slowOrderString = "slow"//String order of the slow ability
    constant attacktype attackType  = ATTACK_TYPE_NORMAL//Attack type of the damage
    constant damagetype damageType  = DAMAGE_TYPE_NORMAL//Damage type of the damage
    constant weapontype weaponType  = WEAPON_TYPE_WHOKNOWS//Weapon type of the damage
    constant string specialEffect   = "Abilities\\Weapons\\snapMissile\\snapMissile.mdl"//Special effect that appears when the knives hits the enemies
    constant real interval          = 0.03125//Interval of the spell
    constant real speed             = 18//Movement speed of the knives
endglobals

private function Damage takes integer level returns real
//Returns the value of the damage each level. Default: 120. + 30. * level (Level 1 = 120 | Level 2 = 150 | Level 3 = 180 | Level 4 = 210)
    return 90. + 30. * level
endfunction

private function AreaOfEffect takes integer level returns real
//Returns the area of effect of the spell. Default: 275. + 25. * level (Level 1 = 300 | Level 2 = 325 | Level 3 = 350 - Level 4 = 375)
    return 275. + 25. * level
endfunction
//**************************************************************************
//End of setup
//**************************************************************************
struct KoTS
    unit c
    unit d
    unit t
    integer level
endstruct

globals
    timer tr = CreateTimer()
    KoTS array ar
    integer total = 0
endglobals

private function Timer takes nothing returns nothing
    local KoTS k
    local unit d
    local integer i = 0
    local real x
    local real y
    local real x1
    local real y1
    local real angle
    loop
    exitwhen i >= total
        set k = ar[i]
        set x = GetUnitX(k.d)
        set y = GetUnitY(k.d)
        set x1 = GetUnitX(k.t)
        set y1 = GetUnitY(k.t)
        if DistanceBetweenPoints(Location(x, y), Location(x1, y1)) > 50 then//I'm going change it when I solve the problem
            set angle = bj_RADTODEG * Atan2(y1 - y, x1 - x)
            call SetUnitX(k.d, x + 20 * Cos(bj_DEGTORAD * angle))
            call SetUnitY(k.d, y + 20 * Sin(bj_DEGTORAD * angle))
            call SetUnitFacing(k.d, angle)
        else
            call UnitDamageTarget(k.c, k.t, Damage(k.level), true, false, attackType, damageType, weaponType)
            call DestroyEffect(AddSpecialEffect(specialEffect, x1, y1))
            set d = CreateUnit(GetOwningPlayer(k.c), dummyCaster, x1, y1, 0)
            call UnitAddAbility(d, abilitySlow)
            call SetUnitAbilityLevel(d, abilitySlow, k.level)
            call IssueTargetOrder(d, slowOrderString, k.t)
            call UnitApplyTimedLife(d, 'BTLF', 0.5)
            call SetUnitExploded(k.d, true)
            call KillUnit(k.d)
            set ar[i] = ar[total - 1]
            set total = total - 1
            call k.destroy()
            set d = null
        endif
        set i = i + 1
    endloop
    if total == 0 then
        call PauseTimer(tr)
    endif
endfunction

private function Conditions takes nothing returns boolean
    local unit u
    local integer level
    local real x
    local real y
    local real x1
    local real y1
    local real angle
    local group g
    local unit d
    local unit j
    local player p
    local KoTS k
    if GetSpellAbilityId() == abilityHero then
        set u = GetTriggerUnit()
        set x = GetUnitX(u)
        set y = GetUnitY(u)
        set g = CreateGroup()
        set p = GetOwningPlayer(u)
        set level = GetUnitAbilityLevel(u, abilityHero)
        set k = k.create()
        set k.c = u
        call GroupEnumUnitsInRange(g, x, y, AreaOfEffect(level), null)
        loop
            set j = FirstOfGroup(g)
        exitwhen j == null
            call GroupRemoveUnit(g, j)
            if not IsUnitType(j, UNIT_TYPE_DEAD) and IsUnitEnemy(j, p) and not IsUnitType(j, UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(j, UNIT_TYPE_STRUCTURE) then
                set x1 = GetUnitX(j)
                set y1 = GetUnitY(j)
                set angle = bj_RADTODEG * Atan2(y1 - y, x1 - x)
                set k.d = CreateUnit(p, dummyMissile, x + 50 * Cos(bj_DEGTORAD * angle), y + 50 * Sin(bj_DEGTORAD * angle), angle)
                set k.t = j
                set k.level = level
                if total == 0 then
                    call TimerStart(tr, interval, true, function Timer)
                endif
                set total = total + 1
                set ar[total - 1] = k
            endif
        endloop
        call DestroyGroup(g)
        set u = null
    endif
    return false
endfunction

private function Init takes nothing returns nothing
    local unit u = CreateUnit(Player(0), dummyCaster, 0, 0, 0)
    local trigger FoTK = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(FoTK, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(FoTK, Condition(function Conditions))
    call UnitAddAbility(u, abilitySlow)
    call UnitAddAbility(u, abilityHero)
    call RemoveUnit(u)
    set u = null
    call Preload(specialEffect)
endfunction

endscope

When I cast the ability the dummies doesn't moves and check only 1 of all created! CAN ANYONE HELPME ? PLEASE

:goblin_cry:
 
Level 4
Joined
Apr 7, 2012
Messages
63
I'll come check again later,but make sure your globals are correct,and the timer.I just scanned through now.But will check later again.
 
Save DistanceBetweenPoints() to a real and then change this:

JASS:
        if DistanceBetweenPoints(Location(x, y), Location(x1, y1)) > 50 then//I'm going change it when I solve the problem
            set angle = bj_RADTODEG * Atan2(y1 - y, x1 - x)
            call SetUnitX(k.d, x + 20 * Cos(bj_DEGTORAD * angle))
            call SetUnitY(k.d, y + 20 * Sin(bj_DEGTORAD * angle))
            call SetUnitFacing(k.d, angle)

to this:

JASS:
        call BJDebugMsg(R2S(dist))
        if dist > 50 then//I'm going change it when I solve the problem
            call BJDebugMsg("worked")
            set angle = bj_RADTODEG * Atan2(y1 - y, x1 - x)
            call SetUnitX(k.d, x + 20 * Cos(bj_DEGTORAD * angle))
            call SetUnitY(k.d, y + 20 * Sin(bj_DEGTORAD * angle))
            call SetUnitFacing(k.d, angle)

Find out what happens.

By the way you need to be a lot more deliberate than this:

JASS:
    unit c
    unit d
    unit t
    integer level

Obfuscated code is terrible when people are trying to help you. I'd much rather have a ridiculously long name like "castingUnitWhoDamages" and "temporaryDummyRemoveAfter" than "c" and "d"
 
Status
Not open for further replies.
Top