Login
Register
Menu
Home
Forum
JassDoc
Types
Functions
Variables
Help
Chat
Media
Search
Search posts
WC3 JASS.com
"The Jass Vault" plus vJASS and Zinc
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
[Snippet] RegisterAnyUnitEvent
Warcraft III:
Maps
Models
Skins
Icons
Spells / Systems
Tools
Tutorials
Snippets
JASS vJASS Spells and Systems
Tutorials
Chat @Discord
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation
-
Zinc documentation
-
WC3 Optimizer documentation
[Snippet] RegisterAnyUnitEvent
Codes & Snippets
Started by
moyack
Views
12018
Replies
3
Users
2
3
1
Pages:
1
Go Down
0 Members and 1 Guest are viewing this topic.
moyack
Site Owner
Administrator
Posts:
970
WC3 Models: 20
WC3 Tutorials: 17
WC3 Tools: 19
WC3 Maps: 12
WC3 Skins: 0
WC3 Icons: 1
WC3 Spells: 16
Reputation:
1153
Site Admin - I love fix things
[Snippet] RegisterAnyUnitEvent
on:
February 02, 2012, 11:18:36 AM
Category:
Execution
Language:
vJASS
Description.
A library to reduce the time writing the same shit. I took some code ideas from a similar
resource
approved here. This one supports all the possibilities in calling the trigger. If user defines the condition and action functions this function will return the respective trigger, so it can be controlled by other instance (just in case).
If the user only sets a condition or action, then it will return
null
because this trigger handles a lot of conditions and actions and it shouldn't be accessible by the user.
Usage:
For functions without triggersleepaction or waits, it's recommended to use
Code: jass
call
RegisterAnyUnitEvent(<Event>,
code
Function,
null
)
For functions with triggersleepaction or waits, it's recommended to use
Code: jass
call
RegisterAnyUnitEvent(<Event>,
null
,
code
Function)
For triggers which condition and action codes must be separated (it could happen) you set this:
Code: jass
private
function
Conditions
takes
nothing
returns
boolean
return
GetSpellAbilityId
() ==
'A000'
endfunction
private
function
Actions
takes
nothing
returns
nothing
// your stuff...
endfunction
private
function
init
takes
nothing
returns
nothing
local
trigger
t = RegisterAnyUnitEvent(
EVENT_PLAYER_UNIT_SPELL_CAST
,
function
Conditions,
function
Actions)
endfunction
Actual code
Code: jass
/*
//************************************************************************/
/
// RegisterAnyUnitEvent by moyack //
//************************************************************************//
// Code improved with the idea developed by Magtheridon96 , Bribe, azlier //
//************************************************************************//
A
library
to
reduce the time writing the same shit. I took some
code
ideas from a similar
resource approved here. This one supports all the possibilities
in
calling the
trigger
.
If user defines the condition
and
action functions
this
function
will
return
the respective
trigger
, so it can be controlled by other instance (just
in
case).
If the user only sets a condition
or
action,
then
it will
return
null
because
this
trigger
handles a lot of conditions
and
actions
and
it shouldn't be accessible by the user.
* For functions without triggersleepaction
or
waits, it's recommended
to
use:
call
RegisterAnyUnitEvent(<Event>,
code
Function,
null
)
* For functions with triggersleepaction
or
waits, it's recommended
to
use:
call
RegisterAnyUnitEvent(<Event>,
null
,
code
Function)
*/
globals
private
trigger
array
ts
endglobals
function
RegisterAnyUnitEvent
takes
playerunitevent
e,
code
cond,
code
act
returns
nothing
local
integer
i =
GetHandleId
(e)
local
trigger
t
if
act !=
null
then
set
t =
CreateTrigger
()
call
TriggerRegisterAnyUnitEventBJ
(t, e)
if
cond !=
null
then
call
TriggerAddCondition
(t,
Filter
(cond))
endif
call
TriggerAddAction
(t, act)
set
t =
null
else
if
ts[i] ==
null
then
set
ts[i] =
CreateTrigger
()
call
TriggerRegisterAnyUnitEventBJ
(ts[i], e)
endif
call
TriggerAddCondition
(ts[i],
Filter
(cond))
endif
endfunction
endlibrary
Examples:
Examples
Condition only
Code: jass
scope
test
initializer
init
private
function
Conditions
takes
nothing
returns
boolean
// your code... please DO NOT use waits or triggersleeaction...
return
false
// please always set it to false
endfunction
private
function
init
takes
nothing
returns
nothing
// that's the recommended way, it's faster and nice :)
call
RegisterAnyUnitEvent(
EVENT_PLAYER_UNIT_SPELL_CAST
,
function
Conditions,
null
)
endfunction
endscope
Action Code Only
Code: jass
scope
test
initializer
init
private
function
Actions
takes
nothing
returns
nothing
// your stuff...
endfunction
private
function
init
takes
nothing
returns
nothing
// It's valid but not as faster as using conditions. Use it when you have in the code
// Polledwait(), triggersleepaction() or wait()
call
RegisterAnyUnitEvent(
EVENT_PLAYER_UNIT_SPELL_CAST
,
null
,
function
Actions)
endfunction
endscope
Condition and action separated
Code: jass
scope
test
initializer
init
private
function
Conditions
takes
nothing
returns
boolean
return
GetSpellAbilityId
() ==
'A000'
endfunction
private
function
Actions
takes
nothing
returns
nothing
// your stuff...
endfunction
private
function
init
takes
nothing
returns
nothing
call
RegisterAnyUnitEvent(
EVENT_PLAYER_UNIT_SPELL_CAST
,
function
Conditions,
function
Actions)
endfunction
endscope
Optionally I can add textmacros for other kind of events, but I left it in this way because this is the most used by me.
«
Last Edit: December 19, 2017, 07:59:19 PM by moyack
»
WC3 Modding Information Center
Magtheridon96
Awesome Global Code Moderator
Recognized User
Posts:
84
WC3 Models: 0
WC3 Tutorials: 0
WC3 Tools: 0
WC3 Maps: 0
WC3 Skins: 0
WC3 Icons: 0
WC3 Spells: 0
Reputation:
516
vJass Incarnate
Re: [Snippet] RegisterAnyUnitEvent
Reply #1 on:
February 09, 2012, 12:48:09 PM
http://www.hiveworkshop.com/forums/2098379-post2.html
I'm too lazy to type that out again =P
moyack
Site Owner
Administrator
Posts:
970
WC3 Models: 20
WC3 Tutorials: 17
WC3 Tools: 19
WC3 Maps: 12
WC3 Skins: 0
WC3 Icons: 1
WC3 Spells: 16
Reputation:
1153
Site Admin - I love fix things
Re: [Snippet] RegisterAnyUnitEvent
Reply #2 on:
February 12, 2012, 09:20:29 PM
Code updated based on the feedback done here:
http://www.hiveworkshop.com/forums/submissions-414/snippet-registeranyunitevent-211598/
WC3 Modding Information Center
moyack
Site Owner
Administrator
Posts:
970
WC3 Models: 20
WC3 Tutorials: 17
WC3 Tools: 19
WC3 Maps: 12
WC3 Skins: 0
WC3 Icons: 1
WC3 Spells: 16
Reputation:
1153
Site Admin - I love fix things
[Snippet] RegisterAnyUnitEvent
Reply #3 on:
July 25, 2013, 07:50:49 AM
A small make up to the first post has been made
WC3 Modding Information Center
Print
Pages:
1
Go Up
« previous
next »
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
[Snippet] RegisterAnyUnitEvent
PortaMx-SEF 1.54
|
PortaMx © 2008-2015
,
PortaMx corp.
Search
Username
Password
Always stay logged in
Forgot your password?