[JASS] The Script of Stun Aura why it doesnt works?

Status
Not open for further replies.
Level 4
Joined
Nov 3, 2004
Messages
79
This are the Script of my Stun Aura why it doesnt works? :(

function Trig_Stun_Aura_Conditions takes nothing returns boolean
if ( not ( GetLearnedSkillBJ() == 'A000' ) ) then
return false
endif
return true
endfunction

function Trig_Stun_loop_Actions takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit learn = GetLinkedUnit(t,"learn")
local group g
local location p
local unit u

set p = GetUnitLoc(learn)
set g = GetUnitsInRangeOfLocAll(800.00, p)
set u = FirstOfGroup(g)
loop
exitwhen u==null
set u = FirstOfGroup(g)
if IsUnitEnemy(u, GetOwningPlayer(learn))==true then
call GroupRemoveUnit(g,u)
set dumb = CreateUnitAtLoc(GetOwningPlayer(learn), ‘n000’, GetUnitLoc(u), 0.00)
call IssueTargetOrderBJ(dumb, “sleep”, u)
call UnitApplyTimedLifeBJ (1.50, ‘BTLF’, dumb)
set dumb = null
endif
endloop

set g = null
set u = null
set p = null
endfunction

function Trig_Stun_Aura_Actions takes nothing returns nothing
local unit learn
local timer t

set learn = GetLearningUnit()
set t = CreateTimer()
call StoreHandle(t,learn, "learn")
call TimerStart(t,4.00,true,function Trig_Stun_loop_Actions)
endfunction

//===========================================================================
function InitTrig_Stun_Aura takes nothing returns nothing
set gg_trg_Stun_Aura = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Stun_Aura, EVENT_PLAYER_HERO_SKILL )
call TriggerAddCondition( gg_trg_Stun_Aura, Condition( function Trig_Stun_Aura_Conditions ) )
call TriggerAddAction( gg_trg_Stun_Aura, function Trig_Stun_Aura_Actions )
endfunction
JASS:
 
Level 14
Joined
Nov 25, 2004
Messages
1,185
First change :

JASS:
if ( not ( GetLearnedSkillBJ() == 'A000' ) ) then 
return false 
endif 
return true

to :

JASS:
return GetLearnedSkillBJ() == 'A000'

Then you don't destroy the timer. But for your spell:

I think the problem is that group g should be created first :

JASS:
local group g = CreateGroup()
 
Level 4
Joined
Nov 3, 2004
Messages
79
mmmh it crashes my pc pls help! i dont know how to delete the Timer without that the Aura becoming useless pls help me. :cry:

function Trig_Stun_Aura_Conditions takes nothing returns boolean
return GetLearnedSkillBJ() == 'A000'
endfunction

function Trig_Stun_loop_Actions takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit learn = GetLinkedUnit(t,"learn")
local group g = CreateGroup()
local location p
local unit u
local unit dumb

set p = GetUnitLoc(learn)
set g = GetUnitsInRangeOfLocAll(800.00, p)
set u = FirstOfGroup(g)
loop
exitwhen u==null
set u = FirstOfGroup(g)
if IsUnitEnemy(u, GetOwningPlayer(learn))==true then
call GroupRemoveUnit(g,u)
set dumb = CreateUnitAtLoc(GetOwningPlayer(learn), ‘n000’, GetUnitLoc(u), 0.00)
call IssueTargetOrderBJ(dumb, "stormbolt", u)
call UnitApplyTimedLifeBJ (1.50, ‘BTLF’, dumb)
set dumb = null
endif
endloop
endfunction

function Trig_Stun_Aura_Actions takes nothing returns nothing
local unit learn
local timer t

set learn = GetLearningUnit()
set t = CreateTimer()
call StoreHandle(t,learn, "learn")
call TimerStart(t,4.00,true,function Trig_Stun_loop_Actions)
endfunction

//===========================================================================
function InitTrig_Stun_Aura takes nothing returns nothing
set gg_trg_Stun_Aura = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Stun_Aura, EVENT_PLAYER_HERO_SKILL )
call TriggerAddCondition( gg_trg_Stun_Aura, Condition( function Trig_Stun_Aura_Conditions ) )
call TriggerAddAction( gg_trg_Stun_Aura, function Trig_Stun_Aura_Actions )
endfunction
 
Level 3
Joined
Mar 27, 2004
Messages
70
I rewrote a lot of your code for you. I hope are ok with using the handle vars instead of whatever "GetLinkedUnit" was supposed to mean. You can get the Handle Var Functions here.

I couldn't test the code in WE since I don't have my Warcraft CD right now. I added comments where I made changes.
JASS:
function Trig_Stun_Aura_Conditions takes nothing returns boolean
    return GetLearnedSkillBJ() == 'A000'
endfunction

