• 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.

[JASS] Problem with redirecting spells

Status
Not open for further replies.
Level 3
Joined
Dec 20, 2007
Messages
44
I'm trying to set up a trigger so if a unit targets a certain unit for a spell, the target of that spell changes to another unit. The problem is that it doesn't work with spells (but it does work with attack). So basically the problem is that the redirected spell fails to cast successfully.

Here's the part of the code that is supposed to redirect the spell

JASS:
call IssueImmediateOrder(u, "stop")
        call PolledWait2(0.1)
        call IssueImmediateOrder(u, "spellbook")
        call SetUnitAnimation(u, "stand")
        call PolledWait2(0.1)
        call IssueTargetOrderById(u, o, udg_Heroes[i])

and here's the whole function

JASS:
function Order_Action takes nothing returns nothing
    local unit u = GetOrderedUnit()
    local unit t = GetOrderTargetUnit()
    local integer i = 0
    local integer j = GetPlayerId(GetOwningPlayer(u))
    local integer o = GetIssuedOrderId()
    
    if (u != t and GetOwningPlayer(u) == GetOwningPlayer(t) and GetUnitTypeId(t) != 'h00Q' and GetUnitTypeId(u)!='h00Q') then
        loop 
            exitwhen i>9 or t == PFArr[j*10+i]
            set i = i+1
        endloop
        call IssueImmediateOrder(u, "stop")
        call PolledWait2(0.1)
        call IssueImmediateOrder(u, "spellbook")
        call SetUnitAnimation(u, "stand")
        call PolledWait2(0.1)
        call IssueTargetOrderById(u, o, udg_Heroes[i])
    endif
    set u = null
    set t = null
endfunction
 
Last edited:
Level 3
Joined
Dec 20, 2007
Messages
44
oh, one note, all the spells are inside, so part of the problem could be ordering units to cast spells that are in spell books... (the only part that isn't working is that the new spell is failing to successfully cast. I've tried ordering the unit to open the spellbook first, but that doesn't seem to be working, and the spell book is already open...)
 
Level 5
Joined
Aug 27, 2007
Messages
138
Perhaps the polled wait disrupts things. Maybe add another local at the beginning:

JASS:
local integer id = GetIssuedOrderId()

Then, use:

JASS:
call IssueTargetOrderById(u, id, udg_Heroes[i])

See if that helps any.

By the way, edit instead of double-posting.
 
Level 3
Joined
Dec 20, 2007
Messages
44
Yeah sorry for the double post.... I edited the top post to be updated. I tried saving it to a local variable but that didn't help (though I doubt it'd work without saving it)
 
Level 5
Joined
Aug 27, 2007
Messages
138
Add a condition function to this:

JASS:
function bla takes nothing returns boolean
    return GetIssuedOrderId() != OrderId("stop") //I don't know teh order Id off the top of my head.  This'll work, but if you know the OrderId, use it insteaed.
endfunction

Right now, it's ordering it to stop every time it stops. Maybe that'll fix it?

Edit: Or maybe not. You can probably ignore that... v.v Can you tell me what kind of events/conditions you already have?
 
Level 5
Joined
Aug 27, 2007
Messages
138
Uhhh... No, that is your problem. When it does this:

JASS:
call IssueTargetOrderById(u, o, udg_Heroes[i])

It fires function Order_Actions and it causes the unit to stop. ...Or is that what those other conditions are for?
 
Last edited:
Level 3
Joined
Dec 20, 2007
Messages
44
yeah, the other function basically check to make sure the targeted unit is the dummy unit (a unit that is owned by the same player) and then redirects the casted spell at a different hero (owned by a different player stored in the heroes array) so the
JASS:
GetOwningPlayer(u) == GetOwningPlayer(t)
part fails
 
Last edited:
Status
Not open for further replies.
Top