Trying to Learn..

SFilip

Gone but not forgotten
Reaction score
634
> where BJ's would be good
PolarProjectionBJ, AngleBetweenPoints, DistanceBetweenPoints if you don't know the formulas (mainly for reference since you probably want to use X and Y instead of locations)
PolledWait
Multiboard stuff
 

Exide

I am amazingly focused right now!
Reaction score
448
Wow. I solved it, at last. What a beauty!
My first succesful JASS trigger. :)
Only took me some 3 hours to code. Who said JASS was quicker than GUI? :p
This is the final result, I'm sure it could be better:

JASS:

function Trig_Hero_Respawning_Copy_Func027C takes nothing returns boolean
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(1) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(2) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(3) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(4) ) ) then
        return true
    endif
    return false
endfunction

function Trig_Hero_Respawning_Copy_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not Trig_Hero_Respawning_Copy_Func027C() ) then
        return false
    endif
    return true
endfunction

function Trig_Hero_Respawning_Copy_Actions takes nothing returns nothing
    local player owner = GetOwningPlayer(GetTriggerUnit())
    local unit hero = GetTriggerUnit()
    local location loc = GetRectCenter(gg_rct_Hero_Respawn_Region)
    local integer time

        if GetHeroLevel(GetTriggerUnit()) == 1 then
        set time = 20
    elseif GetHeroLevel(GetTriggerUnit()) == 2 then
        set time = 25
    elseif GetHeroLevel(GetTriggerUnit()) == 3 then
        set time = 30
    elseif GetHeroLevel(GetTriggerUnit()) == 4 then
        set time = 35
    elseif GetHeroLevel(GetTriggerUnit()) == 5 then
        set time = 40
    elseif GetHeroLevel(GetTriggerUnit()) == 6 then
        set time = 45
    elseif GetHeroLevel(GetTriggerUnit()) == 7 then
        set time = 50
    elseif GetHeroLevel(GetTriggerUnit()) == 8 then
        set time = 55
    else
        set time = 60
    endif

    call DisplayTimedTextToForce( udg_All_Players, 10.00, " " )
    call DisplayTimedTextToForce( udg_All_Players, 10.00, ( "|cff32cd32" + ( GetPlayerName(owner) + "'s Hero has been killed!|r" ) ) )
    call DisplayTimedTextToForce( udg_All_Players, 10.00, ( "|cff32cd32" + ( GetPlayerName(owner) + ( "'s Hero will respawn in " + ( I2S( time) + " seconds!|r" ) ) ) ) )
    call StartTimerBJ( udg_Respawn_Timer[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))], false, I2R( time) )
    call CreateTimerDialogBJ( udg_Respawn_Timer[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))], ( "|cff32cd32" + "Hero respawn in:|r" ) )
    set udg_Timer_Window[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = GetLastCreatedTimerDialogBJ()
    call TimerDialogDisplayBJ( false, GetLastCreatedTimerDialogBJ() )
    call TimerDialogDisplayForPlayerBJ( true, GetLastCreatedTimerDialogBJ(), GetOwningPlayer(GetTriggerUnit()))
    call TriggerSleepAction( I2R( time) )
    call TimerDialogDisplayForPlayerBJ( true, GetLastCreatedTimerDialogBJ(), owner)
    call DestroyTimerDialogBJ( udg_Timer_Window[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] )
    call PanCameraToTimedLocForPlayer( GetOwningPlayer(GetTriggerUnit()), loc, 0 )
    call ReviveHeroLoc( hero, loc, true )
    set loc = null
    set hero = null
    set owner = null
endfunction

//===========================================================================
function InitTrig_Hero_Respawning takes nothing returns nothing
    set gg_trg_Hero_Respawning = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Respawning, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hero_Respawning, Condition( function Trig_Hero_Respawning_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Hero_Respawning, function Trig_Hero_Respawning_Copy_Actions )
endfunction
 

substance

New Member
Reaction score
34
Well I dont know if someone mentioned this before (i didnt read the whole thread) but here are some things to make your code a bit easier.

Anytime You have a 'if statement' like this
JASS:
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
        return true
    endif
You can just doYou can simplify that condition even more by putting all those players in a group(aka a force), then asking if the triggering player is in that force. I imagine players 0-4 are some kind of 'team' or something on your map so using a force allow you to reference those players more easily. So you can turn this
JASS:
function Trig_Hero_Respawning_Copy_Func027C takes nothing returns boolean
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(1) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(2) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(3) ) ) then
        return true
    endif
    if ( ( GetOwningPlayer(GetTriggerUnit()) == Player(4) ) ) then
        return true
    endif
    return false
