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

Help with chains pell system

Status
Not open for further replies.
Level 9
Joined
Aug 21, 2008
Messages
533
I tried to make a system which allow me to easily make "chain" spells like chain healing or chain lightning. but it something do not work...
JASS:
library chainspell

function Enemyfilter takes nothing returns boolean
    return  IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()),GetOwningPlayer(udg_tempunit))
endfunction

function Allyfilter takes nothing returns boolean
return  IsPlayerAlly(GetOwningPlayer(GetFilterUnit()),GetOwningPlayer(udg_tempunit))
endfunction

function ReGroup takes nothing returns nothing
    call GroupRemoveUnit(tempgroup,GetEnumUnit())
endfunction

function chainspell takes unit caster,unit target,integer baseSpell,integer spell,integer NrOfTargets,real range,boolean TargetEnemy returns nothing
    local unit u = CreateUnit(GetOwningPlayer(caster),'h003',GetUnitX(caster),GetUnitY(caster),0)
    local real x=GetUnitX(target)
    local real y=GetUnitY(target)
    local real oldx=GetUnitX(caster)
    local real oldy=GetUnitY(caster)
    local group Donot
//this messeage works
    call BJDebugMsg("spell triggers")
    call GroupAddUnit(Donot,u)
    call UnitAddAbility(u,spell)
    call SetUnitAbilityLevel(u,spell,GetUnitAbilityLevel(caster,baseSpell))
    call GroupAddUnit(chaingroup,u) 
    call SaveReal( udg_HashTable, GetHandleId(u), StringHash("X"), x)
    call SaveReal( udg_HashTable, GetHandleId(u), StringHash("Y"), y)
    call SaveReal( udg_HashTable, GetHandleId(u), StringHash("oldX"), oldx)
    call SaveReal( udg_HashTable, GetHandleId(u), StringHash("oldY"), oldy)
    call SaveInteger( udg_HashTable, GetHandleId(u), StringHash("targets"), NrOfTargets)
    call SaveInteger( udg_HashTable, GetHandleId(u), StringHash("spell"), spell)
    call SaveUnitHandle( udg_HashTable, GetHandleId(u), StringHash("Target"), target)
    call SaveBoolean( udg_HashTable, GetHandleId(u), StringHash("TargetEnemy"), TargetEnemy)
    call SaveGroupHandle( udg_HashTable, GetHandleId(u), StringHash("DoNotTargets"), Donot)
    set u = null
    set caster = null
    set target = null
endfunction



function chainspellEx2 takes nothing returns nothing
    local group g
    local unit u = GetEnumUnit()
    local unit target = LoadUnitHandle( udg_HashTable, GetHandleId(u), StringHash("Target"))
    local group DoNot = LoadGroupHandle( udg_HashTable, GetHandleId(u), StringHash("DoNotTargets"))
    local real x =   LoadReal( udg_HashTable, GetHandleId(u), StringHash("X"))
    local real y =   LoadReal( udg_HashTable, GetHandleId(u), StringHash("Y"))
    local real oldx =   LoadReal( udg_HashTable, GetHandleId(u), StringHash("oldX"))
    local real oldy =   LoadReal( udg_HashTable, GetHandleId(u), StringHash("oldY"))
    local boolean boole =LoadBoolean( udg_HashTable, GetHandleId(u), StringHash("TargetEnemy"))
    local integer RemainTargets= LoadInteger( udg_HashTable, GetHandleId(u), StringHash("targets"))
//this messeage does NOT work
    call BJDebugMsg("it works!")
    call SetUnitX(u,oldx)
    call SetUnitY(u,oldy)
    call UnitResetCooldown( u )
    call IssueTargetOrderById(u,LoadInteger(udg_HashTable, GetHandleId(u), StringHash("spell")),target)
    if RemainTargets == 0 then
        call FlushChildHashtable(udg_HashTable,GetHandleId(u))
        call UnitApplyTimedLife(u,'BTLF',0.01)
        call GroupRemoveUnit(chaingroup,u)
    else
        call GroupAddUnit(DoNot,target)
        set udg_tempunit=u
        if boole == true then
            call GroupEnumUnitsInRange(tempgroup,x,y,500.00,Condition(function Enemyfilter))
        else
            call GroupEnumUnitsInRange(tempgroup,x,y,500.00,Condition(function Allyfilter))
        endif
        call ForGroup(DoNot,function ReGroup)
        set g= tempgroup
        set target=FirstOfGroup(g)
        set RemainTargets=RemainTargets-1
        call SaveReal( udg_HashTable, GetHandleId(u), StringHash("X"), GetUnitX(target))
        call SaveReal( udg_HashTable, GetHandleId(u), StringHash("Y"), GetUnitY(target))
        call SaveReal( udg_HashTable, GetHandleId(u), StringHash("oldX"), x)
        call SaveReal( udg_HashTable, GetHandleId(u), StringHash("oldY"), y)
        call SaveInteger( udg_HashTable, GetHandleId(u), StringHash("targets"),RemainTargets)
        call SaveGroupHandle( udg_HashTable, GetHandleId(u), StringHash("DoNotTargets"), DoNot)
    endif
    set u = null
    set target = null
    call DestroyGroup(tempgroup)
    call DestroyGroup(g)
    call DestroyGroup(DoNot)
    set g = null
    set DoNot=null
