• 🏆 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] Fan of Daggers Help

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
[SOLVED]Fan of Daggers Help

Hi guys,

I have yet another JASS question :grin:
In my map I have 9 customized heroes which all have abilities that are triggered. I want to "upgrade" to JASS to make things less buggy. One of the hero's abilities is the normal "Fan of Knives" except when it's cast it ensnares all enemies within 200 range. It worked fine with GUI but I am having trouble converting to JASS. Please take a look and see what I've done wrong:

JASS:
function Condition_Fan_of_Daggers takes nothing returns boolean
    return (GetOwningPlayer(GetFilterUnit()) == Player(11))
endfunction

function Fan_of_Daggers takes unit u returns nothing
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local group ug = CreateGroup()
    local unit temp
    call GroupEnumUnitsInRange(ug, x, y, 200.00, Condition(function Condition_Fan_of_Daggers))
    loop
        set temp = FirstOfGroup(ug)
        exitwhen temp == null
        if (IsUnitEnemy(temp, GetOwningPlayer(u))) then
            set bj_lastCreatedUnit = CreateUnit(GetOwningPlayer(u), 'h003', x, y, bj_UNIT_FACING)
            call UnitAddAbility(bj_lastCreatedUnit, 'A00B')
            call SetUnitAbilityLevel(bj_lastCreatedUnit, 'A00B', GetUnitAbilityLevel(u, 'A01E'))
            call IssueTargetOrder(bj_lastCreatedUnit, "ensnare", temp)
            call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 1)
        endif
        call GroupRemoveUnit(ug, temp)
    endloop
    set temp = null
    call DestroyGroup(ug)
endfunction
Any help will be much appreciated!
 
Last edited:
Level 17
Joined
Feb 11, 2011
Messages
1,860
  • Fan of Daggers
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fan of Daggers
    • Actions
      • Custom script: call Fan_of_Daggers(GetTriggerUnit())
JASS:
function Condition_Fan_of_Daggers takes nothing returns boolean
    return (GetOwningPlayer(GetFilterUnit()) == Player(11))
endfunction

function Fan_of_Daggers takes unit u returns nothing
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local group ug = CreateGroup()
    local unit temp
    call GroupEnumUnitsInRange(ug, x, y, 200.00, Condition(function Condition_Fan_of_Daggers))
    loop
        set temp = FirstOfGroup(ug)
        exitwhen temp == null
        if (IsUnitEnemy(temp, GetOwningPlayer(u))) then
            set bj_lastCreatedUnit = CreateUnit(GetOwningPlayer(u), 'h003', x, y, bj_UNIT_FACING)
            call UnitAddAbility(bj_lastCreatedUnit, 'A00B')
            call SetUnitAbilityLevel(bj_lastCreatedUnit, 'A00B', GetUnitAbilityLevel(u, 'A01E'))
            call IssueTargetOrder(bj_lastCreatedUnit, "ensnare", temp)
            call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 1)
        endif
        call GroupRemoveUnit(ug, temp)
    endloop
    set temp = null
    call DestroyGroup(ug)
endfunction
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
I would say that the "ensnare" part of the spell isn't working. Converting orders usually have this performance (what I have experienced). Basic check the dummy spell again and its order if it's the same else you can try with order id instead of the string.
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
Guys, don't you think that script can be improved? Group variable isn't nulled + ForGroup is said to be faster than FirstOfGroup. bj_lastCreatedGroup could be usefully here too.

Yeyeye details. As example you can skip the whole fog loop and just add a global unit variable and to the grouploop in the filter conditon function (and get rid of a forgroup as well), and get rid off local group and just use the bj variable. much can be improved as you see but still he is still "learning" JASS so I'm not to eager to point out every single flaw/fault as it might destroy more than it helps (self-confidence), also read Axarions sig aka ap0calypse quote, that thw is a bunch of predators and new people might get caught ... :)
 
Level 7
Joined
Nov 19, 2007
Messages
253
better start learning vJass instead of Jass its much move effective and much more simpier.. heres how i would done this spell in vJass:
JASS:
scope fanOfDaggers initializer i

    globals
        private unit globalCaster
    endglobals

    private function Condition_Fan_of_Daggers takes nothing returns boolean
        if GetOwningPlayer(GetFilterUnit()) == Player(11) then
            if IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(globalCaster)) then
                set bj_lastCreatedUnit = CreateUnit(GetOwningPlayer(globalCaster), 'h003', 0, 0, 0)
                call UnitAddAbility(bj_lastCreatedUnit, 'A00B')
                call SetUnitAbilityLevel(bj_lastCreatedUnit, 'A00B', GetUnitAbilityLevel(globalCaster, 'A01E'))
                call IssueTargetOrder(bj_lastCreatedUnit, "ensnare", GetFilterUnit())
                call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 1)
            endif
        endif
        return false
    endfunction

    private function c takes nothing returns boolean
        local real x
        local real y
        local group ug
        if GetSpellAbilityId()=='A01E' then
            set ug=CreateGroup()
            set globalCaster=GetTriggerUnit()
            set x=GetUnitX(globalCaster)
            set y=GetUnitY(globalCaster)
            call GroupEnumUnitsInRange(ug, x, y, 200, Condition(function Condition_Fan_of_Daggers))
            call DestroyGroup(ug)
        endif
        return false
    endfunction

    private function i takes nothing returns nothing
        local trigger trig=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(trig,Condition(function c))
        set trig=null
    endfunction
    
endscope

you can put this code instead of your GUI and Jass trigger it should work fine if all ID's are right (and after you put this into your map if your using NewGen WE save map 2 times and then test it else it will bring you to main menu)
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
better start learning vJass instead of Jass its much move effective and much more simpier..
It's like going to school in your neighbourhood via aeroplane. If you just started learning Jass give him time to acumulate enough knowledge to move further.

By the way you forgot to null group handle, plus it's better to use bj_lastCreatedGroup here.
 
Level 7
Joined
Nov 19, 2007
Messages
253
Well jass and vJass is allmost the same vJass is different because it has scope struct and some other useful stuff i never learned jass i went straight for vJass and it went verry well for me. And why should i null group there when i destroy it doesnt matter.. and bj_lastCreatedGroup is same thing as ug its just a variable..
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I highly recommend to learn jass before because in the end vJass will be converted in jass, and really you can get some nightmare jass code using vJass (even if it doesn't really matter in most situations), i mean you should know jass very well and how a vJass code is converted exactly in jass.
Same for Zinc (but it's more an alpha parser than something really usable)

If you're using the JassNewGenPack an easy way is to check the .j files inside the sub-folder "logs" after saving the map, else you can open the map with a mopaq editor such as winmpq and read the war3map.j

And anyway that's not like you have to learn many things in jass ...
 
Status
Not open for further replies.
Top