endfunction
To simply
JASS:
function Trig_Hero_Respawning_Copy_Func027C takes nothing returns boolean
return IsPlayerInForce(GetTriggerPlayer(), Team1)
endfunction
**This requires you to create the force and add the players to that force at Map Initialization.

Applying the above optimization to the other condition statement lets you simplify it from
JASS:
function Trig_Hero_Respawning_Copy_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not Trig_Hero_Respawning_Copy_Func027C() ) then
        return false
    endif
    return true
endfunction
to
JASS:
function Trig_Hero_Respawning_Copy_Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) and IsPlayerInForce(GetTriggerPlayer(), Team1)
endfunction
Isn't that alot better? You just turned 28 lines to 3 lines of easy code that makes sense.

If any of this is confusing just take your take a read the function over and over untill it does make sense. You're basically asking the question : Is the triggering unit a hero (and) is the triggering player in Team1? If the answer to that question is yes, it will return true if not, it will return false.

Moreso, you can turn that nasty 'if,then' script to set the time from
JASS:
        if GetHeroLevel(GetTriggerUnit()) == 1 then
        set time = 20
    elseif GetHeroLevel(GetTriggerUnit()) == 2 then
        set time = 25
    elseif GetHeroLevel(GetTriggerUnit()) == 3 then
        set time = 30
    elseif GetHeroLevel(GetTriggerUnit()) == 4 then
        set time = 35
    elseif GetHeroLevel(GetTriggerUnit()) == 5 then
        set time = 40
    elseif GetHeroLevel(GetTriggerUnit()) == 6 then
        set time = 45
    elseif GetHeroLevel(GetTriggerUnit()) == 7 then
        set time = 50
    elseif GetHeroLevel(GetTriggerUnit()) == 8 then
        set time = 55
    else
        set time = 60
    endif
to simply
JASS:
set time = 15 + 5 * GetHeroLevel(GetTriggerUnit())
So your trigger now looks like this
JASS:
function Trig_Hero_Respawning_Copy_Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) and IsPlayerInForce(GetTriggerPlayer(), Team1)
endfunction   
    
