1. Fill your cup and take your pick among the maps best suited for this year's Hive Cup. The 6th Melee Mapping Contest Poll is up!
    Dismiss Notice
  2. Shoot to thrill, play to kill. Sate your hunger with the 33rd Modeling Contest!
    Dismiss Notice
  3. Do you hear boss music? It's the 17th Mini Mapping Contest!
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[System] Supermarker (Unit marker)

Discussion in 'Graveyard' started by Krogoth, Aug 8, 2013.

  1. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    There is a lot of unit indexers, but no markers found :/
    Few words about this:
    - Marker does not really register units, but only marks them
    - Use GetUnitUserData to get unit state:
    >0 - alive
    =0 - dead
    <0 - decaying)
    - Marker recycles dead units periodically (each dead unit has minimum of RECYCLE_TIME before gets recycled)

    Code (vJASS):
    //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    //-=-=-=-] Supermarker [-=-=-=-
    //-=-=-=-=-= v0.900 -=-=-=-=-=-

    /*******************************************************
    * function InitSupermarker takes nothing returns nothing
    *     (Starts supermarker wonderwork)
    *******************************************************/


    library Supermarker requires Support
    //-=-=-=- Settings -=-=-=-
    globals
        private constant real RECYCLE_TIME = 20
    //-=-=-=-==-=-=-=-=-=-=-=-
        private trigger EnterTrigger = CreateTrigger()
        private trigger DeathTrigger = CreateTrigger()
        private integer IndexCount = 0
        private integer FreeindexCount = 0
        private integer array Freeindex
        private group Bathroom = CreateGroup()
    endglobals

        private function Mark takes nothing returns boolean
            set Support.workUnit = GetFilterUnit()
            if FreeindexCount == 0 then
                set IndexCount = IndexCount + 1
                call SetUnitUserData(Support.workUnit, IndexCount)
            else
                set FreeindexCount = FreeindexCount - 1
                call SetUnitUserData(Support.workUnit, Freeindex[FreeindexCount])
            endif
            return false
        endfunction

        private function Wash takes nothing returns boolean
            call GroupAddUnit(Bathroom, GetTriggerUnit())
            return false
        endfunction
       
        private function Grab takes nothing returns nothing
            loop
                set Support.workUnit = FirstOfGroup(Bathroom)
                exitwhen Support.workUnit == null
                set Support.workInteger = GetUnitUserData(Support.workUnit)
                if Support.workInteger > 0 then
                    call SetUnitUserData(Support.workUnit, -Support.workInteger)
                else
                    call GroupRemoveUnit(Bathroom, Support.workUnit)
                    set Support.workInteger = -Support.workInteger
                    if Support.workInteger == IndexCount then
                        set IndexCount = IndexCount - 1
                    endif
                    set Freeindex[FreeindexCount] = Support.workInteger
                    set FreeindexCount = FreeindexCount + 1
                endif
            endloop
        endfunction

        function InitSupermarker takes nothing returns nothing
            local region R = CreateRegion()
            set Support.workRect = GetWorldBounds()
            call RegionAddRect(R, Support.workRect)
            call GroupEnumUnitsInRect(Support.workGroup, Support.workRect, Condition(function Mark))
            call TriggerRegisterEnterRegion(EnterTrigger, R, Condition(function Mark))
            set R = null
            //! runtextmacro TriggerRegisterAnyUnitEvent("DeathTrigger")
            call TriggerAddCondition(DeathTrigger, Condition(function Wash))
            call TimerStart(CreateTimer(), RECYCLE_TIME, true, function Grab)
        endfunction
    endlibrary
     
    Last edited: Aug 10, 2013
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,429
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    This won't get approved since you modify the unit's user data. That is reserved for unit indexers.

    Instead, you should use a unit indexer and attach the data to it. e.g.:
    Code (vJASS):
    set marker[GetUnitUserData(u)] = 0 // or some value < 0 or > 0, depending on state


    Although, there may be other means of doing this:
    e.g. GetWidgetLife(u) > 0.405 [alive]
    IsUnitType(u, UNIT_TYPE_DEAD) and GetHandleId(u) != 0 [decaying or just died]
    IsUnitType(u, UNIT_TYPE_DEAD) and GetHandleId(u) == 0 [dead/fully decayed]

    If I'm not mistaken. I could be wrong though, so feel free to correct me.
     
  3. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    If a unit type is dead and it's unit type id isn't 0, then it may be decaying (some units are permanent, others are not).

    If a unit is alive (UnitAlive), then it's alive... lol

    I don't really know why you'd want to see if a unit is decaying, nor do I know of any good way to check for unit decay instantly, unless you only care whether a unit is dead or not (dead/existence).

    There is ofc a way to check when a unit decays =). See UnitEvent
     
  4. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    This is designed to people who do not use (!) unit indexers. That's why I tried to post a pack last time, because this may be not clear. :O
    Personally I am not using unit array, only bool fields for generic unit states / buffs
    (Invented by myself :ogre_hurrhurr:)
    Sure, but GetUnitUserData is a bit faster.

    Edit:
    Custom special effects attached to corpses / spells based on decaying units
    (Every decaying unit within AoE from the hero spreads Death Aura damaging all enemies around)
     
  5. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Rather than trying to invent all of your own stuff, just adopt the standards on THW, because likely, your attempts at making new standards will never get approved :\.

    Something is only approved if it has some clear advantage over currently approved resources, given that the two do the same thing or collide. That's just one thing.

    Can you clearly state why this resource holds some serious advantage over already approved resources? Why it has a serious advantage over natives?
     
  6. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    But this should be in theory compatible with unit indexers... because people can use this with it...

    now if you're gonna force users that want this to not use a unit indexer, then I'd rather just use other methods...

    personally I don't see the need for this... more so when it conflicts with a super useful script (used by a lot of other scripts)...

    And yeah, it is a THW standard to reserve UnitUserData for Unit indexer script... so better abide by that...
     
  7. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Well, there are some exceptions to the rule, when you can use SetUnitUserData. To use SetUnitUserData, the unit being set must not interact with the map in any way, they must be completely internal to the system. Furthermore, to purposefully disable a unit indexer so that unit user data isn't set, the same rule applies, the unit can't interact with the map in any way.
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,346
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Yeah, about this script:

    Code (vJASS):

            call RemoveRegion(R)
            set R = null
     


    Do you even know what kind of effect this will have on the EnterRegion event? These two lines tell me you haven't even given that much thought on this script. Why should we?
     
  9. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    ^ Fixed
     
  10. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Yet it still uses SetUnitUserData, lol, which is banned
     
  11. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Will fix this later
    There will be an option to use Unit Indexer's index, Supermarker's enter region event will be proced right after Unit Indexer's one
     
  12. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Any use of SetUnitUserData will make it so that this can't be approved, conditional or not. There are many unit indexers out there, so just checking for the existence of one is no good. There may also be custom ones that u can't check for.

    Using SetUnitUserData is banned unless it's for a unit indexer.

    If you are that against them. you can always use a table.
     
  13. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    How about easiest way ever
    I will make an option to use this as indexer directly
    (Striving for people)
     
  14. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Then it'll be super rejected.

    You can't make multi-purpose resources, those aren't allowed. A resource must have a single and direct purpose.
     
  15. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Okay, fuck this rules, fuck this forum. This is just going out of sanity
    Close thread
     
  16. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Don't give up Krogoth ;(

    edit
    If you want, I can help you code something that follows the standards, but ur going to have to have an open mind and accept THW standards :\
     
  17. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,783
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Graveyarded.