• 🏆 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] Trigger Not Working );

Status
Not open for further replies.
I don't know a lot about jass, I have been trying to learn it for a while but have been mostly unsucsessful. I wrote this trigger that is supposed to make unit's spinn around the target, but it doesn't work.
JASS:
globals
constant integer OOP_SpellID = 'A000'
constant integer OOP_DummyID = 'hpea'
constant real OOP_IdealDistance = 300.
constant real OOP_MoveSpeed = 15.
constant real OOP_TurnSpeed = 10
unit array OOP_Dummy
unit array OOP_Dummy_Target
integer array OOP_DummySlotFilled
group OOP_DummyGroup
endglobals

function OOP_MoveOrbs takes nothing returns nothing
local group g = OOP_DummyGroup
local unit temp
local integer i
local location targetPoint
local location dummyPoint
local real angle
local real angle2
local real distance
local real Xdistance
local real Ydistance
local real nudistance
local location nuPoint
call BJDebugMsg("I have pancakes")
    loop
    exitwhen CountUnitsInGroup(g) == 0
    set i = 0
    set temp = FirstOfGroup(g)
        loop
        exitwhen temp == OOP_Dummy[i]
        set i = (i+1)
        endloop
    set dummyPoint = GetUnitLoc(temp)
    set targetPoint = GetUnitLoc(OOP_Dummy_Target[i])
    set angle = AngleBetweenPoints(targetPoint,dummyPoint)
    set Xdistance = (GetLocationX(targetPoint)-GetLocationX(dummyPoint))
    set Ydistance = (GetLocationY(targetPoint)-GetLocationY(dummyPoint))
    set distance =  SquareRoot((Xdistance * Xdistance) + (Ydistance * Ydistance))
    if distance < OOP_IdealDistance then
        set nudistance = distance+OOP_MoveSpeed
        else
        set nudistance = distance - OOP_MoveSpeed
        endif
    set angle2=angle+OOP_TurnSpeed
    set nuPoint = PolarProjectionBJ( targetPoint, nudistance, angle2 )
    call SetUnitX(temp, GetLocationX(nuPoint))
    call SetUnitY(temp, GetLocationY(nuPoint))
//CLEANING UP-------------------------------------------------------------
    call RemoveLocation(dummyPoint)
    call RemoveLocation(targetPoint)
    call RemoveLocation(nuPoint)
    set temp = null
    endloop
endfunction

function OOP_UnitRecycle takes unit temp, unit target returns nothing
local integer i = 0
loop
exitwhen OOP_DummySlotFilled[i] == 0
set i = (i+1)
endloop
set OOP_Dummy[i] = temp
set OOP_Dummy_Target[i] = target
set OOP_DummySlotFilled[i] = 1
call GroupAddUnit( OOP_DummyGroup, temp)
endfunction

function Trig_Orbs_Of_Protection_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == OOP_SpellID ) ) then
        return false
    endif
    return true
endfunction

function OOP_CastTrig takes nothing returns nothing
local unit target = GetSpellTargetUnit()
local location tpoint = GetUnitLoc(target)
local unit dummy = CreateUnitAtLoc( GetOwningPlayer(GetSpellTargetUnit()), OOP_DummyID, tpoint, 0.)
call OOP_UnitRecycle( dummy, target)
endfunction

//===========================================================================
function InitTrig_Orbs_Of_Protection takes nothing returns nothing
    local trigger gg_trg_Orbs_Of_Protection = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic( gg_trg_Orbs_Of_Protection, 0.03 )
    call TriggerAddAction( gg_trg_Orbs_Of_Protection, function OOP_MoveOrbs )
    //---------------------------------------------------------------------------------------------------------------
    set gg_trg_Orbs_Of_Protection = null
    set gg_trg_Orbs_Of_Protection = CreateTrigger()
    //---------------------------------------------------------------------------------------------------------------
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Orbs_Of_Protection, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Orbs_Of_Protection, Condition( function Trig_Orbs_Of_Protection_Conditions ) )
    call TriggerAddAction( gg_trg_Orbs_Of_Protection, function OOP_CastTrig )
endfunction
I need help.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
There are a couple problems. Firstly, in your InitTrig:
JASS:
function InitTrig_Orbs_Of_Protection takes nothing returns nothing
    local trigger gg_trg_Orbs_Of_Protection = CreateTrigger() // O NO YOU DI'NT!
    call TriggerRegisterTimerEventPeriodic( gg_trg_Orbs_Of_Protection, 0.03 )
    call TriggerAddAction( gg_trg_Orbs_Of_Protection, function OOP_MoveOrbs )
    //---------------------------------------------------------------------------------------------------------------
    set gg_trg_Orbs_Of_Protection = null
    set gg_trg_Orbs_Of_Protection = CreateTrigger()
    //---------------------------------------------------------------------------------------------------------------
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Orbs_Of_Protection, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Orbs_Of_Protection, Condition( function Trig_Orbs_Of_Protection_Conditions ) )
    call TriggerAddAction( gg_trg_Orbs_Of_Protection, function OOP_CastTrig )
endfunction
Did you just make a local variable with the same name as a compiler generated global? Uh oh, bad idea. Here's what you should do instead:
JASS:
function InitTrig_Orbs_Of_Protection takes nothing returns nothing
    set gg_trg_Orbs_Of_Protection = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic( gg_trg_Orbs_Of_Protection, 0.03 )
    call TriggerAddAction( gg_trg_Orbs_Of_Protection, function OOP_MoveOrbs )
    //---------------------------------------------------------------------------------------------------------------
    set gg_trg_Orbs_Of_Protection = null
    set gg_trg_Orbs_Of_Protection = CreateTrigger()
    //---------------------------------------------------------------------------------------------------------------
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Orbs_Of_Protection, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Orbs_Of_Protection, Condition( function Trig_Orbs_Of_Protection_Conditions ) )
    call TriggerAddAction( gg_trg_Orbs_Of_Protection, function OOP_CastTrig )
endfunction

Also, your group OOP_DummyGroup isn't initialized, so the first time you call GroupAddUnit or something of the likes, you will most likely face total randomness. You should initialize it in the definition:
JASS:
group OOP_DummyGroup = CreateGroup()

Next, LEARN TO INLINE!!! D: D: D:

Also, your recycling method is horrible... Can't you just keep an integer count as a global and stack the objects in the array?
JASS:
globals
    unit array OOP_Dummy
    unit array OOP_Dummy_Target
    integer COUNT = 0
endglobals

function mainloop takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i >= COUNT
        // Do your stuff here.
    endloop
endfunction

function destroy takes integer ref returns nothing
    set COUNT = COUNT - 1
    set OOP_Dummy[ref] = OOP_Dummy[COUNT]
    set OOP_Dummy_Target[ref] = OOP_Dummy_Target[COUNT]
    set OOP_Dummy[COUNT] = null
    set OOP_Dummy_Target[COUNT] = null
endfunction

function create takes unit dummy, unit target returns integer
    set OOP_Dummy[COUNT] = dummy
    set OOP_Dummy[COUNT] = target
    set COUNT = COUNT + 1
    return (COUNT - 1)
endfunction

I think that would work better. Haven't looked much more through your spell but you definitely need to fix your use of locations and BJ functions.
 
Status
Not open for further replies.
Top