function Trig_Hero_Respawning_Copy_Actions takes nothing returns nothing
    local player owner = GetOwningPlayer(GetTriggerUnit())
    local unit hero = GetTriggerUnit()
    local location loc = GetRectCenter(gg_rct_Hero_Respawn_Region)
    local integer time = 15 + 5 * GetHeroLevel(hero)

    call DisplayTimedTextToForce( udg_All_Players, 10.00, " " )
    call DisplayTimedTextToForce( udg_All_Players, 10.00, ( "|cff32cd32" + ( GetPlayerName(owner) + "'s Hero has been killed!|r" ) ) )
    call DisplayTimedTextToForce( udg_All_Players, 10.00, ( "|cff32cd32" + ( GetPlayerName(owner) + ( "'s Hero will respawn in " + ( I2S( time) + " seconds!|r" ) ) ) ) )
    call StartTimerBJ( udg_Respawn_Timer[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))], false, I2R( time) )
    call CreateTimerDialogBJ( udg_Respawn_Timer[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))], ( "|cff32cd32" + "Hero respawn in:|r" ) )
    set udg_Timer_Window[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = GetLastCreatedTimerDialogBJ()
    call TimerDialogDisplayBJ( false, GetLastCreatedTimerDialogBJ() )
    call TimerDialogDisplayForPlayerBJ( true, GetLastCreatedTimerDialogBJ(), GetOwningPlayer(GetTriggerUnit()))
    call TriggerSleepAction( I2R( time) )
    call TimerDialogDisplayForPlayerBJ( true, GetLastCreatedTimerDialogBJ(), owner)
    call DestroyTimerDialogBJ( udg_Timer_Window[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] )
    call PanCameraToTimedLocForPlayer( GetOwningPlayer(GetTriggerUnit()), loc, 0 )
    call ReviveHeroLoc( hero, loc, true )
    set loc = null
    set hero = null
    set owner = null
endfunction

//===========================================================================
function InitTrig_Hero_Respawning takes nothing returns nothing
    set gg_trg_Hero_Respawning = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Respawning, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hero_Respawning, Condition( function Trig_Hero_Respawning_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Hero_Respawning, function Trig_Hero_Respawning_Copy_Actions )
endfunction


Also, I dunno why you use GetTriggerUnit() throughout the function when you set that unit to a variable at the beggning. There's a bunch of other things that could use tweaking like you should use coordinates instead of locations and you should get rid of all those BJ functions too... but I dont have the time now to show you how to fix all that, just use the search button.
 

Exide

I am amazingly focused right now!
Reaction score
448
It all looks very good when you write it.
Just one problem, it doesn't work.
I got 30 errors when trying your code..

I think three people told me about the

JASS:

    set time = 15 + 5 * GetHeroLevel(GetTriggerUnit())


That one doesn't work at all. If it did work, it wouldn't work with my map. If the hero that dies is level 56 or something, he'd be waiting forever to respawn. :p

EDIT: Oh, and how does:



work?
it says: Owner of triggering unit equal to player * *, right?
How is that an 'Or, multiple conditions'?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
set time = 15 + 5 * GetHeroLevel(GetTriggerUnit())
if time > 60 then
set time = 60
endif


> How is that an 'Or, multiple conditions'?

It isn't.
The function will return the result of the first test only.

Though you can combine them:
return test1() or test2() or test(3)
 

Exide

I am amazingly focused right now!
Reaction score
448
Ok, I added Tom Jones' if function, and it actually works. :)
Thanks!

I believe someone said this before, but I probably didn't understand what they were talking about back then; about my conditions: if Player owner of (Triggering unit) equal to Player * **

Code:
Or - Any (Conditions) are true
    Conditions
        (Owner of (Attacking unit)) Equal to Player 1 (Red)
        (Owner of (Attacking unit)) Equal to Player 2 (Blue)
        (Owner of (Attacking unit)) Equal to Player 3 (Teal)
        (Owner of (Attacking unit)) Equal to Player 4 (Purple)
        (Owner of (Attacking unit)) Equal to Player 5 (Yellow)

-that thing.
Looking at the way Tom optimized my timer, I figured this thing can be changed in a similar way as well?
Problem is, I don't know how. :p

EDIT: Oh, and. I was wondering about leaks. I'm used to taking care of leaks like: 'Custom Script call RemoveLocation(udg_Loc)', or similar. I believe the way to do it with locals is: 'set loc = null', correct?
Also, how do I know which ones needs "nulling", and can some not be nulled? Like 'local integer a = GetHeroLevel(hero)', can't seem to be nulled.
 

Arkan

Nobody rides for free
Reaction score
92
local locations and groups needs to be removed and destroyed just like global ones.
You null them AFTER you have destroyed/removed them.

JASS:
local location l = "somelocation"
local group g = CreateGroup()

call RemoveLocation(l)
call DestroyGroup(g)
set l = null
set g = null


You null everything except strings, players, integers and reals.
That includes units, forces, locations, groups, items etc.

About your condition question:
JASS:
function yourcondition takes nothing returns boolean
   local player p = GetOwningPlayer(GetAttacker())
   return p==Player(0) or p==Player(1) or p==Player(2) or p==Player(3) or p==Player(4)
endfunction
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
You null everything except strings, players, integers and reals.
That includes units, forces, locations, groups, items etc.

I'm gonna disagree. You null everything except strings, booleans, integers and reals. A local player is a handle, and you have to null it.

EDIT: Also, in the condition:

JASS:
function yourcondition takes nothing returns boolean
  local player p = GetOwningPlayer(GetAttacker())
  return p==Player(0) or p==Player(1) or p==Player(2) or p==Player(3) or p==Player(4)
endfunction


I'd use an integer, to avoid leaks (you're leaking a player):

JASS:
function yourcondition takes nothing returns boolean
  local integer id = GetPlayerId(GetOwningPlayer(GetAttacker()))
  return id<5
endfunction
 

Tom Jones

N/A
Reaction score
437
Yea, player is handle, but it's a constant handle, so no need for nulling. Same thing goes for boolexpr, and code.
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Does that mean that all instances/references of Player(0) have the same handle id?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> Does that mean that all instances/references of Player(0) have the same handle id?

Of course, you are refering to the same handle, which is a player that is added at the beggining of the game.
 

