• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Just a question about Magtheridon's system

Status
Not open for further replies.
Level 7
Joined
Apr 5, 2011
Messages
245
Magtheridon96's RegisterPlayerUnitEvent:
JASS:
/**************************************************************
*
*   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:
JASS:
    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:
Level 16
Joined
Oct 12, 2008
Messages
1,570
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..
 
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.
 
Level 7
Joined
Apr 5, 2011
Messages
245
I think it should be...
1)
JASS:
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
       local integer i = GetHandleId(p) - 18
2)
JASS:
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
        local integer i = 260 + 16 * (GetHandleId(p) - 18) + GetPlayerId(pl)
 
Status
Not open for further replies.
Top