• 🏆 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] Unit won't cast a simple spell...

Status
Not open for further replies.
Level 6
Joined
Oct 10, 2009
Messages
1,425
Problem solved thanks to:
Bribe
Berb

Well, I am currently working on a spell for my map and in it, I am creating a dummy unit to cast an ability who's code is 'A000'
The problem is the unit WILL not cast it.
As you can see, I create it for Player 1, so I know he CAN cast it, he just won't do it on command.
I've checked all the rawcodes and I know they are correct.
I even tried getting him to cast it from a string command, to no avail.

Don't bug me on the coding. It's not close to being finished, and some locals I declare, I don't even use yet.
As for the wrapper functions, I have a friend who wants the spell when I'm done and he doesn't know JASS, so those are pretty much there so he can implement. I'm not done with those yet either, ofc.

If you have a recommendation for a function I should use or something that is actually helpful, then sure, go ahead and tell me and you'll get rep for helping out a JASS noob. :)
JASS:
        loop 
            set LoopUnits = FirstOfGroup(targets)
            exitwhen LoopUnits == null
                set Dummy = CreateUnit(Player(0),RAWCODEDUMMY(),X,Y,0.00)
                call UnitApplyTimedLife(Dummy,'BTLF',1)
                call UnitAddAbility(Dummy,'A000')
                call SetUnitAbilityLevel (Dummy, 'A000', GetUnitAbilityLevel(U, 'XYYY'))
                call IssueTargetOrderById(U, 'A000' , LoopUnits)
                call GroupRemoveUnit(targets,LoopUnits)
        endloop


JASS:
constant function RAWCODEABILITY takes nothing returns integer
    return 'XYYY'
endfunction

constant function RAWCODEDUMMY takes nothing returns integer
    return 'h000'
endfunction 

function Damage_Tree takes integer level returns integer
    return level *200
endfunction

function Range_Tree takes integer level returns real
   if level == 1 then
   return 300.000
   else
   if level == 2 then
   return 350.000
   else
   return 400.000
   endif    
   endif
endfunction

function Targets_Tree takes unit target returns boolean
        return (GetWidgetLife(target) > 0.405) and (IsUnitType(target, UNIT_TYPE_STRUCTURE) == false) and (IsUnit(target,GetTriggerUnit()) == false) and (IsUnitType(target,UNIT_TYPE_MAGIC_IMMUNE) == false)
   endfunction
   
function Conditions_Tree takes nothing returns boolean
    return GetSpellAbilityId() == RAWCODEABILITY()
endfunction

function Pick_Tree takes nothing returns boolean
        return Targets_Tree(GetFilterUnit())
    endfunction

function Trig_Tree_Attack_Actions takes nothing returns nothing
    local unit U = GetTriggerUnit()
    local real X = GetLocationX(GetSpellTargetLoc())
    local real Y = GetLocationY(GetSpellTargetLoc())
    local boolexpr b = Condition(function Pick_Tree)
    local group targets = CreateGroup()
    local group targets2 = CreateGroup()
    local integer level = GetUnitAbilityLevel(U,RAWCODEABILITY())
    local unit LoopUnits
    local unit Dummy
    call GroupEnumUnitsInRange(targets,X,Y,Range_Tree(level),b)
    call GroupEnumUnitsInRange(targets2,X,Y,Range_Tree(level),b)
        loop 
            set LoopUnits = FirstOfGroup(targets)
            exitwhen LoopUnits == null
                set Dummy = CreateUnit(Player(0),RAWCODEDUMMY(),X,Y,0.00)
                call UnitApplyTimedLife(Dummy,'BTLF',1)
                call UnitAddAbility(Dummy,'A000')
                call SetUnitAbilityLevel (Dummy, 'A000', GetUnitAbilityLevel(U, 'XYYY'))
                call IssueTargetOrderById(U, 'A000' , LoopUnits)
                call GroupRemoveUnit(targets,LoopUnits)
        endloop
endfunction

//===========================================================================
function InitTrig_Tree_Attack takes nothing returns nothing
    local trigger T = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(T, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddAction(T, function Trig_Tree_Attack_Actions )
    call TriggerAddCondition(T,Condition(function Conditions_Tree))
endfunction


ANY help would be appreciated and rewarded.! :D

Please note*
I use the word WON'T for a reason...don't ask me if I got the RawCode wrong or if it cost mana. Don't ask me about things like that unless that is absolutely the only logical explanation.
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
call IssueTargetOrderById(U, 'A000' , LoopUnits)

Won't work. You have to use the order ID, not the spell's rawcode. If it's based on Shockwave:

call IssueTargetOrder(U, "shockwave", LoopUnits)
or
call IssueTargetOrderById(U, OrderId("shockwave"), LoopUnits)

Oh, yeah. don't use EVENT_PLAYER_UNIT_SPELL_CAST because the trigger will fire before the unit expends his mana. Do:

EVENT_PLAYER_UNIT_SPELL_EFFECT.
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
Hmm interesting, about both of those.
Thank you for showing me SPELL_EFFECT,
but I based it off Entangling Roots so it should be "entanglingroots" according to the ability I beleive then.
Only catch is that it didn't work either way I tried that you showed :/
Any Idea what might cause it not to fire?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Check if dummy's turnrate or movespeed are screwed up. those could be factors. Check if the 'targets allowed' are screwed up, that's a common one, too.

Put in a BJDebugMsg() near each of the variables to see if they are doing what they are supposed to be doing.

Also, you're still using the mind-bending GetLocationX(GetSpellTargetLoc()) when I'm pretty sure I told you about the infinitely better GetSpellTargetX()
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
mmm maybe you did awhile back to be honest. I forgot if you have.
I'll use that, thanks for that as well.
Weird...it doesn't show up in newgen?
Is it just because newgen is dated?

And nope. Movespeed is 270, turn rate is .60. And targets allowed are fine.

EDIT: also, I did the BJD()'s and all the variables are correct.
It displayed the targets correctly, it displayed the dummy, and it showed the rawcode being Entangling Roots so all is good as far as varibs go.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You can immediately determine whether it is an Object Editor problem or a Trigger Editor problem by doing:

JASS:
if IssueTargetOrder(u, "shockwave", LoopUnits) then
    call BJDebugMsg("The order was successful.")
else
    call BJDebugMsg("The order was not successful.")
endif
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
Well thank you Berb for that helpful little function.
My order is NOT successful so it must be a problem with the activation string.
I'll look into it.

Bribe, mmm...thanks a lot for that. I needed hashtables the other day and could've used that.
:)
 
Level 10
Joined
May 27, 2009
Messages
494
suggestion if you haven't do so..

try making the dummy's casting backswing to 0 so it would not take some time before the ability is casted. Default is 0.500. It is found on the Arts portion of the object editor because from the way you call it, it has an expiration timer so it might be a dummy though
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
Hmm...I've never even seen that, yet that could come in handy.
Thanks for the tip.

EDIT: after exhausting all of my coding powers, I still can't fix it.
I'm deeply saddened.

I even changed the Use string to "shockwave" since I saw you guys used it, but I'm still failing. >.>

EDIT:
I win!
:)
Thanks to all who helped in the process.
 
Last edited:
Status
Not open for further replies.
Top