• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Trigger don't work (angled missile)

Status
Not open for further replies.
Level 12
Joined
Mar 23, 2008
Messages
942
These two triggers are supposed to make a circular movement of two missiles in the direction of the target... But does nothing.

  • Kansho and Bakuya
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Kansho and Bakuya (based in channel)
    • Actions
      • Set SpellPoint[0] = (Position of (Casting unit))
      • Set SpellPoint[1] = (Position of (Target unit of ability being cast))
      • Set SpellPoint[2] = (SpellPoint[1] offset by ((Distance between SpellPoint[0] and SpellPoint[1]) / 2.00) towards (Angle from SpellPoint[1] to SpellPoint[0]) degrees)
      • Unit - Create 1 Kansho and Bakuya for Neutral Victim at SpellPoint[0] facing SpellPoint[1]
      • Unit - Set Rally-Point for (Last created unit) to SpellPoint[2]
      • Unit - Create 1 Kansho and Bakuya for Neutral Extra at SpellPoint[0] facing SpellPoint[1]
      • Unit - Set Rally-Point for (Last created unit) to SpellPoint[2]
      • Trigger - Turn on Kansho and Bakuya missile <gen>
      • Custom script: call RemoveLocation(udg_SpellPoint[0])
      • Custom script: call RemoveLocation(udg_SpellPoint[1])
      • Custom script: call RemoveLocation(udg_SpellPoint[2])
JASS:
function Trig_Kansho_and_Bakuya_missile_Func001001002 takes nothing returns boolean
    return (GetUnitTypeId(GetFilterUnit()) == 'h00H')
endfunction

function Trig_Kansho_and_Bakuya_missile_Func001A takes nothing returns nothing
    local location epos
    local location center
    local location x
    local real r
    local real angle
    local real angleplus
    local real fim
    local real dist
    if ((GetOwningPlayer(GetEnumUnit()) == Player(bj_PLAYER_NEUTRAL_VICTIM))) then
        set center = GetUnitRallyPoint(GetEnumUnit())
        set x = GetUnitLoc(GetEnumUnit())
        set r = DistanceBetweenPoints(x, center)
        set angle = AngleBetweenPoints(center, x)
        set angleplus = (angle + (360 / 3.14159265*r))
        call SetUnitPositionLoc(GetEnumUnit(), PolarProjectionBJ(center, r, angleplus))
    else
        set center = GetUnitRallyPoint(GetEnumUnit())
        set x = GetUnitLoc(GetEnumUnit())
        set r = DistanceBetweenPoints(x, center)
        set angle = AngleBetweenPoints(center, x)
        set angleplus = (angle - (360 / 3.14159265*r))
        call SetUnitPositionLoc(GetEnumUnit(), PolarProjectionBJ(center, r, angleplus))
    endif
endfunction

function Trig_Kansho_and_Bakuya_missile_Actions takes nothing returns nothing
    set bj_wantDestroyGroup = true
    call ForGroupBJ(GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Kansho_and_Bakuya_missile_Func001001002)), function Trig_Kansho_and_Bakuya_missile_Func001A)
endfunction

//===========================================================================
function InitTrig_Kansho_and_Bakuya_missile takes nothing returns nothing
    set gg_trg_Kansho_and_Bakuya_missile = CreateTrigger(  )
    call DisableTrigger( gg_trg_Kansho_and_Bakuya_missile )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Kansho_and_Bakuya_missile, 0.04 )
    call TriggerAddAction( gg_trg_Kansho_and_Bakuya_missile, function Trig_Kansho_and_Bakuya_missile_Actions )
endfunction

*I know that is still missing the event to stop the jass trigger from running, but first I need to make it work to later stop it xD
 
Level 11
Joined
Oct 13, 2005
Messages
233
I just tested out your code, and it actually works... somewhat. To test it, I copied your triggers exactly and used a peasant as the unit to be moved and created a custom ability based off of channel with a unit target.

What happens is the two units are created and do rotate around a point, but it's surely not where you would like it to be. If you could be a bit more clear on exactly how you want the units to be moving (around the enemy unit, around the targeted point, etc.), I would gladly help you fix your triggers.
 
Level 12
Joined
Mar 23, 2008
Messages
942
I want to make two units (based on spellbreaker missile) to spawn and goes on a circle-move toward the oponent.
Its something like Rexar axes, but with a circle instead of a ellipse.

Edit: Here the trigger don't work o.o

Edit2: Its a circle-move where the center is between the caster and the target.
The two missile spawn on the caster, and start moving following the "circle line" toward the target position.
 
Last edited:
Level 11
Joined
Oct 13, 2005
Messages
233
What you need to do is set the center to first start at the caster, and then have your "center" move towards the enemy. What is currently happening is the "center" for your spell is always at 0,0 at the map. This means that you likely cannot go on using rally points to try and set the center for the spell because it just isn't working.

