1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. 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.

[vJASS] Just a question about Magtheridon's system

Discussion in 'Triggers & Scripts' started by Krogoth, Oct 8, 2012.

  1. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Magtheridon96's RegisterPlayerUnitEvent:
    Code (vJASS):
    /**************************************************************
    *
    *   RegisterPlayerUnitEvent
    *   v5.1.0.0
    *   By Magtheridon96
    *
    *   I would like to give a special thanks to Bribe, azlier
    *   and BBQ for improving this library. For modularity, it only
    *   supports player unit events.
    *
    *   Functions passed to RegisterPlayerUnitEvent must either
    *   return a boolean (false) or nothing. (Which is a Pro)
    *
    *   Warning:
    *   --------
    *
    *       - Don't use TriggerSleepAction inside registered code.
    *       - Don't destroy a trigger unless you really know what you're doing.
    *
    *   API:
    *   ----
    *
    *       - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
    *           - Registers code that will execute when an event fires.
    *       - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
    *           - Registers code that will execute when an event fires for a certain player.
    *       - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
    *           - Returns the trigger corresponding to ALL functions of a playerunitevent.
    *
    **************************************************************/

    library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
        globals
            private trigger array t
        endglobals
       
        function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
            local integer i = GetHandleId(p)
            local integer k = 15
            if t[i] == null then
                set t[i] = CreateTrigger()
                loop
                    call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
                    exitwhen k == 0
                    set k = k - 1
                endloop
            endif
            call TriggerAddCondition(t[i], Filter(c))
        endfunction
       
        function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
            local integer i = 260 + 16 * GetHandleId(p) + GetPlayerId(pl)
            if t[i] == null then
                set t[i] = CreateTrigger()
                call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
            endif
            call TriggerAddCondition(t[i], Filter(c))
        endfunction
       
        function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
            return t[GetHandleId(p)]
        endfunction
    endlibrary
    Just this:
    Code (vJASS):
        local integer i = 260 + 16 * GetHandleId(p) + GetPlayerId(pl)

    "16 * GetHandleId(p) + GetPlayerId(pl)" is clear for me but what does "260" mean? There is no "260" in "RegisterPlayerUnitEvent" but it's in "RegisterPlayerUnitEventForPlayer". They should have or not have both because there is no principal difference I guess.
     
    Last edited: Oct 15, 2012
  2. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Looks like he's reserving the first 260 indices for RegisterPlayerUnitEvent and the rest for ...ForPlayer.
     
  3. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Does 260 mean maximum playerunitevent handle?
     
  4. Yixx

    Yixx

    Joined:
    Oct 12, 2008
    Messages:
    1,492
    Resources:
    3
    Spells:
    3
    Resources:
    3
    Probably there are 260 PlayerUnitEvent's or indeed the maximum handleId of all PlayerUnitEvent's is 260, knowing how Mag thinks (abit), but you would have to ask him to clarify the 260 constant to know it for sure, because it is, after all, his resource..
     
  5. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Yes.

    The highest handle id for a playerunitevent is 277,
    so I need to reserve indices 0-277 for RegisterPlayerUnitEvent.

    260 + 16 * GetHandleId(p) + GetPlayerId(pl)
    -> The handle id will never be less than 18 and the player id can be 0,
    so 260 + 16 * 18 => something greater than 277, and thus, the first 278 indices are reserved.

    Then again, looking at this now, I realized that the 260 constant can be removed while still allowing me to reserve all the indices O:

    edit
    Problem is, I assumed the handle Ids were going to start from 1.
    That's why I put that '260' in there back then ;P
    I've updated my resource.
     
  6. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    I think it should be...
    1)
    Code (vJASS):
    function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
           local integer i = GetHandleId(p) - 18

    2)
    Code (vJASS):
    function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
            local integer i = 260 + 16 * (GetHandleId(p) - 18) + GetPlayerId(pl)