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,495
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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