AngleBetweenPoints, how to use the native ?

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Assuming two points (x1, y1) and (x2, y2),
the angle from point 1 to point 2 is
Atan2(y2 - y1, x2- x1)
and the angle from point 2 to point 1 is
Atan2(y1 - y2, x1 - x2)

The angle is returned in radians.


Then again, that line is already using it... what's the problem? (Other than trying to get the x-coordinate of a real...)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
well syntax check gives me that error, and i'm just wondering how to fix it?

EDIT: And also is this line necessary, since every syntax check gives me an error?

JASS:
set gg_trg_Untitled_Trigger_006 = CreateTrigger()
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well this is my trigger, wich variable should i use?

JASS:
function Spell_Check takes nothing returns boolean
    return (GetSpellAbilityId() == '0000')
endfunction

function Spell takes nothing returns nothing
local unit tunit = GetTriggerUnit()
    local location l = GetUnitLoc(tunit)
    local string s = "Abilities\\Spells\\Human\\Flare\\FlareCaster.mdl"
    call DestroyEffect(AddSpecialEffectLoc(s,l))
    call RemoveLocation(l)
    set l = null
endfunction

function Effects takes nothing returns nothing
local integer i = 1
local string e = "Abilities\\Spells\\Human\\Flare\\FlareCaster.mdl"
local string e2 = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
local unit u = GetTriggerUnit()
local location loc = GetUnitLoc(u)
local real xu = GetUnitX(u)
local real yu = GetUnitY(u)
local real x
local real y
local player p = GetOwningPlayer(u)
local integer unitid = 'h000'
local integer aid = 'Aloc'
local unit du
loop
exitwhen i>180
set x = xu+200*Cos((i*2)*bj_DEGTORAD)
set y = yu+200*Sin((i*2)*bj_DEGTORAD)
call DestroyEffect(AddSpecialEffect(e,x,y))
call DestroyEffect(AddSpecialEffect(e2,x,y))
call UnitDamagePoint(u,0,10,x,y,50,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
call RemoveLocation(loc)
set du = CreateUnit(p,unitid,xu,yu,(Atan2(GetLocationY(x)-(GetLocationY(yu)),(GetLocationX(y)-(GetLocationX(xu)))
call UnitAddAbility(du,aid)
set x = 0
set y = 0
set i = i+1
endloop
set i = 0
set xu = 0
set yu = 0
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_006 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_006 = CreateTrigger()
    call TriggerAddCondition(gg_trg_Untitled_Trigger_006,Condition(function Spell_Check))
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Untitled_Trigger_006,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_Untitled_Trigger_006,function Spell)
    call TriggerAddAction(gg_trg_Untitled_Trigger_006,function Effects)
endfunction
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Try this:

JASS:
(bj_RADTODEG*Atan2(y-yu,x-xu))


for your other problem:

JASS:
function InitTrig_Untitled_Trigger_006 takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerAddCondition(trig,Condition(function Spell_Check))
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(trig,function Spell)
    call TriggerAddAction(trig,function Effects)
endfunction

Thank you soo much!!! ..... And you also of course Acehart !!



EDIT: I also have this problem, this line gives me 2 errors:

JASS:
call UnitAddAbility(du,aid)


Errors:
"Missin')'"
"syntax error"

It's in the same trigger so just check the upper post for locals
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Oh ok that worked !!!! didn't know "Missin')'" was reffering to the line before it!

EDIT: BTW, how do i know how long it takes for a unit with the movement speed 100 to move 200 distance ???
is there somekind of function for that ??
 

Komaqtion

You can change this now in User CP.
Reaction score
469
can i somehow add an epiration timer to a dummy unit then for 2 seconds??? i looked up what function the BJ used and it said that i need a buffID... what should this be ?
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok thanks !guys, but now i did this with the trigger to not use a BJ in the "TriggerRegisterAnyUnitEventBJ"

JASS:
function Trigger takes nothing returns nothing
    local integer index
    local trigger Spell = CreateTrigger()
    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(Spell,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        call TriggerAddCondition(Spell,Condition(function Spell_Check))
        call TriggerAddAction(Spell,function Spell_Stuff)
        call TriggerAddAction(Spell,function Effects)
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction


will this work or will i have to add the line:
call TriggerAddAction(Spell,function Trigger)

or something ?
 

Flare

Stops copies me!
Reaction score
662
JASS:
        call TriggerAddCondition(Spell,Condition(function Spell_Check))
        call TriggerAddAction(Spell,function Spell_Stuff)
        call TriggerAddAction(Spell,function Effects)

1) Do you need 2 separate sets of actions associated with the trigger?
2) Move those out of the loop, otherwise they will be added 16 times, and I doubt you want the trigger to run 16 times over whenever the event fires
 

Kenny

Back for now.
Reaction score
202
JASS:
function True takes nothing returns boolean
    return true
endfunction

function Trigger takes nothing returns nothing
    local trigger Spell = CreateTrigger()
    local integer index = 0

    loop
        call TriggerRegisterPlayerUnitEvent(Spell,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,Filter(function True))
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop

    call TriggerAddCondition(Spell,Condition(function Spell_Check))
    call TriggerAddAction(Spell,function Spell_Stuff)
    call TriggerAddAction(Spell,function Effects)
endfunction


The whole point of not using the BJ for the event is so that you do not leak the boolexpr or whatever. In yours you still put null for it, therefore it was doing nothing. Thats where:

JASS:
function True takes nothing returns boolean
    return true
endfunction


Comes in handy, it does nothing at all except stop the leak.

As Flare has said, the conditions and actions only need to be added once, so they are out of the loop, while the event needs to be added for each player. Also you may as well initialize index as 0 at the locals section. Again as Flare said, you probably only need one action, so try merging the two action triggers together if you want.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Thanks sooo much !!! but i still don't understand that about
JASS:
function True takes nothing returns boolean
    return true
endfunction

does that prevent somekind of leak???
And should i use this function in all of my triggers then ??

sorry, but i'm new to JASS XD

EDIT: And also btw, where can i find all of the order strings and like weapon types and stuff???

EDIT2: This is what the trigger looks like now, but all of a sudden, i doesn't do anything XD

JASS:
function Spell_Check takes nothing returns boolean
    return (GetSpellAbilityId() == '0000')
endfunction

function True takes nothing returns boolean
    return true
endfunction

function Effects takes nothing returns nothing
    local string o = "move"
    local integer i = 0
    local string e = "Abilities\\Spells\\Human\\Flare\\FlareCaster.mdl"
    local string e2 = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
    local unit u = GetTriggerUnit()
    local real xu = GetUnitX(u)
    local real yu = GetUnitY(u)
    local real x
    local real y
    local player p = GetOwningPlayer(u)
    local integer unitid = 'h000'
    local integer aid = 'Aloc'
    local integer bid = 'BTLF'
    local unit du
    call DestroyEffect(AddSpecialEffect(e,xu,yu))
    loop
        exitwhen i>16
        set x = xu+200*Cos((i*22.5)*bj_DEGTORAD)
        set y = yu+200*Sin((i*22.5)*bj_DEGTORAD)
        call DestroyEffect(AddSpecialEffect(e,x,y))
        call DestroyEffect(AddSpecialEffect(e2,x,y))
        call UnitDamagePoint(u,0,10,x,y,50,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
        set du = CreateUnit(p,unitid,xu,yu,bj_RADTODEG*Atan2(y-yu,x-xu))
        call UnitApplyTimedLife(du,bid,2.)
        call UnitAddAbility(du,aid)
        call IssuePointOrder(u,o,x,y)
        set x = 0
        set y = 0
        set i = i+1
        set du = null
    endloop
    set u = null
    set p = null
    set unitid = 0
    set aid = 0
    set bid = 0
    set i = 0
    set xu = 0
    set yu = 0
endfunction

function Trigger takes nothing returns nothing
    local integer index = 0
    local trigger Spell = CreateTrigger()
    loop
        call TriggerRegisterPlayerUnitEvent(Spell,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition(Spell,Condition(function Spell_Check))
    call TriggerAddAction(Spell,function Effects)
endfunction
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
If you put null where there should be a boolexpr, it leaks. Using that return true function prevents that.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
oh ok, so you mean that i can put null in any boolexpr now and it won't leak ?
 

Viikuna

No Marlo no game.
Reaction score
265
Didnt Troll Brain just proved that null booleanexpr does not leak in trigger events, or did I miss something?

Edit. Anyways, even if it leaks it doenst really matter, since that function is only called in map init. Im not sure if it leaks or not, so you should test it by yourself.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top