Snippet ConstructionStatus

Troll-Brain

You can change this now in User CP.
Reaction score
85
Requires vJass and GroupUtils.

This is just a simple library to know if an unit is being built, upgraded or finished, it will return false if the unit is dead.

JASS:
library ConstructionStatus initializer init uses GroupUtils

globals
    private constant real TIME_OUT = 30.0 // It is the periodic time (seconds) which the group will be refreshed (ghost units are removed)
endglobals

//==============================================================================
//  ConstructionStatus -- by Troll-Brain -- v 1.2
//==============================================================================
//
//  PURPOUSE:
//       * To know if an unit is finished, or being built/upgraded
//       * Note that it doesn't care about trained units, but ofc a trained unit will be considered as finished
//
//  HOW TO USE:
//       * function IsUnitFinished takes unit u returns boolean
//       * function IsUnitBeingBuilt takes unit u returns boolean
//       * function IsUnitBeingUpgraded takes unit u returns boolean
//
//       * Note that these 3 functions will return false if the unit is dead or not valid (for example == null)
//
//  PROS: 
//       * Easy to use, can be done in a single custom script for gui users
//         
//  CONS:
//       * It will fail if the unit has an usable revive ability if the unit die during the upgrade or construction
//       * I could handle it thought, let me know if you have the use of it, but then you have to know that it will require more stuff
//
//  DETAILS:
//       * I simply catch construct and upgrade events
//
//  THANKS TO:
//       * Rising_Dusk : to tell me that i've forgotten the upgraded units
//       * grim001 : for more sexy functions/library names 

//
//  HOW TO IMPORT:
//       * Just create a trigger named ConstructionStatus
//       * convert it to text and replace the whole trigger text with this one
//       * Do the same for the library GroupUtils if you don't already use it
//
//==============================================================================

globals
    private group BeingBuiltUnits
    private group BeingUpgradedUnits
endglobals

function IsUnitFinished takes unit u returns boolean
    return GetUnitTypeId(u) != 0 and not IsUnitType(u,UNIT_TYPE_DEAD) and not IsUnitInGroup(u,BeingBuiltUnits) and not IsUnitInGroup(u,BeingUpgradedUnits)
endfunction

function IsUnitBeingBuilt takes unit u returns boolean
    return not IsUnitType(u,UNIT_TYPE_DEAD) and IsUnitInGroup(u,BeingBuiltUnits)
endfunction

function IsUnitBeingUpgraded takes unit u returns boolean
    return not IsUnitType(u,UNIT_TYPE_DEAD) and IsUnitInGroup(u,BeingUpgradedUnits)
endfunction

private function HandleUnits takes nothing returns boolean
    
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_START then
        call GroupAddUnit(BeingBuiltUnits,GetConstructingStructure())
        
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_FINISH then
        call GroupRemoveUnit(BeingBuiltUnits,GetConstructedStructure())
        
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_UPGRADE_START then
        call GroupAddUnit(BeingUpgradedUnits,(GetTriggerUnit()))
        
    else
        call GroupRemoveUnit(BeingUpgradedUnits,GetTriggerUnit())
    endif

    return false
endfunction

private function RefreshGroup takes nothing returns nothing
    call GroupRefresh(BeingBuiltUnits)
    call GroupRefresh(BeingUpgradedUnits)
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local timer tim = CreateTimer()

    set BeingBuiltUnits = NewGroup()
    set BeingUpgradedUnits = NewGroup()
    call TimerStart(tim,TIME_OUT,true,function RefreshGroup)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_CONSTRUCT_START)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_UPGRADE_START)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_UPGRADE_FINISH)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_UPGRADE_CANCEL)
    call TriggerAddCondition(trig,Condition(function HandleUnits))
    
    // unneeded but i tend to null all handles, even if it is never destroyed 
    set trig = null
    set tim = null
endfunction

//==============================================================================
//  CHANGELOG
//==============================================================================
//
//  v 1.2 :
//       * IsUnitFinished return false instead of true when the unit argument is not valid.
//
//  v 1.1 :
//       * It handles upgrading units as well, so IsUnitBeingUpgraded is added
//
//  v 1.0 :
//       * Since the initial release didn't handle morphed units and units created by trigger,
//       * i've fixed that
//
//  v 0.1 :
//       * Initial release

endlibrary
 

Attachments

  • ConstructionStatus v1.2.w3x
    26.7 KB · Views: 289

Troll-Brain

You can change this now in User CP.
Reaction score
85
Why not, but is not a big deal to use the functions inside your own boolexpr, because you may need to do other checks, if unit is invulnerable, an enemy of the player X, and so one.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Last bump ever.
If you want approve it but something is wrong with this for you, tell me what.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Well i guess i'm a liar because it's a kind of bump, but meh nevermind, i only try to get the best answer to this problem :

I've found a bug.
When an unit die during it was constructed or upgraded and the unit has a revive ability, then when she is coming to life it takes the finished form (constructed/upgraded).
And the code doesn't handle that, since events doesn't fire in these special cases.

But now i'm wondering if someone would ever need a such thing, so i suggest to add theses kind of abilities during the game after the end constructing event, and disable them during the upgrading event. (ofc if the unit can be constructed/upgraded)
Let me know if i think wrong.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Wait, wait wait.
Maybe Jesus4Lyf is right. In the original version GroupRefresh was needed because i used only finish event, and added units only when it was finished, but then it didn't handle morphed and created units with CreateUnit...
But now maybe the event finish fire when an unit under construction dead or is removed, i will test it tomorrow.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Ok tested and the CANCEL events don't fire when an unit is killed/removed, so GroupRefresh is still needed.
For the worst and the best GroupRefresh is not anymore inside a single library but included in GroupUtils, so for completeness reason i use NewGroup(), instead of CreateGroup().

Back to the problem :

Troll-Brain said:
I've found a bug.
When an unit die during it was constructed or upgraded and the unit has a revive ability, then when she is coming to life it takes the finished form (constructed/upgraded).
And the code doesn't handle that, since events doesn't fire in these special cases.

But now i'm wondering if someone would ever need a such thing, so i suggest to add theses kind of abilities during the game after the end constructing event, and disable them during the upgrading event. (ofc if the unit can be constructed/upgraded)
Let me know if i think wrong.

What do you think about that ?
Should i track the revive event and handle it, or simply say in the documentation to avoid theses cases ?
 

asipo

New Member
Reaction score
15
Forgive me if because im new with JASS
I download the map and run it and it work just fine

However, when I save the map (ctrl+s)
It said there is an error on it which is on trigger ConstructionStatus, GroupUtils and display status
So does when I'm try to enable the trigger

So... how to solve this?
Because I want to use those trigger and put on my other map
 

Romek

Super Moderator
Reaction score
963
Approved. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      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