Exide

I am amazingly focused right now!
Reaction score
448

Arkan

Nobody rides for free
Reaction score
92
It's a condition, you see because it returns a boolean.
So put it above your actions.
 

Exide

I am amazingly focused right now!
Reaction score
448
Can I set a local variable under conditions?
How does
return id<5
work?
I thought < meant 2<1 - 2 is larger than 1?
 

Arkan

Nobody rides for free
Reaction score
92
You sure can.

How does
return id<5
work?

It means the condition will only be met if the player id is 0,1,2,3 or 4. Meaning it will only trigger for player 1-5.

< = less than
> = greater than
 

Exide

I am amazingly focused right now!
Reaction score
448
Cool, thanks. :)

Another question.
What types do I destroy?
Like: call RemoveLocation / DestroyGroup.. I only know those two. :p
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Search in JassCraft "Destroy". Important ones (for leaks):

Code:
DestroyEffect
DestroyForce
DestroyGroup
DestroyLeaderboard
DestroyLightning
DestroyTextTag
DestroyTimer
DestroyTrigger
 

Exide

I am amazingly focused right now!
Reaction score
448
Ok, thanks. :)

This is what my trigger looks like now, anything else I can improve?

JASS:

function Trig_Hero_Respawning_Func027C takes nothing returns boolean
    local integer id = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
    return id&lt;5
endfunction

function Trig_Hero_Respawning_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not Trig_Hero_Respawning_Func027C() ) then
        return false
    endif
    return true
endfunction

function Trig_Hero_Respawning_Actions takes nothing returns nothing
    local location loc = GetRectCenter(gg_rct_Hero_Respawn_Region)
    local player owner = GetOwningPlayer(GetTriggerUnit())
    local unit hero = GetTriggerUnit()
    local integer a = GetHeroLevel(hero)
    local integer time

    if a &lt;= 9 then
        set time = 15+(5*a)  
    else
        set time = 60
    endif

    call DisplayTimedTextToForce( udg_All_Players, 10.00, &quot; &quot; )
    call DisplayTimedTextToForce( udg_All_Players, 10.00, ( &quot;|cff32cd32&quot; + ( GetPlayerName(owner) + &quot;&#039;s Hero has been killed!|r&quot; ) ) )
    call DisplayTimedTextToForce( udg_All_Players, 10.00, ( &quot;|cff32cd32&quot; + ( GetPlayerName(owner) + ( &quot;&#039;s Hero will respawn in &quot; + ( I2S( time) + &quot; seconds!|r&quot; ) ) ) ) )
    call StartTimerBJ( udg_Respawn_Timer[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))], false, I2R( time) )
    call CreateTimerDialogBJ( udg_Respawn_Timer[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))], ( &quot;|cff32cd32&quot; + &quot;Hero respawn in:|r&quot; ) )
    set udg_Timer_Window[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = GetLastCreatedTimerDialogBJ()
    call TimerDialogDisplayBJ( false, GetLastCreatedTimerDialogBJ() )
    call TimerDialogDisplayForPlayerBJ( true, GetLastCreatedTimerDialogBJ(), GetOwningPlayer(GetTriggerUnit()))
    call TriggerSleepAction( I2R( time) )
    call TimerDialogDisplayForPlayerBJ( true, GetLastCreatedTimerDialogBJ(), owner)
    call DestroyTimerDialogBJ( udg_Timer_Window[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] )
    call PanCameraToTimedLocForPlayer( GetOwningPlayer(GetTriggerUnit()), loc, 0 )
    call ReviveHeroLoc( hero, loc, true )
    call RemoveLocation( loc)
    set loc = null
    set hero = null
    set owner = null
endfunction

//===========================================================================
function InitTrig_Hero_Respawning takes nothing returns nothing
    set gg_trg_Hero_Respawning = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Respawning, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hero_Respawning, Condition( function Trig_Hero_Respawning_Conditions ) )
    call TriggerAddAction( gg_trg_Hero_Respawning, function Trig_Hero_Respawning_Actions )
endfunction


How do I destroy a timer?
'call DestroyTimer(udg_Respawn_Timer)' ?
What about DestroyTrigger?
Should all triggers have a DestroyTrigger function or what? -I thought it did that automatically. :p
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
If you never want a trigger to run ever again, you call DestroyTrigger() on it.
 
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