• 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] Issue with movement/instancing again

Status
Not open for further replies.
Level 4
Joined
Sep 25, 2005
Messages
71
EDIT: For the most part I fixed this. Anyways, the tl;dr is this spell is supposed to create a fireball that moves towards the target when the spell is cast. It functions, however, with a high number of simultaneous casts occasionally a dummy is left behind. Is there some issue in my instancing I can't see?

JASS:
globals
    timer fireballTimer = CreateTimer()
    real fireballInterval = .015
    integer activeFireballs = 0
    fireballData array fireballArray
endglobals

struct fireballData
    unit caster
    unit dummy
    real angle
    real x
    real y
    real speed
    real maxDist
    real distance
endstruct

function fireballExecution takes nothing returns nothing
    local integer i = 0
    local real x = 0.
    local real y = 0.
    local effect smoke
    
    local fireballData localFireball = fireballData.create()
    

    loop
        exitwhen i >= activeFireballs
        
        
        set localFireball = fireballArray[i]
        set x = GetUnitX(localFireball.dummy) + localFireball.speed * Cos(localFireball.angle * bj_DEGTORAD)
        set y = GetUnitY(localFireball.dummy) + localFireball.speed * Sin(localFireball.angle * bj_DEGTORAD)
        
        call SetUnitBoundedX(localFireball.dummy, x)
        call SetUnitBoundedY(localFireball.dummy, y)
        
        set localFireball.distance = localFireball.distance + localFireball.speed
        
        set smoke = AddSpecialEffect("Abilities\\Spells\\Human\\FlakCannons\\FlakTarget.mdl", x, y)
               
        if localFireball.distance >= localFireball.maxDist then

            call KillUnit(localFireball.dummy)
            set activeFireballs = activeFireballs - 1
            set fireballArray[i] = fireballArray[activeFireballs]
            
            call localFireball.destroy()
            
        endif
        
        call DestroyEffect(smoke)
        set smoke = null
        set i = i + 1
    endloop
    
    if activeFireballs == 0 then
        call PauseTimer(fireballTimer)
    endif
    
endfunction

function activatedFireball takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit fireball
    local player casterOwner = GetOwningPlayer(GetTriggerUnit())
    local fireballData localFireball = fireballData.create()
    
    set fireball = CreateUnit(casterOwner, 'o003', GetUnitX(caster), GetUnitY(caster), GetUnitFacing(caster))
    call UnitApplyTimedLife(fireball, 'B001', .9)
    call SetUnitPathing(fireball, false)
    set localFireball.caster = caster
    set localFireball.dummy = fireball
    set localFireball.angle = GetUnitFacing(caster)
    set localFireball.x = GetUnitX(caster)
    set localFireball.y = GetUnitY(caster)
    set localFireball.speed = 33.
    set localFireball.maxDist = 700.
    set localFireball.distance = 0.
    set fireballArray[activeFireballs] = localFireball
    
    if activeFireballs <= 0 then
        call TimerStart(fireballTimer, fireballInterval, true, function fireballExecution)
    endif
    
    set activeFireballs = activeFireballs + 1
    
    set caster = null
    set fireball = null
    set casterOwner = null
    call localFireball.destroy()
    
endfunction

function checkFireball takes nothing returns boolean
    if GetSpellAbilityId() == 'A005' then
        call activatedFireball()
    endif
    return false
endfunction

function InitTrig_Fireball takes nothing returns nothing
    local trigger localTrigVar = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( localTrigVar, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( localTrigVar, Condition( function checkFireball ) )
    set localTrigVar = null
endfunction
 

Attachments

  • MvMAbilityDump.w3x
    26.4 KB · Views: 48
Last edited:
You have a few issues:

  1. in activated fireball function you have call LocalFireball.destroy() , remove this line.
  2. in fireball execution function you have local FireballData LocalFireball = fireballData.create(). remove the =... part

you have other imperfections but these are the only issuesican see on my mobile device which will ruin the script.

let me know if this solves the issues and we can talk about other improvements.
 
Status
Not open for further replies.
Top