function Trig_Stun_loop_Actions takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit learn = GetHandleUnit(t, "learn") // !! CHANGED: Try using the handle vars instead
    local group g
    // !! REMOVED: local location p  ... not needed
    local unit u
    local unit dumb
    
    // !! ADDED: Checking to see if hero still exists
    if ( learn == null ) then
        // If the hero is gone, clean this up
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        return
    endif
    
    // !! ADDED: Checking to see if hero is alive
    if ( GetUnitState(learn, UNIT_STATE_LIFE)<=0 ) then
        return // Auras don't work while the hero is dead
    endif
    
    // !! REMOVED: set p = GetUnitLoc(learn) ... not needed
    // !! CHANGED: Using GroupEnumUnitsInRange instead.. doesn't use locations
    set g = CreateGroup()
    set g = GroupEnumUnitsInRange(g, GetUnitX(learn), GetUnitY(learn), 800.00, null)
    // !! REMOVED: set u = FirstOfGroup(g) .. not needed because of next change
    loop
        // !! CHANGED: set u = FirstOfGroup(g) moved up before exitwhen u==null... its just easier this way
        set u = FirstOfGroup(g)
        exitwhen u==null
        if IsUnitEnemy(u, GetOwningPlayer(learn)) then // !! CHANGED: ==true is not needed
            // !! CHANGED: Used CreateUnit instead of CreateUnitAtLoc, to prevent location from leaking
            set dumb = CreateUnit(GetOwningPlayer(learn), 'n000', GetUnitX(u), GetUnitY(u), 0.00)
            call IssueTargetOrderBJ(dumb, "stormbolt", u)
            call UnitApplyTimedLifeBJ (1.50, 'BTLF', dumb)
            set dumb = null
        endif
        // !! CHANGED: Don't forget to remove the unit from the group, even if its an ally
        // !! Otherwise this is an infinite loop if an allied unit is in the group
        call GroupRemoveUnit(g, u)
    endloop
    // !! ADDED: Cleaning up...
    call DestroyGroup(g)
endfunction

function Trig_Stun_Aura_Actions takes nothing returns nothing
    local unit learn
    local timer t

    set learn = GetLearningUnit()
    set t = CreateTimer()
    call SetHandleHandle(t, "learn", learn) // !! CHANGED: Using handle vars instead
    call TimerStart(t,4.00,true,function Trig_Stun_loop_Actions)
endfunction

//===========================================================================
function InitTrig_Stun_Aura takes nothing returns nothing
    set gg_trg_Stun_Aura = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stun_Aura, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition( gg_trg_Stun_Aura, Condition( function Trig_Stun_Aura_Conditions ) )
    call TriggerAddAction( gg_trg_Stun_Aura, function Trig_Stun_Aura_Actions )
endfunction

I can you understand my comments, it can be a mess reading other people's Jass code.
 
Level 4
Joined
Nov 3, 2004
Messages
79
function Trig_Stun_Aura_Conditions takes nothing returns boolean
return GetLearnedSkillBJ() == 'A000'
endfunction

function Trig_Stun_loop_Actions takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit learn = GetHandleUnit(t, "learn") // !! CHANGED: Try using the handle vars instead
local group g
// !! REMOVED: local location p ... not needed
local unit u
local unit dumb

// !! ADDED: Checking to see if hero still exists
if ( learn == null ) then
// If the hero is gone, clean this up
call FlushHandleLocals(t)
call DestroyTimer(t)
return
endif

// !! ADDED: Checking to see if hero is alive
if ( GetUnitState(learn, UNIT_STATE_LIFE)<=0 ) then
return // Auras don't work while the hero is dead
endif

// !! REMOVED: set p = GetUnitLoc(learn) ... not needed
// !! CHANGED: Using GroupEnumUnitsInRange instead.. doesn't use locations
set g = CreateGroup()
set g = It says this is a Type Conflict in command :shock: -----------> GroupEnumUnitsInRange(g, GetUnitX(learn), GetUnitY(learn), 800.00, null)
// !! REMOVED: set u = FirstOfGroup(g) .. not needed because of next change
loop
// !! CHANGED: set u = FirstOfGroup(g) moved up before exitwhen u==null... its just easier this way
set u = FirstOfGroup(g)
exitwhen u==null
if IsUnitEnemy(u, GetOwningPlayer(learn)) then // !! CHANGED: ==true is not needed
// !! CHANGED: Used CreateUnit instead of CreateUnitAtLoc, to prevent location from leaking
set dumb = CreateUnit(GetOwningPlayer(learn), 'n000', GetUnitX(u), GetUnitY(u), 0.00)
call IssueTargetOrderBJ(dumb, "stormbolt", u)
call UnitApplyTimedLifeBJ (1.50, 'BTLF', dumb)
set dumb = null
endif
// !! CHANGED: Don't forget to remove the unit from the group, even if its an ally
// !! Otherwise this is an infinite loop if an allied unit is in the group
call GroupRemoveUnit(g, u)
endloop
// !! ADDED: Cleaning up...
call DestroyGroup(g)
endfunction

function Trig_Stun_Aura_Actions takes nothing returns nothing
local unit learn
local timer t

set learn = GetLearningUnit()
set t = CreateTimer()
call SetHandleHandle(t, "learn", learn) // !! CHANGED: Using handle vars instead
call TimerStart(t,4.00,true,function Trig_Stun_loop_Actions)
endfunction

//===========================================================================
function InitTrig_Stun_Aura takes nothing returns nothing
set gg_trg_Stun_Aura = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Stun_Aura, EVENT_PLAYER_HERO_SKILL )
call TriggerAddCondition( gg_trg_Stun_Aura, Condition( function Trig_Stun_Aura_Conditions ) )
call TriggerAddAction( gg_trg_Stun_Aura, function Trig_Stun_Aura_Actions )
endfunction
 
Status
Not open for further replies.
Top