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
964
"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
964

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.
  • 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
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1

      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