• 🏆 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!

[Trigger] need help with unit casting custom ability

Status
Not open for further replies.
Level 17
Joined
Aug 19, 2007
Messages
1,380
Hi, I want to make an ability which offers jobs to the target village, increasing it's population growth rate. I need a dummy unit to cast the custom spell (which uses "Aerial Shackles" as a base and has the same "order string - use/turn on" -> "magicleash). Now the problem, whenever I use the following trigger it does nothing, what am I doing wrong? Thanks for taking the time, here is the not working trigger in gui:
  • Offersciencejob
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Offers a Job (scientist)
    • Actions
      • Set ScienceJobCaster = (Casting unit)
      • Set ScienceJobTarget = (Target unit of ability being cast)
      • Unit - Order (Casting unit) to Stop
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (ScienceJobTarget is A town-hall-type unit) Equal to (==) True
          • Then - Actions
            • Unit Group - Pick every unit in (Units within 100.00 of (Position of ScienceJobCaster) matching ((Unit-type of (Matching unit)) Equal to (==) dummy science job)) and do (Actions)
              • Loop - Actions
                • Unit - Order (Picked unit) to Human Dragonhawk Rider - Aerial Shackles ScienceJobTarget
          • Else - Actions
and here in custom text:
JASS:
function Trig_Offersciencejob_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00V' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Offersciencejob_Func004Func002001003 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'n001' )
endfunction

function Trig_Offersciencejob_Func004Func002A takes nothing returns nothing
    call IssueTargetOrder( GetEnumUnit(), "magicleash", udg_ScienceJobTarget )
endfunction

