Some jass questions

Flare

Stops copies me!
Reaction score
662
JASS:
if distance < 50 then
    call BJDebugMsg ("If works")
    call PauseTimer (data.SlideTimer)
//Move everything below the data.destroy () above it
//Or use an onDestroy method (-slightly- more complicated)
    call data.destroy ()
    call ResetData (data.SlideTimer)
    call DestroyTimer (data.SlideTimer)
    call PauseUnit (data.target,true)
    call Effect(data.tx, data.ty, data.target)

endif
 

Kazuga

Let the game begin...
Reaction score
110
Hm the function isn't called for some reason and it has nothing to do with
JASS:
call data.destroy ()

Tested to kill it but it still didn't work o something must be wrong with
JASS:
    call Effect(data.tx, data.ty, data.target)

even though I get no errors :S

(Whole code)
JASS:
library HAILInit requires HAIL
//! runtextmacro HAIL_CreateProperty ("Data", "integer", "")
endlibrary
scope Lightnings initializer Lightning
globals
private constant integer raw = 'ANfl'
endglobals
private struct TestStruct
unit dummy
unit caster
unit target
real tx
real ty
timer SlideTimer
endstruct

private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == raw
endfunction

private function Effect takes real myX, real myY, unit Target returns nothing
    local TestStruct data = TestStruct.create ()
    local real x
    local real y
    local real x2
    local real y2
    local real real1 = 0
    set x  = myX + 300 * Cos((45)  * bj_DEGTORAD)
    set y  = myY + 300 * Sin((45)  * bj_DEGTORAD)
    set x2 = myX + 300 * Cos((315) * bj_DEGTORAD)
    set y2 = myY + 300 * Sin((315) * bj_DEGTORAD)
    

    call TriggerSleepAction (1.00)
    call TimedLightning ("CLPB", x2, y2, 0, myX, myY, 0, 2., true, 1, 0)
    call TimedLightning ("CLPB", x, y, 0, myX, myY, 0, 2., true, 1, 0)

    call BJDebugMsg("works")
    call PauseUnit (Target,false)
    call AddSpecialEffect("Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl",myX,myY)  
endfunction



private function Slide takes nothing returns nothing
local TestStruct data = GetData (GetExpiredTimer ())
local real x = GetUnitX(data.dummy)
local real y = GetUnitY(data.dummy)
local real newX
local real newY
local real angle
local real distance
local real real1=45
local real x2 
local real y2 



set data.tx    = GetUnitX(data.target)
set data.ty    = GetUnitY(data.target)
set angle = Atan2(data.ty-y,data.tx-x)
set newX  = x + 30 *Cos(angle)
set newY  = y + 30 *Sin(angle)

call SetUnitPosition(data.dummy,newX,newY)
call AddSpecialEffect("Abilities\\Weapons\\Bolt\\BoltImpact.mdl",newX,newY)
set distance=SquareRoot( (data.tx-x)*(data.tx-x) + (data.ty-y)*(data.ty-y) )
if distance < 50 then
    call BJDebugMsg ("If works")
    call PauseTimer (data.SlideTimer)
    call ResetData (data.SlideTimer)
    call DestroyTimer (data.SlideTimer)
    call PauseUnit (data.target,true)
    call Effect(data.tx, data.ty, data.target)
    call data.destroy ()
endif
endfunction


private function Actions takes nothing returns nothing
local TestStruct data = TestStruct.create ()
local unit Unit                    = GetTriggerUnit()
local real real1                   = GetUnitFacing(GetTriggerUnit())

local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())

local real x2 = x + 300 * Cos((real1+145)*bj_DEGTORAD)
local real y2 = y + 300 * Sin((real1+145)*bj_DEGTORAD)

local real x3 = x + 300 * Cos((real1+180)*bj_DEGTORAD)
local real y3 = y + 300 * Sin((real1+180)*bj_DEGTORAD)

local real x4 = x + 300 * Cos((real1+215)*bj_DEGTORAD)
local real y4 = y + 300 * Sin((real1+215)*bj_DEGTORAD)

set data.SlideTimer = CreateTimer()
set data.target = (GetSpellTargetUnit())
call AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl",x,y)
call TriggerSleepAction (0.1)
call AddSpecialEffect("Abilities\\Weapons\\Bolt\\BoltImpact.mdl",x2,y2)
call AddSpecialEffect("Abilities\\Weapons\\Bolt\\BoltImpact.mdl",x3,y3)
call AddSpecialEffect("Abilities\\Weapons\\Bolt\\BoltImpact.mdl",x4,y4)
call AddSpecialEffect("Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl",x,y)
call PauseUnit (Unit, true)

