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

[JASS] Plasma Field

Status
Not open for further replies.
Level 7
Joined
Jul 3, 2011
Messages
251
Hey guys, im new to JASS and i want to make an ability like Razor's plasma field in DotA, i just dont understand why this is moving so slow.
JASS:
function Trig_JASS_Vers_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_JASS_Vers_Actions takes nothing returns nothing
    local unit Triggering_Unit = GetTriggerUnit()
    local integer Countdown = 80
    local real Distance_Forward = 0
    local real Distance_Back = 900
    local location Position_Of_Warden = GetUnitLoc(GetTriggerUnit())
    local location Dummies_Position
    local unit array Dummies
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call CreateNUnitsAtLoc( 1, 'h001', GetOwningPlayer(GetTriggerUnit()), Position_Of_Warden, bj_UNIT_FACING )
        call UnitApplyTimedLifeBJ( 4.00, 'BTLF', GetLastCreatedUnit() )
        set Dummies[GetForLoopIndexA()] = GetLastCreatedUnit()
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    loop
        exitwhen Distance_Forward == 900
        set Position_Of_Warden = GetUnitLoc(Triggering_Unit)
        set Distance_Forward = ( Distance_Forward + 25.00 )
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set Dummies_Position = PolarProjectionBJ(Position_Of_Warden, Distance_Forward, ( 36.00 * I2R(GetForLoopIndexA()) ))
        call SetUnitPositionLoc( Dummies[GetForLoopIndexA()], Dummies_Position )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
        call TriggerSleepAction( 0.03 )
    endloop
        
endfunction

//===========================================================================
function InitTrig_JASS_Vers takes nothing returns nothing
    set gg_trg_JASS_Vers = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Vers, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_JASS_Vers, Condition( function Trig_JASS_Vers_Conditions ) )
    call TriggerAddAction( gg_trg_JASS_Vers, function Trig_JASS_Vers_Actions )
endfunction

I know that it is leaking and that i have variables that im not using, i fix leaks after making the spell and i want to speed the spell up before making the rest.
 
Last edited:
Level 4
Joined
Mar 27, 2008
Messages
112
This looks like converted GUI you should use local vars instead of bj_forloop... and update your condition to look like this:
function condition ...
return GetSpellAbilityId() == 'yourid'
endfunction
 
Level 7
Joined
Jul 3, 2011
Messages
251
This looks like converted GUI you should use local vars instead of bj_forloop... and update your condition to look like this:
function condition ...
return GetSpellAbilityId() == 'yourid'
endfunction

But when i change the return function it errors and the entire thing won't work, also i tried using local vars but the spell worked even less than before, now just 1 dummy moves out. My spell worked fine before, its just that it moves far too slow, and i don't know how to speed it up.
 
Level 4
Joined
Mar 27, 2008
Messages
112
Try this cleaned up your code. Btw you shouldn't use TriggerSleepAction in your loop you should use timers and vJass if you want it done well. Didn't know if you used newgen so didn't use vjass.
JASS:
function Trig_JASS_Vers_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Trig_JASS_Vers_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local location DummyPos
    local location Pos = GetUnitLoc(u)
    local unit array Dummies
    local player p = GetOwningPlayer(u)
    local integer i = 0
    local integer i2 = 0
    loop
        set i = i + 1
        set Dummies[i] == CreateUnit(p,'h001',x,y,bj_UNIT_FACING)
        call UnitApplyTimedLife(Dummies[i],'BTLF',4)
        exitwhen i == 10
    endloop
    set i = 0 
    loop
        set i = i + 25
        loop
            set i2 = i2 + 1
            set DummyPos = PolarProjectionBJ(Pos, i, ( 36.00 * I2R(i2) ))
            call SetUnitPositionLoc( Dummies[i2], DummyPos )
            call RemoveLocation(DummyPos)//thought this is needed not 100% sure
            exitwhen i2 == 10
        endloop
        exitwhen i == 900
        call TriggerSleepAction( 0.03 )
    endloop
        set u = null
        set DummyPos = 0
        call RemoveLocation(Pos)
        set Pos = null
endfunction

//===========================================================================
function InitTrig_JASS_Vers takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( t, Condition( function Trig_JASS_Vers_Conditions ) )
    call TriggerAddAction( t, function Trig_JASS_Vers_Actions )
    set t = null
endfunction
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
Why:
call TriggerSleepAction( 0.03 ) if there are timers in jass.

Avoid locations in jass, since reals are faster.
call SetUnitPositionLoc( Dummies[i2], DummyPos ) can be replaced by:
JASS:
native          SetUnitPosition     takes unit whichUnit, real newX, real newY returns nothing
local location Pos = GetUnitLoc(u) isn't realy needed since you already set coordinates:
JASS:
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
 
Last edited:
Level 7
Joined
Jul 3, 2011
Messages
251
Try this cleaned up your code. Btw you shouldn't use TriggerSleepAction in your loop you should use timers and vJass if you want it done well. Didn't know if you used newgen so didn't use vjass.
JASS:
function Trig_JASS_Vers_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Trig_JASS_Vers_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local location DummyPos
    local location Pos = GetUnitLoc(u)
    local unit array Dummies
    local player p = GetOwningPlayer(u)
    local integer i = 0
    local integer i2 = 0
    loop
        set i = i + 1
        set Dummies[i] == CreateUnit(p,'h001',x,y,bj_UNIT_FACING)
        call UnitApplyTimedLife(Dummies[i],'BTLF',4)
        exitwhen i == 10
    endloop
    set i = 0 
    loop
        set i = i + 25
        loop
            set i2 = i2 + 1
            set DummyPos = PolarProjectionBJ(Pos, i, ( 36.00 * I2R(i2) ))
            call SetUnitPositionLoc( Dummies[i2], DummyPos )
            call RemoveLocation(DummyPos)//thought this is needed not 100% sure
            exitwhen i2 == 10
        endloop
        exitwhen i == 900
        call TriggerSleepAction( 0.03 )
    endloop
        set u = null
        set DummyPos = 0
        call RemoveLocation(Pos)
        set Pos = null
endfunction

//===========================================================================
function InitTrig_JASS_Vers takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( t, Condition( function Trig_JASS_Vers_Conditions ) )
    call TriggerAddAction( t, function Trig_JASS_Vers_Actions )
    set t = null
endfunction

It doesn't work, the dummies are created in a circle around the caster but they wont move even once.
 
Last edited:
Status
Not open for further replies.
Top