endfunction


function chainspellEx takes nothing returns nothing
//this messeage works
call BJDebugMsg("timer")
call ForGroup(chaingroup,function chainspellEx2)
endfunction
endlibrary
Jasshelper says everything is fine =/
 
Level 9
Joined
Aug 21, 2008
Messages
533
Serously im not going to use a gui system. This make it even harder to share it:hohum:
And i like to do most things for myself. I hate using Systems which i dont understand. I normally like to create my own ones.

edit: o and i like to be able to make the spell within 1 line. That have style =)
 
Change the bottommost chainspellex to this:
JASS:
function chainspellEx takes nothing returns nothing
    local integer i = CountUnitsInGroup(chaingroup)
    if chaingroup != null then
        call BJDebugMsg("Chaingroup is not null.")
    else 
        call BJDebugMsg("Chaingroup is null.")
    endif
    if i == 0 then
        call BJDebugMsg("There are no units in chaingroup.")
    else
        call BJDebugMsg("There are "+I2S(i)+" units in chaingroup.")
    endif
//this messeage works
call BJDebugMsg("timer")
call ForGroup(chaingroup,function chainspellEx2)
endfunction

Test it in game and see what the message is.
It should say "Chaingroup is not null". Otherwise, then there is your problem.

If it says there are no units, that means that the units weren't enumerated in the group for some reason. If it displays the number of the units, then it is some other problem.

Report back with the results so we can figure out what the problem is. =)

EDIT: Also:
JASS:
    local group Donot = CreateGroup()
//If you do not create the group, there will be nothing to add to. =D
 
Level 9
Joined
Aug 21, 2008
Messages
533
It says there are no units in chaingroup =/
Here is the spell itself:
  • ChainPolyTest
    • Events
      • Einheit - A unit starts casting a ability
    • Bedingungen
      • (Ability being cast) Gleich ChainPolyTest
    • Aktionen
      • Custom script: call chainspell(GetTriggerUnit(),GetSpellTargetUnit(),GetSpellAbilityId(),'Aply',4,500.00,true)
 
There might be something wrong with this line:
JASS:
    call GroupAddUnit(chaingroup,u)

Place this part:
JASS:
    if u != null
        call BJDebugMsg("The unit has been created.")
    else
        call BJDebugMsg("The unit does not exist.")
    endif
In this:
JASS:
function chainspell takes unit caster,unit target,integer baseSpell,integer spell,integer NrOfTargets,real range,boolean TargetEnemy returns nothing
    local unit u = CreateUnit(GetOwningPlayer(caster),'h003',GetUnitX(caster),GetUnitY(caster),0)
    local real x=GetUnitX(target)
    local real y=GetUnitY(target)
    local real oldx=GetUnitX(caster)
    local real oldy=GetUnitY(caster)
    local group Donot = CreateGroup()
//this messeage works
    call BJDebugMsg("spell triggers")
    //Place the function right here like so:
    if u != null
        call BJDebugMsg("The unit has been created.")
    else
        call BJDebugMsg("The unit does not exist.")
    endif

Then report back with what it says.

EDIT: Also, try this in the same spot as above:
JASS:
    if chaingroup == null then
        set chaingroup = CreateGroup()
    endif
 
Level 9
Joined
Sep 28, 2004
Messages
365
Correct me if i am wrong. But i didn't see you storing the chaingroup in a hashtable and i am assuming your chaingroup is local since it doesnt have udg or you didn't post the global declaration. Therefore as a local since it is a local scope, it will be destroy at the end of chainspell function.

SlayerII said:
Serously im not going to use a gui system. This make it even harder to share it
And i like to do most things for myself. I hate using Systems which i dont understand. I normally like to create my own ones.

edit: o and i like to be able to make the spell within 1 line. That have style =)
:D 1 line in custom script is actually the same as GUI, just that GUI can't squeeze all arguments in 1 long line. (Eg: 5 arguments = 5 lines of GUI code (Most of the time atleast))

EDIT:
Offtopic:
@Tiche3
:D Didn't know someone is promoting my system, thanks! [:
 
Level 9
Joined
Jun 25, 2009
Messages
427
Correct me if i am wrong. But i didn't see you storing the chaingroup in a hashtable and i am assuming your chaingroup is local since it doesnt have udg or you didn't post the global declaration. Therefore as a local since it is a local scope, it will be destroy at the end of chainspell function.


:D 1 line in custom script is actually the same as GUI, just that GUI can't squeeze all arguments in 1 long line. (Eg: 5 arguments = 5 lines of GUI code (Most of the time atleast))

EDIT:
Offtopic:
@Tiche3
:D Didn't know someone is promoting my system, thanks! [:

Your welcome ;) :wink:
 
Status
Not open for further replies.
Top