Death Trigger

Cheesy

some fucker
Reaction score
95
Alright, back with another problem.

I have a trigger called Death that runs every 5.00 seconds. It picks a random number of 3 - 6 footmen and explodes them instantly. However it's not working. ( Obviously :rolleyes: ) Anyways, could anyone tell me why? Here is my code:

JASS:
function PickAllConditions1 takes nothing returns boolean
    return ( GetUnitTypeId(GetEnumUnit()) == 'hfoo' )
endfunction

function PickAllActions1 takes nothing returns nothing
    call ExplodeUnitBJ( GetEnumUnit() )
endfunction

function Trig_Death_Actions takes nothing returns nothing
    call ForGroupBJ( GetRandomSubGroup(GetRandomInt(3, 6), GetUnitsOfPlayerMatching(Player(1), Condition(function PickAllConditions1))), function PickAllActions1 )
endfunction

//===========================================================================
function InitTrig_Death takes nothing returns nothing
    set gg_trg_Death = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Death, 5.00 )
    call TriggerAddAction( gg_trg_Death, function Trig_Death_Actions )
endfunction
 

Flare

Stops copies me!
Reaction score
662
Can't see what's wrong there - add a few BJDebugMsg's in your functions e.g.
JASS:
function PickAllConditions1 takes nothing returns boolean
call BJDebugMsg ("Filter")
    return ( GetUnitTypeId(GetEnumUnit()) == 'hfoo' )
endfunction

function PickAllActions1 takes nothing returns nothing
call BJDebugMsg ("ForGroup")
    call ExplodeUnitBJ( GetEnumUnit() )
endfunction

function Trig_Death_Actions takes nothing returns nothing
call BJDebugMsg ("Trigger")
    call ForGroupBJ( GetRandomSubGroup(GetRandomInt(3, 6), GetUnitsOfPlayerMatching(Player(1), Condition(function PickAllConditions1))), function PickAllActions1 )
endfunction


And fix your leaks :p
 

Cheesy

some fucker
Reaction score
95
Ahh, thanks for clearing that up, I'll try it out when I get home from school and post my results. :thup:
 

Cheesy

some fucker
Reaction score
95
Alright, I did a lot of thinking and changed my code but it isn't that great. It is supposed to kill the set number of units and then display how many units were killed, ( Sounds easy, eh? ) and it turns out I was way off target. It kills the units* and displays the message fine, but it displays 4 messages with 2 of them as different numbers.

ex.
4 units killed!
4 units killed!
3 units killed!
3 units killed!


however the numbers change.

Here is my code:

JASS:
function PickAllConditions1 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'hfoo' )
endfunction

function PickAllActions1 takes nothing returns nothing
    local group g = GetUnitsInRectAll( gg_rct_Region_010 )
    local integer i = 1
    local integer ii = GetRandomInt( 2, 5 )
    local unit u = GetEnumUnit()
    loop
        exitwhen ( i >= ii )
        call GroupPickRandomUnit( g )
        call ExplodeUnitBJ( u )
        call GroupRemoveUnit( g, u )
        set i = (i + 1)
    endloop
    call DisplayTextToForce( GetPlayersAll(), I2S( ii ) + " units killed!" )
endfunction

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

function Trig_Death_Actions takes nothing returns nothing
    call ForGroup( GetUnitsOfPlayerMatching( Player(1), Condition( function PickAllConditions1 )), function PickAllActions1 )
endfunction

//===========================================================================
    function InitTrig_Death takes nothing returns nothing
    set gg_trg_Death = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Death, 8.00 )
    call TriggerAddAction( gg_trg_Death, function Trig_Death_Actions )
endfunction



Any ideas?


EDIT:

* It seems that it's killing every footman owned by Player(1) instead of the set number, 'i'.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> GetUnitsOfPlayerMatching( Player(1), Condition( function PickAllConditions1 ))

That line creates a unit group with all Footmen of player 1.

> call ForGroup( ..., function PickAllActions1 )

Then it runs your function for each and every unit in that group.


> local group g = GetUnitsInRectAll( gg_rct_Region_010 )

All units in some region... what are those for?

> call GroupPickRandomUnit( g )

Well, yes.
This will run a loop on your group, determine a random unit and .... then it forgets what it was doing.
It returns that unit but since you're calling it instead of storing the result, might just as well remove that line.

> call ExplodeUnitBJ( u )

On every run in your loop, the same "picked unit" is killed...
Once is enough.
It's probably not the unit you think this kills.

> call GroupRemoveUnit( g, u )

This is also pointless.
You're not doing anything with that group.
Why remove the unit 2 to 5 times? Once would do.
Why is that group even there?
Or, what would removing do since the group is reset for each picked unit anyway?



