• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Need help on spell

Status
Not open for further replies.
Level 5
Joined
Apr 12, 2009
Messages
125
I need help with a location variable

locOffset need's to be an array, how to fix? And what should I type after the equal?

JASS:
function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(GetTriggerUnit())
    local real r = 0.00
    local integer i = 0
    local location locOffset = WTF  // ... = what?  

    loop
        exitwhen i <= 8
        call CreateNUnitsAtLoc( 1, 'hfoo', GetOwningPlayer(c), casloc, 270)
        set locOffset[GetForLoopIndexA()] = PolarProjectionBJ( casloc, 700.00, r)
        call IssuePointOrderLoc ( GetLastCreatedUnit(), "flamestrike", locOffset[GetForLoopIndexA()] )
        set r = ( r + ( 360.00 / 8.00 ) )
        set i = i + 1
    endloop
endfunction
 
Level 5
Joined
Apr 12, 2009
Messages
125
JASS:
local location array locOffset

and use :
JASS:
set locOffset[i] = //stuff...

JASS:
GetForLoopIndexA()
doesnt work in this case.. it's not getting raised.

Thx, but I can't still get the trigger working. Can you/someone see the problem?

Im trying to create a simpel NOVA spell. But the units wont be created :S

JASS:
function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(c)
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local location array locOffset
      
    loop
        exitwhen i <= 8
        call CreateNUnitsAtLoc( 1, 'hfoo', GetOwningPlayer(c), casloc, 270)
        set locOffset[i] = PolarProjectionBJ( casloc, 700.00, r)
        call IssuePointOrderLoc ( GetLastCreatedUnit(), "flamestrike", locOffset[i] )
        set r = ( r + ( 360.00 / 8.00 ) )
        set i = i + 1
    endloop
endfunction
 
Level 9
Joined
Aug 21, 2008
Messages
533
first of all: you dont need an array. :
JASS:
    set locOffset= PolarProjectionBJ( casloc, 700.00, r)
i enough cause you never need the loc again(i mean after the flamestrike)

then:
CreateNUnitsatLoc
lol wy? you only create 1 unit. use this:
CreateUnitAtLoc

Try it again then
 
hmm...



are you sure that the units dont get created or they just don't cast the spell... if they just don't cast then maybe they have the locust ability, units with locust ability seems to bug with GetLastCreatedUnit()..... try this..

JASS:
function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(c)
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local integer p = GetPlayerNumber(GetOwningPlayer(c)) //to save function calls and so that we can recycle the unit variable c... I'm not sure if GetPlayerNumber is the right function...
    local location locOffset
    loop
        exitwhen i >= 8
         set c = CreateNUnitsAtLoc( 1, 'hfoo', p, casloc, 270) //I haven't changed this to CreateUnit becuase I'm pretty sure something is changed in the order of the parameters and I'm not in my editor right now and I cannot recall the order of the parameters...
         set locOffset = PolarProjectionBJ( casloc, 700.00, r)
         call IssuePointOrderLoc ( c, "flamestrike", locOffset)
         set r = ( r + ( 360.00 / 8.00 ) )
         set i = i + 1
         call RemoveLocation(locOffset) //leak removal
    endloop
endfunction
//leak removal
call RemoveLocation(casloc)
set p = null
set casloc = null
set locOffset = null
set p = null //not sure of this one...
 
Last edited:
JASS:
exitwhen i <= 8
Shouldn't it be >= 8?
Besides get rid of locations, there are enough ways to use coordinates.

oh right... haven't noticed, so maybe that's why the units don't get created, because the loop exits during the first run... well he uses PolarProjectionBJ so he needs location... I'm not with my WE now so I can't modify it to use coordinates.....
 
Level 5
Joined
Apr 12, 2009
Messages
125
hmm...



are you sure that the units dont get created or they just don't cast the spell... if they just don't cast then maybe they have the locust ability, units with locust ability seems to bug with GetLastCreatedUnit()..... try this..

JASS:
function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(c)
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local integer p = GetPlayerNumber(GetOwningPlayer(c)) //to save function calls and so that we can recycle the unit variable c... I'm not sure if GetPlayerNumber is the right function...
    local location locOffset
    loop
        exitwhen i >= 8
         set c = CreateNUnitsAtLoc( 1, 'hfoo', p, casloc, 270) //I haven't changed this to CreateUnit becuase I'm pretty sure something is changed in the order of the parameters and I'm not in my editor right now and I cannot recall the order of the parameters...
         set locOffset = PolarProjectionBJ( casloc, 700.00, r)
         call IssuePointOrderLoc ( c, "flamestrike", locOffset)
         set r = ( r + ( 360.00 / 8.00 ) )
         set i = i + 1
         call RemoveLocation(locOffset)
    endloop
endfunction
//leak removal
call RemoveLocation(casloc)
set p = null
set casloc = null
set locOffset = null
set p = null //not sure of this one...

Hmm, I think it's the loop which is wrong...

