[Log in / Register]
| News | Chat | Pastebin | Donations | Tutorials | Rules | Forums |
| Maps | Skins | Icons | Models | Spells | Tools | Jass | Packs | Hosted Projects | Starcraft II Modding | Starcraft II Resources | Galaxy Wiki |
(Keeps Hive Alive)
Go Back   The Hive Workshop > Warcraft III Modding > JASS Resources


JASS Resources Find JASS code snippets and functions here or write your own and post it on the Submissions sub-forum.

Reply
 
Thread Tools
Old 09-07-2011, 06:05 PM   #1 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
[Snippet] RegisterPlayerUnitEvent

This system was made to replace that cumbersome GTrigger by Jesus4Lyf.
Special thanks to Bribe, azlier and BBQ :)

Jass:
/**************************************************************
*
*   RegisterPlayerUnitEvent
*   v5.1.0.1
*   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 = 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

Here's a vanilla Jass version:

Jass:
//**************************************************************
//*
//*   RegisterPlayerUnitEvent (Vanilla Jass)
//*   v5.1.0.1
//*   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)
//*
//*   Implementation:
//*   ---------------
//*
//*       - Copy all this script into a new trigger called "RegisterPlayerUnitEvent Jass"
//*       - Create a trigger array variable called RPUE.
//*       - Done.
//*
//*   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.
//*
//**************************************************************
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
    local integer i = GetHandleId(p)
    local integer k = 15
    if udg_RPUE[i] == null then
        set udg_RPUE[i] = CreateTrigger()
        loop
            call TriggerRegisterPlayerUnitEvent(udg_RPUE[i], Player(k), p, null)
            exitwhen k == 0
            set k = k - 1
        endloop
    endif
    call TriggerAddCondition(udg_RPUE[i], Filter(c))
endfunction

function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
    local integer i = 16 * GetHandleId(p) + GetPlayerId(pl)
    if udg_RPUE[i] == null then
        set udg_RPUE[i] = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(udg_RPUE[i], pl, p, null)
    endif
    call TriggerAddCondition(udg_RPUE[i], Filter(c))
endfunction

function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
    return udg_RPUE[GetHandleId(p)]
endfunction
   
function InitTrig_RegisterPlayerUnitEvent_Jass takes nothing returns nothing
endfunction

Feel free to comment..

Last edited by Magtheridon96; 10-08-2012 at 05:35 PM.
Magtheridon96 is offline   Reply With Quote
Old 09-07-2011, 06:49 PM   #2 (permalink)
Registered User Troll-Brain
cool != useful
 
Troll-Brain's Avatar
 
Join Date: Apr 2008
Posts: 1,937
Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)
I haven't read your code, just your functions descriptions.
Could you add an "EVERY" constant ? (a "random" negative value seems fine)

I mean for orders sometimes we don't need to catch a specific order, just any order.
Sure we could still create a trigger and add it this event, like the old good way.

It would also be useful for the other events, but orders are the most obvious one.
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.

You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
Troll-Brain is offline   Reply With Quote
Old 09-07-2011, 07:13 PM   #3 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
From what you told me, I understood that you want me to add an "Any Order" event.
If that's true, sure i'll add it bro :)
__________________
Magtheridon96 is offline   Reply With Quote
Old 09-07-2011, 07:28 PM   #4 (permalink)
Registered User Troll-Brain
cool != useful
 
Troll-Brain's Avatar
 
Join Date: Apr 2008
Posts: 1,937
Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)
Well i'm sure it is useful for order events, but it could also be for other events, that's why i'm suggesting a constant integer.

Jass:
constant integer CommonEvent_ANY = -42

Jass:
...

call registerBeginCast(CommonEvent_ANY,<boolexpr>) // any ability
call registerItemUse(CommonEvent_ANY,<boolexpr>) // any item

Ofc the constant name could (must ?) be improved.
Alternatively you could also create several constants, one for each event "type" (order, item, ...) but i personnaly don't like this idea.
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.

You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
Troll-Brain is offline   Reply With Quote
Old 09-07-2011, 07:56 PM   #5 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
Ok.. I'll just remove those events in the struct and use this instead :P
__________________
Magtheridon96 is offline   Reply With Quote
Old 09-07-2011, 08:04 PM   #6 (permalink)
Registered User Nestharus
User
 
Nestharus's Avatar
 
Join Date: Jul 2007
Posts: 4,914
Nestharus has disabled reputation
Also, player specific and unit specific events would be nice.
__________________

Anime-Planet.com - anime | manga | reviews
Nestharus is online now   Reply With Quote
Old 09-07-2011, 08:24 PM   #7 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
;_;
If you list them, it would be much easier for me >:P

Come to think of it Troll-Brain, it would be more efficient if I keep the system the way it is and just add an "AnyOrder" event.
That way, The entire API would inline :D
__________________
Magtheridon96 is offline   Reply With Quote
Old 09-07-2011, 08:34 PM   #8 (permalink)
Registered User Troll-Brain
cool != useful
 
Troll-Brain's Avatar
 
Join Date: Apr 2008
Posts: 1,937
Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)
Quote:
Originally Posted by Magtheridon96 View Post
;_;
If you list them, it would be much easier for me >:P
But it would be less funny for us :/

Quote:
Come to think of it Troll-Brain, it would be more efficient if I keep the system the way it is and just add an "AnyOrder" event.
That way, The entire API would inline :D
Like i said order events are only one example ...
And seriously who care about register event inlines, it's just better to work on the API usage. (plz refrain your speed-freak)
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.

You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
Troll-Brain is offline   Reply With Quote
Old 09-07-2011, 08:45 PM   #9 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
I don't know :S
I'll add it and see how the public likes it :P
__________________
Magtheridon96 is offline   Reply With Quote
Old 09-07-2011, 08:46 PM   #10 (permalink)
Registered User Troll-Brain
cool != useful
 
Troll-Brain's Avatar
 
Join Date: Apr 2008
Posts: 1,937
Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)
Quote:
Originally Posted by Magtheridon96 View Post
I don't know :S
I'll add it and see how the public likes it :P
Since when there is a public for the jass section ?
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.

You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
Troll-Brain is offline   Reply With Quote
Old 09-07-2011, 08:47 PM   #11 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
Quote:
Since when there is a public for the jass section ?
Since the day I decided to link my resources in my sig >:D
__________________
Magtheridon96 is offline   Reply With Quote
Old 09-07-2011, 08:56 PM   #12 (permalink)
Registered User Troll-Brain
cool != useful
 
Troll-Brain's Avatar
 
Join Date: Apr 2008
Posts: 1,937
Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)
Mouahahaha the jass section is more likely a semi-private flood forum.

(Ok, end of the silly flood for me, i couldn't resist, sorry :p )
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.

You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
Troll-Brain is offline   Reply With Quote
Old 09-07-2011, 10:11 PM   #13 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,700
Magtheridon96 has a brilliant future (1812)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
Nestharus, Player-specific events would be way too messy =/
I'll see what I can do, but if I go beyond 600 lines, NO DEAL XD
__________________
Magtheridon96 is offline   Reply With Quote
Old 09-08-2011, 07:46 AM   #14 (permalink)
Forum Moderator Bribe
Keep it simple
 
Bribe's Avatar
Spells, Help Zones & JASS Moderator
 
Join Date: Sep 2009
Posts: 5,581
Bribe has much of which to be proud (1209)Bribe has much of which to be proud (1209)
PayPal Donor: This user has donated to The Hive. 
This line is awkward:

call UD.remove(i) // To avoid bugs after the handle id is recycled.

The unit could die multiple times :/

I think for death events you should let users just use Nestharus' Unit
Event.

This event-player-leave stuff is also strange to include in this library.
>> call TriggerRegisterPlayerEvent(c,p,EVENT_PLAYER_LEAVE)

I will show you how to make this a lot shorter code (works for all
playerunitevents):

Jass:
function RegisterPlayerUnitEvent takes boolexpr condition, playerunitevent pu returns nothing
    globals
        private trigger array trigs
    endglobals
    local integer id = GetHandleId(pu)
    if trigs[id] == null then
        set trigs[id] = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trigs[id], pu)
    endif
    call TriggerAddCondition(trigs[id], condition)
endfunction
__________________
How to post your triggers on the Hive Workshop.
JPAG - Bettering the cause of readable source code.


Last edited by Bribe; 09-08-2011 at 08:07 AM.
Bribe is offline   Reply With Quote
Old 09-08-2011, 08:39 PM   #15 (permalink)
Registered User baassee
MORE CONTESTS PLS
 
baassee's Avatar
 
Join Date: Nov 2008
Posts: 3,554
baassee is a splendid one to behold (845)baassee is a splendid one to behold (845)baassee is a splendid one to behold (845)baassee is a splendid one to behold (845)baassee is a splendid one to behold (845)
I am the public of the JASS section.

Oo loooots of tables, I'm happy that it's not Vex's table. Anyway I'm very thankful for this as I hate the stupid GT (have modified it myself just because of that matter). Only thing that drives me mad but will probably not affect anyone else is the exitwhen i>15 but I can make that constant myself and filter out nonplaying players aswell (so what I mean is that you should keep it). Brilliant.

And the effect event should be in, just static if it out if the player already used Bribe's. (Or maybe merge with Bribe's? Sorry Bribe :D)
__________________
Nobody dies a virgin, life fucks us all. - Master Arena is alive! v4.0 in construction. - Dr Super Good for president! - Sorry derps but I do not do requests unless they prove themselves worthy of my time.
My Resources! - Help me out with my project! - How To Import vJASS spells tutorial! - Practice makes perf... improves you.
Quote:
Originally Posted by Marc Mamales View Post
Hey guys, please fix my spells, cz i dont know how to make it GUI.
baassee is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 05:01 AM.





Powered by vBulletin
Copyright 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1 PL2
Copyright © Ralle