call TimedLightning ("CLPB", x, y, 0, x2, y2, 0, 2., true, 1, 0)
call TimedLightning ("CLPB", x, y, 0, x3, y3, 0, 2., true, 1, 0)
call TimedLightning ("CLPB", x, y, 0, x4, y4, 0, 2., true, 1, 0)


call TriggerSleepAction (1)
set data.dummy = CreateUnit (GetOwningPlayer(Unit),'h001',x,y,0)
call SetUnitPathing(data.dummy, false )
call PauseUnit (Unit, false)
call TimerStart (data.SlideTimer,0.05,true, function Slide)
call SetData (data.SlideTimer, data)
set Unit = null

endfunction


//===========================================================================

private function SafeFilt takes nothing returns boolean
return true
endfunction
private function Lightning takes nothing returns nothing
 local trigger trig = CreateTrigger()
local integer i = 0
loop
    exitwhen i > 15
    call TriggerRegisterPlayerUnitEvent(trig,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,Condition(function SafeFilt))
    set i = i + 1
endloop
 call TriggerAddCondition (trig, Condition (function Conditions ) )
 call TriggerAddAction (trig, function Actions )
 set trig = null
 endfunction

endscope
Edit: Wops sorry for doubleposting :(
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
What doesn't work?

And why is this line in your Effect function?

JASS:
    local TestStruct data = TestStruct.create ()
 

Kazuga

Let the game begin...
Reaction score
110
1: The Effect function isn't called.
2: It's there to declare the struct?
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
You do not need the struct in that function, therefore you can remove that line.
 

SerraAvenger

Cuz I can
Reaction score
234
2: It's there to declare the struct?

He wants to know why you declare it, you don't use it in the function anyway nor do you pass any information about the struct to other functions. The struct declaration seems somewhat pointless here.

Could you please try some Debug Messages?

you can use this tiny code here for short messages

JASS:

library Debug
globals
 debug    constant string        debugtag = "|cffff0303DEBUG: "
 debug    constant string        end      = "|r"
endglobals

function DebugMSG takes string MSG returns nothing
 debug    call DisplayTimedTextToPlayer( GetLocalPlayer() , 0 , 0 , 60 , debugtag + MSG + end )
endfunction

function DebugTAG takes string MSG , real x , real y returns nothing
 debug    local texttag TAG = CreateTextTag()
 debug    set MSG = debugtag + MSG + end
 debug    call SetTextTagText     ( TAG , MSG   , 0.23 )
 debug    call SetTextTagVelocity ( TAG , 0     , 0.71 / 25 )
 debug    call SetTextTagPermanent( TAG , false )
 debug    call SetTextTagLifespan ( TAG , 40    )
 debug    call SetTextTagFadepoint( TAG , 35    )
 debug    call SetTextTagPos      ( TAG , x , y , 0 )
 debug    set TAG = null
endfunction

//! textmacro DebugArray takes ARRAY , CONVERTER
function Debug$ARRAY$ takes integer start, integer end returns nothing
 debug    local integer iterator = start
 debug    loop
 debug        exitwhen iterator > end
 debug        call DebugMSG( $CONVERTER$( $ARRAY$[iterator] ) )
 debug        set iterator = iterator + 1
 debug    endloop
endfunction
//! endtextmacro
endlibrary

just do:
JASS:

call DebugMSG( R2S( x ) )

with all your variables after declaring them, and look if they show the right values.
 

Kazuga

Let the game begin...
Reaction score
110
Hm k I removed that line but it seems that it didn't cause the problem. The Effect function isn't calld for some strange reason...
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Just a wildshot: Try to change the order of these ones:

JASS:
set distance = SquareRoot( (data.tx-x)*(data.tx-x) + (data.ty-y)*(data.ty-y) )


To this:

JASS:
set distance = SquareRoot( (x-data.tx)*(x-data.tx) + (y-data.ty)*(y-data.ty) )
 

Kazuga

Let the game begin...
Reaction score
110
Made no difrence =/ Also, the if-then-else works. It's the calling of the Effect function that doesn't =/
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Try to remove that TriggerSleep() inside the Effect function just to see if that is affecting somehow.
 

Kazuga

Let the game begin...
Reaction score
110
Ah, yup it was the wait action... Thanks +rep for all the help:thup:

Edit: Hm why does the wait stop the trigger?
 

SerraAvenger

Cuz I can
Reaction score
234
Just a wildshot: Try to change the order of these ones:

JASS:
set distance = SquareRoot( (data.tx-x)*(data.tx-x) + (data.ty-y)*(data.ty-y) )


To this:

JASS:
set distance = SquareRoot( (x-data.tx)*(x-data.tx) + (y-data.ty)*(y-data.ty) )

This makes no difference because you are raising the difference to the 2nd power which will just return |x - data.tx|² (|| indicating the function:
|f| ={ f A f >= 0;
-f A f < 0 }
so it makes no difference whatsoever.


It stops it because the wait was in the condition. You may not call Waits in a trigger's condition, that is why I generally try to code the condition in my action. ( if [ conditions ] then ... else return endif )
 

Kazuga

Let the game begin...
Reaction score
110
How can the Effect function be a condition function?

Also I got a new question, I'm trying to create a unit group with all units within x range matching conditions (a:is alive) and (b:belongs to an enemy of owner of unit)
Like this in gui
Code:
Set UnitGroup = (Units within 512.00 of (Center of (Playable map area)) matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of Player 1 (Red)) Equal to True)))

