• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Area of effect spell problem please HELP

Status
Not open for further replies.
JASS:
//condition 
function Cond takes nothing returns boolean 
return GetSpellAbilityId()== 'A000' 
endfunction
//actoin
function Mass_Sleep takes nothing returns nothing
local group sleep_units
local unit first_spell_target
local unit caster
local unit dummy_caster
local location target_ability_point
set caster = GetTriggerUnit()
set target_ability_point = GetSpellTargetLoc()
set sleep_units = GetUnitsInRangeOfLocAll(200.00, target_ability_point)
set first_spell_target = FirstOfGroup(sleep_units)
loop
exitwhen first_spell_target==null
set first_spell_target = FirstOfGroup(sleep_units)
if IsUnitEnemy(first_spell_target, GetOwningPlayer(caster))==true then 
call GroupRemoveUnit(sleep_units, first_spell_target)
set dummy_caster = CreateUnitAtLoc(GetOwningPlayer(caster), 'h000', GetUnitLoc(first_spell_target), 0.00)
call UnitAddAbility(dummy_caster, 'A001')
call IssueTargetOrderBJ (dummy_caster, "sleep", first_spell_target)
call UnitApplyTimedLifeBJ (2.5, 'BTLF', dummy_caster)
set dummy_caster = null
endif
endloop
set sleep_units = null
set caster = null
set target_ability_point = null 
endfunction
//well, events, conditions and other (i think)
function InitTrig_masssleep takes nothing returns nothing
local trigger Mytrigger
set Mytrigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Mytrigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(Mytrigger, Condition(function Cond))
call TriggerAddAction(Mytrigger, function Mass_Sleep)
endfunction

Guys, this is my AoE mass sleep spell. I know it is not new (i don't need new spells, just want to learn how they are created so i can create my owns).

It was in a tutorial and i made a few changes... Problem is that it doesn't work properly. It is not due my modifications.
It works fine at first, but if you keep casting it, it will eventually stop working ... I don't know if it is some kind of bug ...

Problems:
1- If casted too many times, just breaks up
2 - If there are in the AoE 2 units, an an enemy and an allied unit, the spell doesn't work
3 - If the unit under the sleep spell is attacked, when the spell is cast again, it doesn't work

Notes:
1- Spell created using silence ability
2- Uses a dummy unit and a dummy sleep ability

Raw Codes:
Dummy unit = h000
Silence = A000
Dummy Sleep = A001

The JassCraft program detects no errors and i don't know why it doesn't work properly.
Together with this post i have the test map, where you can found the jass script.
Please help me out.
 

Attachments

  • test-jass.w3x
    18.4 KB · Views: 66
Level 11
Joined
Oct 13, 2005
Messages
233
Before I go over why this isn't working, I'd first like to let you know you can create a local variable and set it to a value on the same line. Additionally
JASS:
set first_spell_target = FirstOfGroup(sleep_units)
loop
exitwhen first_spell_target==null
set first_spell_target = FirstOfGroup(sleep_units)
Should be changed to:
JASS:
loop
set first_spell_target = FirstOfGroup(sleep_units)
exitwhen first_spell_target==null

As for the problem, you need to remove the picked unit from the enemies group regardless of whether it's an enemy or an ally. Otherwise it will just keep picking the same unit and nothing with happen.
 
Yes, i already read your JASS tutorials, i commented them as well. I know i can create and declare a variable in only 1 line, but i prefer this way, i am new at JASS.
Now the solution you gave is not correct according to Daelin.
At http://www.hiveworkshop.com/forums/showthread.php?t=16456 Daelin uses the same triggers and he says:

Daelin said:
Now, you will wonder why I gave the variable u the value of FirstOfGroup(g) both outside and inside the loop. If I would’ve given it the value only inside, the unit would’ve been null when we would’ve entered the loop. And since the condition that u==null would’ve been true, the loop would’ve been skipped.

And yes, i also remove the picked unit using the
JASS:
call GroupRemoveUnit(sleep_units, first_spell_target)
statement.

It seems that nothing is wrong but the fact is the spell just doesn't work ... any other solutions ??

Btw, thx for your comment WyrmLord
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
No, you give the value BEFORE you check it, Flame.

But you should have moved the GroupRemoveUnit outside of the If-Statement, is what he was saying.

Here's what it should look like (I also renamed some of your ridiculously long var names)

JASS:
function MassSleepConds takes nothing returns boolean 
    return GetSpellAbilityId()== 'A000' 
endfunction

function MassSleep takes nothing returns nothing
    local group g = CreateGroup()
    local unit u
    local unit cast = GetTriggerUnit()
    local unit dumm
    local location targ = GetSpellTargetLoc()
    call GroupEnumUnitsInRange( g, GetLocationX( targ ), GetLocationY( targ ), 200, Filter(null) )
    loop
        set u = FirstOfGroup( g )
        exitwhen u==null
        if IsUnitEnemy(u, GetOwningPlayer(cast)) then
            set dumm = CreateUnit(GetOwningPlayer(cast), 'h000', GetUnitX(u), GetUnitY(u), 0)
            call UnitAddAbility(dumm, 'A001')
            call IssueTargetOrder(dumm, "sleep", u)
            call UnitApplyTimedLife(dumm, 'BTLF', 2.5)
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    call RemoveLocation(targ)
    set g = null
    set cast = null
    set targ = null
    set dumm = null
endfunction

function InitTrig_masssleep takes nothing returns nothing
    set gg_trg_masssleep = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_masssleep, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_masssleep, Condition(function MassSleepConds))
    call TriggerAddAction(gg_trg_masssleep, function MassSleep)
endfunction

What I changed

-destroyed the group and the loc
-indented
-moved the GroupRemoveUnit OUTSIDE the loop
-used the default initialized trigger in the InitTrig
-made the condition's name related to the spell
-replaced BJs with natives
-shortened var names
-set the variables upon initializing them

If you encounter any bugs relating to the sleep dummy ability (like you said with it not sleeping properly the second time), that's that ability's fault, not this one's.
 
Well, i tested the correction of the spell, and i must say it works properly. Really thanks, you were the only 1 who were able to help me. Now, once you are done with the locals prob (yes i know how annoying i can be, i still have questions) i will have probably no more spell issues ... for now.
I will later try to mix this spell with the other, i mean try to make this simple AoE spell a hero spell, with 3 levels and stuff like that. But i want to do that alone and i will only come if i have major issues.


Thx for help. Flame_Phoenix
 
Status
Not open for further replies.
Top