• 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] what's wrong with this code?

Status
Not open for further replies.
Level 3
Joined
Sep 14, 2007
Messages
43
This code suppose to teleport a target unit infront of the caster, but it doesnt, so please tell me what's wrong with it.

JASS:
function Trig_Void_Tunnel_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A03T'
endfunction

function Trig_Void_Tunnel_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    call TriggerSleepAction(0.1)
    call SetUnitX(t, x + Cos(bj_RADTODEG * GetUnitFacing(u)) * 130)
    call SetUnitY(t, y + Sin(bj_RADTODEG * GetUnitFacing(u)) * 130)
    set u = null
    set t = null
endfunction
//===========================================================================
function InitTrig_Void_Tunnel takes nothing returns nothing
    set gg_trg_Void_Tunnel = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Void_Tunnel, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Void_Tunnel, Condition(function Trig_Void_Tunnel_Conditions))
    call TriggerAddAction(gg_trg_Void_Tunnel, function Trig_Void_Tunnel_Actions)
endfunction
 
Last edited by a moderator:
Level 20
Joined
Apr 22, 2007
Messages
1,960
GetUnitFacing() returns a real in degrees, not radians, so you don't use bj_RADTODEG, you use bj_DEGTORAD or CosBJ() or GetUnitFacing(u)*3.14159/180.

Also, even if you do TriggerSleepAction(0.1), the smallest amount of time TriggerSleepAction can work is 0.27 seconds (don't ask why, I don't know). You're better to use timers + globals or handle vars.

Also, watch out with SetUnitX and SetUnitY. If the targeted coordinate is outside map bounds, the map will fatal error.

EDIT: OMG POOT STOP STEALING MY POSTS!
 
Level 3
Joined
Sep 14, 2007
Messages
43
w8 there's something i dont understand.
if GetUnitFacing(u) returns degrees so why cant i just leave it that way?
why do i have to turn it to radians?
 
Level 3
Joined
Sep 14, 2007
Messages
43
so if i write shiftsin(0.5) in jass it will print pie/6 and not 30? :(
getunitface work with degs while trigo funcs work with rads... how can i tell which function work with deg and which with rads?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Wtf is 'shiftsin'? You mean Asin?

Everything that returns angles except custom functions (including BJs like AngleBetweenPoints) and GetUnitFacing return radians.

AngleBetweenPoints would return radians, but they multiply by bj_RADTODEG before returning it.



And shouldn't this be old news to you, if you already have done trigonometry? Or are they still making you use that accursed "Degree Mode" on the calculators?
 
Level 3
Joined
Sep 14, 2007
Messages
43
i dont know, i just finished highschool and i'm much more comfortable with degrees than with radians.
 
Status
Not open for further replies.
Top