Set UnitGroup = Units owned by Player 1 matching (((Matching unit) is a Footman) equal to true)
Set TempInteger = Random integer between 2 and 5
For each Integer A from 1 to TempInteger, do
- Set Unit = Random unit from UnitGroup
- Unit group - Remove Unit from UnitGroup
- Unit - Explode Unit

You may want to test if there actually are "TempInteger" units in your group.
 

Cheesy

some fucker
Reaction score
95
Thank you so much AceHart, it works perfectly now. If anyone cares here is my current code.

JASS:
function Trig_Death_Conditions1 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'hfoo' )
endfunction

function Trig_Death_Actions takes nothing returns nothing
    local unit Unit
    local group UnitGroup = GetUnitsOfPlayerMatching( Player(1), Condition( function Trig_Death_Conditions1 ))
    local integer TempInteger = GetRandomInt( 4, 7 )
    local integer LoopStart = 1
    local integer UnitsKilled = 0
    loop
        exitwhen LoopStart > TempInteger
        set Unit = GroupPickRandomUnit(UnitGroup)
        call GroupRemoveUnitSimple( Unit, UnitGroup )
        call ExplodeUnitBJ( Unit )
        set UnitsKilled = ( UnitsKilled + 1 )
        set LoopStart = ( LoopStart + 1 )
    endloop
    call DisplayTextToForce( GetPlayersAll(), ( I2S(UnitsKilled) + " Units exploded!" ) )
    set LoopStart = 1
    set UnitsKilled = 0
    call DestroyGroup( UnitGroup )
endfunction

//===========================================================================
function InitTrig_Death takes nothing returns nothing
    set gg_trg_Death = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Death, 8.00 )
    call TriggerAddAction( gg_trg_Death, function Trig_Death_Actions )
endfunction
 

Cheesy

some fucker
Reaction score
95
What's wrong with BJ's anyways? Everyone's always saying, "Eww, a BJ, better get rid of it." What do they do anyways? How do they differ from regular functions?
 

Sevion

The DIY Ninja
Reaction score
413
Native: 1 call.



BJ: 2+ calls.



Turns into:

JASS:
function GetUnitAbilityLevelSwapped takes integer abilcode, unit whichUnit returns integer
    return GetUnitAbilityLevel(whichUnit, abilcode)
endfunction


So. Look at it this way, you have 2 roads to take.

The road on the right has a hole that spans across it, but you can easily jump it.

The road on the left has two holes that span across it, but you can still jump them.

What takes more time and energy? Jumping across the two holes.

It's the same way with programming. Calling 2 functions take more time than calling 1 function.

Besides, a lot of BJ's leak.
 

Cheesy

some fucker
Reaction score
95
Ahh. So basically a BJ function just calls another function? That's just nonsense! I don't really see any point to that whatsoever. Why are they even there if they just take longer to use?
 

Sevion

The DIY Ninja
Reaction score
413
So they could create UI's for GUI easier.

So taking the above sample:

JASS:
native          GetUnitAbilityLevel takes unit whichUnit, integer abilcode returns integer


And:

JASS:
function GetUnitAbilityLevelSwapped takes integer abilcode, unit whichUnit returns integer
    return GetUnitAbilityLevel(whichUnit, abilcode)
endfunction


With the native, you'd see something like:

"Level of an ability for <Unit> <Ability>"

Whereas in the BJ, you get:

"Level of <Ability> for <Unit>"

Blizzard is just stupid and didn't put the arguments in the right order the first time.
 

Romek

Super Moderator
Reaction score
963
"Level of an ability for <Unit> <Ability>"

Whereas in the BJ, you get:

"Level of <Ability> for <Unit>"

Not really.. You could do:
"<Units> Level of <Ability>"

And some BJ's, such as DestroyEffectBJ make no difference what-so-ever since they only take 1 argument.

Actually, on another note, Some BJ's which take more than 1 argument don't re-arrange them.
 

Romek

Super Moderator
Reaction score
963

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> So why would BJ's be created for those '1 argument' functions?

To keep it simple. And future-proof (patches for example).

If, some day, some patch requires a function to take slightly different parameters, or one more than before,
you do not want to edit 500 functions in different places.
You want to edit one single spot and it works.

Once you start there, you do it all there, you do not keep a list of "functions that will never change anyway".
Or some crap like, if the GUI uses this function, it's from here, else it's from here, or... wait, where was that again?
You'll never get anything done there.

If you're a company like Blizzard, you really need working products (as much as that's possible that is).

Nothing strange there.


Additionally, it also simplifies development.
As in, they were able to provide Blizzard.j to the "GUI" team "here's the functions, use those and we make sure they work".
All the while, at the same time, some other team could handle the details.
So you get two teams that can actually do some work, instead of having to wait on each other.
Time is money, even when you make several millions a month :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top