It works if I don't use loop, but then it creates only 1 unit. Yeye, this is what i've this far.

No, its not the locust hehe ;)

JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'AHtc'
endfunction
//===========================================================================

function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(c)
    local location locOffset
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local integer pe = [--ERROR--](GetOwningPlayer(c)) //  GetPlayerNumber doesn't exist at all. 

    loop
        exitwhen i <= 8
         call CreateUnitAtLoc(GetOwningPlayer(c), 'hrif', casloc, r)
         set locOffset = PolarProjectionBJ( casloc, 700.00, r)
         call IssuePointOrderLoc ( c, "flamestrike", locOffset)
         set r = ( r + ( 360.00 / 8.00 ) )
         set i = i + 1
         call RemoveLocation(locOffset) //leak removal
    endloop

call RemoveLocation(casloc)
set p = null
set casloc = null
set locOffset = null

endfunction

//===========================================================================
function InitTrig_t takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(t, function coolspell)
endfunction


EDIT Yeah, the loop was the problem :p, but I'm testing it now
 
Hmm, I think it's the loop which is wrong...

It works if I don't use loop, but then it creates only 1 unit. Yeye, this is what i've this far.

No, its not the locust hehe ;)

JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'AHtc'
endfunction
//===========================================================================

function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(c)
    local location locOffset
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local integer pe = GetPlayerId(GetOwningPlayer(c)) //to save function calls and so that we can recycle the unit variable c... I'm not sure if GetPlayerNumber is the right function...

    loop
        exitwhen i <= 8
         call CreateUnitAtLoc(GetOwningPlayer(c), 'hrif', casloc, r)
         set locOffset = PolarProjectionBJ( casloc, 700.00, r)
         call IssuePointOrderLoc ( c, "flamestrike", locOffset)
         set r = ( r + ( 360.00 / 8.00 ) )
         set i = i + 1
         call RemoveLocation(locOffset) //leak removal
    endloop

call RemoveLocation(casloc)
set p = null
set casloc = null
set locOffset = null

endfunction

//===========================================================================
function InitTrig_t takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(t, function coolspell)
endfunction

it looks like because we use exitwhen i <= 8 which is always true right from the start because i = 0 so the loop terminates right at the start... I edited the code I posted... and for the place were you put ERROR, I said that I'm not sure if that's the right function.... not with my WE right now.. sorry.
 
Level 5
Joined
Apr 12, 2009
Messages
125
JASS:
exitwhen i <= 8
Shouldn't it be >= 8?
Besides get rid of locations, there are enough ways to use coordinates.

oh right... haven't noticed, so maybe that's why the units don't get created, because the loop exits during the first run... well he uses PolarProjectionBJ so he needs location... I'm not with my WE now so I can't modify it to use coordinates.....

Ye ye guys, everything is working but;

JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'AHtc'
endfunction
//===========================================================================

function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location casloc = GetUnitLoc(c)
    local location locOffset
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local integer pe = GetPlayerId(GetOwningPlayer(c)) //Not here, some lines down  
   
    loop
        exitwhen i >= 8
         call CreateUnitAtLoc(GetOwningPlayer(c), 'hrif', casloc, r)
         set locOffset = PolarProjectionBJ( casloc, 700.00, r)
         call IssuePointOrderLoc ( [WHAT SHOULD IT BE HERE???], "flamestrike", locOffset) // What should i type in? LastCreatedUnit doesen't exist"
         set r = ( r + ( 360.00 / 8.00 ) )
         set i = i + 1
         call RemoveLocation(locOffset)
    endloop

call RemoveLocation(casloc)
set p = null
set casloc = null
set locOffset = null

endfunction

//===========================================================================
function InitTrig_t takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(t, function coolspell)
endfunction
 
Level 11
Joined
Apr 29, 2007
Messages
826
JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'AHtc'
endfunction
//===========================================================================

function coolspell takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit u
    local location casloc = GetUnitLoc(c)
    local location locOffset
    local player p = GetTriggerPlayer()
    local real r = 0.00
    local integer i = 0
    local integer pe = GetPlayerId(GetOwningPlayer(c)) //Not here, some lines down

    loop
        exitwhen i >= 8
         set u = CreateUnitAtLoc(GetOwningPlayer(c), 'hrif', casloc, r)
         set locOffset = PolarProjectionBJ( casloc, 700.00, r)
         call IssuePointOrderLoc ( u, "flamestrike", locOffset) // What should i type in? LastCreatedUnit doesen't exist"
         set r = ( r + ( 360.00 / 8.00 ) )
         set i = i + 1
         call RemoveLocation(locOffset)
    endloop

    call RemoveLocation(casloc)
    set p = null
    set casloc = null
    set locOffset = null
    set c = null
    set u = null

endfunction

//===========================================================================
function InitTrig_t takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(t, function coolspell)
endfunction

You should null unit variables.
 
Status
Not open for further replies.
Top