But when converted it looks real wierd, it's 3-5 different functions =/

Are they really needed or can you do it with one simple call/set?
 

Kazuga

Let the game begin...
Reaction score
110
Hm so complicated for such an simple action (in gui atleast)..
Edit: Searched through all jass tutorials I could found, none of them teaches about unit groups etc =/

New question^^
I ran into a BJ, and since I know they are bad and should be avoided if possible I was wondering if there is any way to avoid this one:
JASS:
    call IssueImmediateOrderBJ( GetTriggerUnit(), &quot;thunderclap&quot; )

What I'm doing is ordering a unit to cast a spell (in this case a spell based on thunderclap). And as you can see it's a BJ =/

Any way to avoid it?
 

Kazuga

Let the game begin...
Reaction score
110
Hm back to the unit group thing, should I have all the functions alone and then call for the action or...? Sort of confusing to handle 4 functions for one action..

JASS:
function Trig_x_Func001002003001 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_x_Func001002003002 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true )
endfunction

function Trig_x_Func001002003 takes nothing returns boolean
    return GetBooleanAnd( Trig_x_Func001002003001(), Trig_x_Func001002003002() )
endfunction

function Trig_x_Actions takes nothing returns nothing
    set udg_z = GetUnitsInRangeOfLocMatching(512, GetUnitLoc(GetTriggerUnit()), Condition(function Trig_x_Func001002003))
endfunction

should be here?
JASS:
library HAILInit requires HAIL
//! runtextmacro HAIL_CreateProperty (&quot;Data&quot;, &quot;integer&quot;, &quot;&quot;)
endlibrary
scope Lightnings initializer Lightning
globals
private constant integer raw = &#039;A001&#039;
endglobals
private struct TestStruct
unit dummy
unit caster
unit target
real tx
real ty
timer SlideTimer
endstruct

private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == raw
endfunction


//Here?

private function Effect takes real myX, real myY, unit Target returns nothing
    local real x
    local real y
    local real x2
    local real y2
    local real real1 = 0
    local unit dummy
    
    set x  = myX + 300 * Cos((45)  * bj_DEGTORAD)
    set y  = myY + 300 * Sin((45)  * bj_DEGTORAD)
    set x2 = myX + 300 * Cos((315) * bj_DEGTORAD)
    set y2 = myY + 300 * Sin((315) * bj_DEGTORAD)
    
    call TimedLightning (&quot;CLPB&quot;, x2, y2, 0, myX, myY, 0, 2., true, 1, 0)
    call TimedLightning (&quot;CLPB&quot;, x, y, 0, myX, myY, 0, 2., true, 1, 0)

    set x  = myX + 300 * Cos((125)  * bj_DEGTORAD)
    set y  = myY + 300 * Sin((125)  * bj_DEGTORAD)
    set x2 = myX + 300 * Cos((225) * bj_DEGTORAD)
    set y2 = myY + 300 * Sin((225) * bj_DEGTORAD)
    
    call TimedLightning (&quot;CLPB&quot;, x2, y2, 0, myX, myY, 0, 2., true, 1, 0)
    call TimedLightning (&quot;CLPB&quot;, x, y, 0, myX, myY, 0, 2., true, 1, 0)

    call BJDebugMsg(&quot;wait works&quot;)
    call PauseUnit(Target,false)
    
    call AddSpecialEffect(&quot;Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl&quot;,myX,myY)  
endfunction


Edit: Also one small question, I'm trying to destroy this effect but it says that it's undeclared?

JASS:
local effect special1

JASS:
set special1 = AddSpecialEffect(&quot;Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl&quot;,x,y)
JASS:
call DestroyEffect(udg_special1)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top