function Trig_Offersciencejob_Func004C takes nothing returns boolean
    if ( not ( IsUnitType(udg_ScienceJobTarget, UNIT_TYPE_TOWNHALL) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Offersciencejob_Actions takes nothing returns nothing
    set udg_ScienceJobCaster = GetSpellAbilityUnit()
    set udg_ScienceJobTarget = GetSpellTargetUnit()
    call IssueImmediateOrder( GetSpellAbilityUnit(), "stop" )
    if ( Trig_Offersciencejob_Func004C() ) then
        call ForGroupBJ( GetUnitsInRangeOfLocMatching(100.00, GetUnitLoc(udg_ScienceJobCaster), Condition(function Trig_Offersciencejob_Func004Func002001003)), function Trig_Offersciencejob_Func004Func002A )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Offersciencejob takes nothing returns nothing
    set gg_trg_Offersciencejob = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Offersciencejob, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Offersciencejob, Condition( function Trig_Offersciencejob_Conditions ) )
    call TriggerAddAction( gg_trg_Offersciencejob, function Trig_Offersciencejob_Actions )
endfunction

Code:
function Trig_Offersciencejob_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00V' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Offersciencejob_Func004Func002001003 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'n001' )
endfunction

function Trig_Offersciencejob_Func004Func002A takes nothing returns nothing
    call IssueTargetOrder( GetEnumUnit(), "magicleash", udg_ScienceJobTarget )
endfunction

function Trig_Offersciencejob_Func004C takes nothing returns boolean
    if ( not ( IsUnitType(udg_ScienceJobTarget, UNIT_TYPE_TOWNHALL) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Offersciencejob_Actions takes nothing returns nothing
    set udg_ScienceJobCaster = GetSpellAbilityUnit()
    set udg_ScienceJobTarget = GetSpellTargetUnit()
    call IssueImmediateOrder( GetSpellAbilityUnit(), "stop" )
    if ( Trig_Offersciencejob_Func004C() ) then
        call ForGroupBJ( GetUnitsInRangeOfLocMatching(100.00, GetUnitLoc(udg_ScienceJobCaster), Condition(function Trig_Offersciencejob_Func004Func002001003)), function Trig_Offersciencejob_Func004Func002A )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Offersciencejob takes nothing returns nothing
    set gg_trg_Offersciencejob = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Offersciencejob, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Offersciencejob, Condition( function Trig_Offersciencejob_Conditions ) )
    call TriggerAddAction( gg_trg_Offersciencejob, function Trig_Offersciencejob_Actions )
endfunction
 
Last edited by a moderator:
Level 17
Joined
Aug 19, 2007
Messages
1,380
  • Is the mana cost of the ability 0? Have you disabled "check dependencies" for the ability?
, mana is 0, reqs are removed and "check dependencies" i've tested both "yes" and "no", in both cases it didn't work.

Oh, there's something I forgot to say: when I tried to fix it myself I found that the trigger didn't work anymore when I added the "pick every unit in..." action, before that I had instead of "Order (Picked unit)" :fp: "Order (~specific selected unit with 'select unit' in editor)" and this worked. So I think the problem lies in the unit group action, don't know where though. And one more thing, the dummy unit has the locust ability but I don't think that matters.
 
Level 3
Joined
Feb 13, 2008
Messages
65
Make sure the target unit is able to be targeted by the aerial shackles ability. IE if the dummy unit is an ally of the casting unit and aerial shackles cant be cast on allies, then there's an issue.

Also the "If (ScienceJobTarget is a Town-hall unit then)" condition looks fishy to me... look into that
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
Thanks for the comment,

Make sure the target unit is able to be targeted by the aerial shackles ability. IE if the dummy unit is an ally of the casting unit and aerial shackles cant be cast on allies, then there's an issue.
, I changed to targets on which it can be cast to friendly, or do you mean something which is hardcoded in the ability?

Also the "If (ScienceJobTarget is a Town-hall unit then)" condition looks fishy to me... look into that
, I tried it with and without it, made no difference.
 
Level 3
Joined
Feb 13, 2008
Messages
65
At this point I would insert game - announce triggers so that it says certain phrases during each step of the trigger, so you can isolate which part of the trigger is not functioning.

As for the town-hall-type unit condition, removing it wont change the problem, you need to replace that condition with something that applies to the units you want to use it on (IE if they're heroes or only a certain color ect.)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
JASS:
function Trig_Offersciencejob_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00V' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Offersciencejob_Func004Func002001003 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'n001' )
endfunction

function Trig_Offersciencejob_Func004Func002A takes nothing returns nothing
    // i have changed up this function (added some debugging), it should display either "true" or "false"
    // when ran in-game.
    
    if IssueTargetOrder( GetEnumUnit(), "magicleash", udg_ScienceJobTarget ) then
        call BJDebugMsg("true")
    else
        call BJDebugMsg("false")
    endif
    
    // if 'true' is displayed, then the order is being issued properly, if it displays false then it has
    // to do with the ability being ordered. just test it out.
endfunction

function Trig_Offersciencejob_Func004C takes nothing returns boolean
    if ( not ( IsUnitType(udg_ScienceJobTarget, UNIT_TYPE_TOWNHALL) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Offersciencejob_Actions takes nothing returns nothing
    set udg_ScienceJobCaster = GetSpellAbilityUnit()
    set udg_ScienceJobTarget = GetSpellTargetUnit()
    call IssueImmediateOrder( GetSpellAbilityUnit(), "stop" )
    if ( Trig_Offersciencejob_Func004C() ) then
        call ForGroupBJ( GetUnitsInRangeOfLocMatching(100.00, GetUnitLoc(udg_ScienceJobCaster), Condition(function Trig_Offersciencejob_Func004Func002001003)), function Trig_Offersciencejob_Func004Func002A )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Offersciencejob takes nothing returns nothing
    set gg_trg_Offersciencejob = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Offersciencejob, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Offersciencejob, Condition( function Trig_Offersciencejob_Conditions ) )
    call TriggerAddAction( gg_trg_Offersciencejob, function Trig_Offersciencejob_Actions )
endfunction
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
If it doesn't show anything then the function isn't even executing, which means there is a problem with the ForGroupBJ, or one of the conditions used. I am on my way to University at the moment but I will respond back when I can.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
He's actually ordering the units in the group to cast "magicleash" on the target. This code makes no sense.

What exactly is this supposed to do again? I read over the GUI code and I don't understand your logic. Why don't you just "create" a dummy, order him to use magic leash, then apply an expire-timer on him. Why are you using a Unit Group at all?
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
Are you sure the targeted unit has the town-hall flag?
Try to alter this condition or remove it for testing.
Also, even if it works, only the first guy of the group will be able to cast magic leash. Because you can't cast another one when it's being hit by one already.
, the unit has town-hall unit marked on in unit classification and I tried the trigger without the condition.

He's actually ordering the units in the group to cast "magicleash" on the target. This code makes no sense.

What exactly is this supposed to do again? I read over the GUI code and I don't understand your logic. Why don't you just "create" a dummy, order him to use magic leash, then apply an expire-timer on him. Why are you using a Unit Group at all?
, see it as this, the village has two stats, 1 that matters in this trigger: the population of the village (this matter in my map for income). Now the unit which I want to cast "offer jobs" to the village must make usage of a dummy since I want him to research at the same time also (it is kind of a science lab structure). My idea was whenever a structure of the type ~science lab was created, a dummy unit is as well created next/in to it which will actually cast the ability when you use the offer job ability from the ~science lab. But now that I look back, 'creating a temporilly unit' should work as well. Going to try it out.
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
I tried to the temporilly create a dummy unit, but it still doesn't work (this times it creates the unit though, but won't cast the ability):

  • Offersciencejobnew
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Offers a Job (scientist)
      • ((Target unit of ability being cast) is A town-hall-type unit) Equal to (==) True
    • Actions
      • Unit - Order (Casting unit) to Stop
      • Set ScienceJobTarget = (Target unit of ability being cast)
      • Set TempPoint4 = (Position of (Casting unit))
      • Unit - Create 1 dummy science job for (Owner of (Casting unit)) at TempPoint4 facing Default building facing (270.0) degrees
      • Unit - Order (Last created unit) to Human Dragonhawk Rider - Aerial Shackles ScienceJobTarget
      • Unit - Add a 65536.00 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation(udg_TempPoint4)
 
Level 9
Joined
Nov 4, 2007
Messages
931
Try posting your map, it would be easier to see just what exactly you did with the object editor on aerial shackles as well as the units used in your trigger.
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
Try posting your map, it would be easier to see just what exactly you did with the object editor on aerial shackles as well as the units used in your trigger.
, ok here it is than, my Seven Kingdoms remake with a twist (still in alpha or earlier though). You can find the triggers for the science lab under TowerofScience and the dummy unit can be found under orc custom special. The dummy unit has temporilly a water elemental model for testing purposes.
 

Attachments

  • SevenKingdomsBeta.w3x
    477.3 KB · Views: 53
Level 9
Joined
Nov 4, 2007
Messages
931
HAHAHA YOU FOOL! YOU FOOLISH FOOL OF A FOOL! This map shall be mine and I shall take all the credit distributing it to b.net, to think it'd be so easy!













Nah j/king found your problem, the order of your actions matter, just set your variables at the start of actions instead of later, when you ordered the casting unit to stop, the target of the ability was lost, set the target before ordering the caster to stop and itll work fine.
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
HAHAHA YOU FOOL! YOU FOOLISH FOOL OF A FOOL! This map shall be mine and I shall take all the credit distributing it to b.net, to think it'd be so easy!
, lol, none of my maps are protected, if somebody would steal this they are stupid; they should wait till it's finished :p.

Nah j/king found your problem, the order of your actions matter, just set your variables at the start of actions instead of later, when you ordered the casting unit to stop, the target of the ability was lost, set the target before ordering the caster to stop and itll work fine.
, it still doesn't work. I use jassnewgenpack5b, does that matter?

  • Offersciencejobnew
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Offers a Job (scientist)
      • ((Target unit of ability being cast) is A town-hall-type unit) Equal to (==) True
    • Actions
      • Set ScienceJobTarget = (Target unit of ability being cast)
      • Set TempPoint4 = (Position of (Casting unit))
      • Unit - Create 1 dummy science job for (Owner of (Casting unit)) at TempPoint4 facing Default building facing (270.0) degrees
      • Unit - Order (Last created unit) to Human Dragonhawk Rider - Aerial Shackles ScienceJobTarget
      • Unit - Order (Casting unit) to Stop
      • Unit - Add a 65536.00 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation(udg_TempPoint4)
 
You also need to adjust the Turn rate and movement of the unit.
Set the movement speed of the dummy to 1 and turn rate to 3. Then do as Darkness said and move the stop order to bottom and if you like remove the ability to move from the dummy unit.
  • Offersciencejobnew
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Offers a Job (scientist)
      • ((Target unit of ability being cast) is A town-hall-type unit) Equal to True
    • Actions
      • Set ScienceJobTarget = (Target unit of ability being cast)
      • Set TempPoint4 = (Position of (Casting unit))
      • Unit - Create 1 dummy science job for (Owner of (Casting unit)) at TempPoint4 facing Default building facing degrees
      • Unit - Order (Last created unit) to Human Dragonhawk Rider - Aerial Shackles ScienceJobTarget
      • Unit - Add a 65536.00 second Generic expiration timer to (Last created unit)
      • Unit - Order (Casting unit) to Stop
      • Custom script: call UnitRemoveAbility( bj_lastCreatedUnit, 'Amov' )
      • Custom script: call RemoveLocation(udg_TempPoint4)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
K40$-Spectre said:
Unit - Add a 65536.00 second Generic expiration timer to (Last created unit)

I hope this is for testing purposes only.

K40$-Spectre said:
TempPoint4 facing Default building facing (270.0) degrees

The turn-rate may be an issue. Try making the dummy initially face the target of the ability you want him to use.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
[K40$-Spectre said:
]actually its not. I had no problem yet with it.

It will create an enormous build-up of dummy units because they'll live for hours. You only want the dummy to live for as much time as it has to. Just give him an expiration time the same as the channeling time on your magicleash ability.
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
It will create an enormous build-up of dummy units because they'll live for hours. You only want the dummy to live for as much time as it has to. Just give him an expiration time the same as the channeling time on your magicleash ability.
, I've a trigger which destroys other dummies next to the sciencelab when the ability is cast (I've done this so the science lab can only increase the population rate of 1 village, but it apperantly also fixes an issue :D). It works perfectly.
 
Status
Not open for further replies.
Top