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

[Solved] [Jass] a simple(noob) trigger

Status
Not open for further replies.
Level 4
Joined
Feb 17, 2008
Messages
67
Hello
In the past 2 days i have been checking out numerous tutorials on how to make maps using jass , the one made/updated by wyrmlord was most helpful .
[ http://www.hiveworkshop.com/forums/...als-280/beginning-jass-tutorial-series-30765/ ]

(actual problem)
It might be a bit outdated ,but now i feel as though i have a fair grip of the basics, the last spell covered in his tutorial was a spell similar to dota's omnislash.A spell that basically picks up every unit in a AoE of the targeted unit and moves the caster to the unit ,plays a special effect and damages that unit ,eliminates that unit from the group then "jumping" to the next unit in the group; repeating the process (instantly move,effect,dmg) till the group has no more units or the process of "jumping" has been done a number of times (nr_units_jumped == 0).
One extra condition when a unit from the group gets "jumped"-to it cannot be "jumped"-to again consecutively unless this unit is the only unit it the group.

I have tried the function GroupEnumUnitsInRange(group_g,location...) and first time it works ..but i tried afterwards to clear the links (minding the leaks) in a attempt to re-use the same group with some other position (position of the 2nd unit that is "jumped"-to) but it seems that the group_g ends up empty.

If somebody can help me with this i'd be really grateful ,different approaches are appreciated and if it wouldn't be to much trouble a pointer to a intermediate jass tutorial would be really great :)

for your time,
Thanks in advance
 
Level 4
Joined
Feb 17, 2008
Messages
67
ok this is the way i tried doing this :
and the comments aren't posted by me so they don't help too much with my particular problem
JASS:
function Slash_Condition takes nothing returns boolean

    return GetSpellAbilityId() == 'A002' //Compares the ability id of the ability being cast to the ability id of our Slash spell.

endfunction

function Slash_Actions takes nothing returns nothing


 local unit caster = GetSpellAbilityUnit()          //Create a local variable and set it to the unit that's casting the spell
 local location start_position = GetUnitLoc(GetSpellTargetUnit()) //Create the local and set it to the caster's position
 local group enemies = CreateGroup()                //When you create a group in JASS, it's like a trigger. First you need it empty, and then you add stuff to it
 local unit temp                                    //Used when looping through the group
 local integer count = 5                            //This will be the maximum amount of enemies that can be hit
 local location temp_loc
 local real current_ms
 local effect specialEffectt 
 local location temp_caster_loc

    call GroupEnumUnitsInRangeOfLoc(enemies, start_position, 500.0, null)

// GroupEnumUnitsInRangeOfLoc takes a group, a location, a radius, and a boolexpr (a condition, kind of) and then gets units within that radius and adds them to our group
loop
    if count == 5 then
    set temp = GetSpellTargetUnit()
    set current_ms = GetUnitMoveSpeed(caster)
    call SetUnitInvulnerable(caster,true)
    call SetUnitMoveSpeed(caster,0)

    else
    set temp = FirstOfGroup(enemies)

    endif


    exitwhen temp == null or count == 0
    
    if IsUnitEnemy(temp, GetOwningPlayer(caster)) and IsUnitAliveBJ(temp) then //If the enemy unit is an enemy of the owner of the caster
        
        set temp_loc = GetUnitLoc(temp)                //Set a temporary location variable to the enemy position
        
        if count != 5 then 
        call TriggerSleepAction( 0.49 )
        call DestroyEffect(specialEffectt)

        endif 

        call SetUnitPositionLoc(caster, temp_loc)      //Move our unit instantly to the enemy's location
        set temp_caster_loc = GetUnitLoc(caster)
        set specialEffectt = AddSpecialEffectLoc("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl",temp_caster_loc)
        call RemoveLocation(temp_caster_loc)
        

        //call IssueTargetOrderBJ( caster , "attack", temp )
        call UnitDamageTarget(caster, temp, 150, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)

                                                       //The caster will instantly damage the enemy for 50 damage with an attack type of chaos
                                                       //You can ignore the damage type, and the last parameter (weapontype) is just for sound, but we will
                                                 //have none for right now
        
                                                 //A unit has been hit, so now the units left to hit is reduced by 1
        
        
        if (ModuloInteger(count,2)!=0) then
        call RemoveLocation(temp_loc)
        

        endif
        set count = count - 1

    endif 
    call GroupRemoveUnit(enemies, temp)

    if (ModuloInteger(count,2)!=0) then
        
        call GroupEnumUnitsInRangeOfLoc(enemies, temp_loc, 500.0, null)
        call RemoveLocation(temp_loc)
        
        
        endif 

endloop

                             //Cleaning up memory leaks will be put here
 call SetUnitInvulnerable(caster,false) 
 call SetUnitMoveSpeed(caster,current_ms)

 set caster = null
 call RemoveLocation(start_position)
 set start_position = null
 call DestroyGroup(enemies)
 set enemies = null
 
 set temp = null
 set temp_loc = null

 call DestroyEffect(specialEffectt)
 set specialEffectt = null
endfunction

function InitTrig_Slash takes nothing returns nothing
 set gg_trg_Slash = CreateTrigger() //Set the global variable that is created for our trigger to a new trigger

    call TriggerRegisterAnyUnitEventBJ(gg_trg_Slash, EVENT_PLAYER_UNIT_SPELL_EFFECT) //This BJ function registers an event for whenever a unit starts the effect
                                                                                     //of an ability for our trigger

    call TriggerAddCondition(gg_trg_Slash, Condition(function Slash_Condition))
    call TriggerAddAction(gg_trg_Slash, function Slash_Actions)
endfunction
my thoughts where if i would apply this change of group whenever the parity of the counter goes off count == 5 initial group ; count == 4 same group ; count 3 == new group...
 
Last edited:
Level 4
Joined
Feb 17, 2008
Messages
67
I guess not to many people have the patience/time to go through all that code
so to sum it up :
JASS:
call GroupEnumUnitsInRangeOfLoc(enemies, start_position, 500.0, null)
works nicely, but once i try to clear the group called "enemies" and re-use it like:
JASS:
call GroupEnumUnitsInRangeOfLoc(enemies, 1st_position, 500.0, null)
//ok so far
call GroupClear(enemies)
set enemies = null
call GroupEnumUnitsInRangeOfLoc(enemies, 2nd_position, 500.0, null)
// "enemies" remains empty or i am unable to pick up a new set of units or i am unable to get units form it via [  set temp = FirstOfGroup(enemies)  ]
can somebody tell me where i gone wrong?
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Simplify your code a bit.

GroupEnum clears the group, so you don't need to clear it before hand.

Don't null variables until you are totally done using them. Nulling them over and over again is pointless. I am speaking of enemies for one.

Surround your code in JASS tags. Nobody is going to want to bother looking at it with how it is now.

People normally use x,y coordinates in JASS, not locations. Locations are only used if it's going to be used over and over again for things like unit creation or if the Z coordinate needs to be retrieved.

Once you do all of the above, I'm sure people will then happily read your code = ).
 
Level 4
Joined
Feb 17, 2008
Messages
67
Thank you for the reply
Ok i have tagged my code and simplified it a bit though i'm not used to using coordinates instead of locations
 
Level 4
Joined
Feb 17, 2008
Messages
67
I can't believe it actually works
all i did was eliminate the = null 's that where put at the wrong spots
thank you Nestharus
PS: can you please point me to a/some common up-to-date jass tutorial/s?
 
Status
Not open for further replies.
Top