Now, you'll need to use some sort of attachment system instead, either setting the unit's custom values to structs (if you're using vJASS with the JASS NewGen Pack) or perhaps handle variables if for some reason you're unable to use the NewGen pack. Basically, either of these methods will allow you to "attach" variables to the units such as who the caster is, who the enemy is, their locations, etc. and you'll be able to get those values while keeping your spell multi-instancible.

One other thing you should look into after getting the spell up and running is using timers instead of an external trigger that you enable and disable.

Also, I should probably mention that it's better practice to use real variables instead of locations because they don't cause memory leaks and in most cases will work more efficiently.
 
Level 12
Joined
Mar 23, 2008
Messages
942
But how I will use a real as a location? And for memory leak, inst only put RemoveLocation on the end?

Also, I use NewGen Pack, but I don't know structs or handle variables...
I'm a Jass newbie, this is like my third trigger on Jass (well, a converted to custom text trigger...)

I don't need it to be MUI, since only 1 hero can cast it, and can't have two heroes of the same type in game. Could you help-me how can I do that thing simple?
(Also, I could use an array of size 12, because if I want to add a mirror mode)
 
Level 11
Joined
Oct 13, 2005
Messages
233
If you're using reals, you'd have to know a bit more math instead of using the polar projection, angle between points, and distance between points functions. As for memory leaks, you're leaking more locations than you're actually aware of. Each call to PolarProjectBJ returns a location, which in turn must be removed with RemoveLocation. This is especially important in functions that are called frequently like yours.

Now, if you don't care about being MUI, you can use global variables to store things like the center location of the spell and so on. Just keep in mind that only one unit will be able to cast it at a time.

Finally, you can clean up your JASS functions a bit.
JASS:
function KanshoAndBakuya_Cond takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'h00H'
endfunction

function KanshoAndBakuyaActions takes nothing returns nothing
    local location epos   //What's this for? You're not using it at all!

    // Instead of having the exact same code twice, let's only have it done once

    local location center = GetUnitRallyPoint(GetEnumUnit())
    local location x = GetUnitLoc(GetEnumUnit())
    local real r = DistanceBetweenPoints(x, center)
    local real angle = AngleBetweenPoints(center, x)
    local real angleplus

    //Again, 2 variables you aren't using!

    local real fim  
    local real dist


    if ((GetOwningPlayer(GetEnumUnit()) == Player(bj_PLAYER_NEUTRAL_VICTIM))) then
        set angleplus = (angle + (360 / 3.14159265*r))
    else
        set angleplus = (angle - (360 / 3.14159265*r))
    endif

    // Found a use for the location you weren't using
    set epos = PolarProjectionBJ(center, r, angleplus)

    // Again, let's not have the exact same code twice
    call SetUnitPositionLoc(GetEnumUnit(), epos)

    //Remove locations to prevent memory leaks
    //See why locations aren't recommended? You need to clean them up
    call RemoveLocation(epos)
    call RemoveLocation(center)
    call RemoveLocation(x)

    set epos = null
    set center = null
    set x = null
endfunction

// Nothing wrong with your function right here; I'm just cleaning it up a bit
// Next time, try making the names of your functions more readable
function KanshoAndBakuya_TriggerAction takes nothing returns nothing
 local group g = GetUnitsInRectMatching(bj_mapInitialPlayableArea, Condition(function KanshoAndBakuya_Cond))
    call ForGroup(g, function KanshoAndBakuyaActions)
    call DestroyGroup(g)
 set g = null
endfunction

//===========================================================================
function InitTrig_Kansho_and_Bakuya_missile takes nothing returns nothing
    set gg_trg_Kansho_and_Bakuya_missile = CreateTrigger()
    call DisableTrigger(gg_trg_Kansho_and_Bakuya_missile)
    call TriggerRegisterTimerEventPeriodic(gg_trg_Kansho_and_Bakuya_missile, .04)
    call TriggerAddAction(gg_trg_Kansho_and_Bakuya_missile, function KanshoAndBakuya_TriggerAction)
endfunction
 
Level 12
Joined
Mar 23, 2008
Messages
942
I think I will just use a line missile... this is giving me so much trouble...

Where can I find a skill that only does damage? All the skills I look does damage and stun or anything else... I want some skill that only damage, or explode on target.
 
Level 11
Joined
Oct 13, 2005
Messages
233
Thanks for the new code!

I found why my code don't work, mine units have Locust... How can I move these units if they can't be picked with "Unit group"?

You must use GroupEnumUnitOfPlayer, if I remember right, in order to enumerate locusts. Basically, using "Units of player" is the only way to get pick units in a group. The better option in your case is to use variables or structs which refer to your units so you will have no need to enumerate the units each time.

Now, if I said that in a confusing way, let me rephrase that. Right now, you're picking all units on the map of a type and then doing actions. The locust units, as you've found out, are unable to be picked this way. Instead, if you wanted to pick units with locust, you must pick all units of a player matching a certain unit type in order to pick them. Doing is this way, however, is quite a hassle. The better option would be to store the units and all related data either in structs or as handle variables and work your spell around that. Otherwise, if you don't need the spell to be MUI, possibly as globals. By doing it this way, you will not need to pick units and have to deal with the locust problem.
 
Status
Not open for further replies.
Top