- Joined
- Nov 20, 2011
- Messages
- 202
We need Wurst tags!!!
This looks like **** with jass highlighting!
Here is a peeeq version for better readablity:
http://peeeq.de/code.php?id=6537
Some example spell where the system is used:
peeeq version: http://peeeq.de/code.php?id=6538
This looks like **** with jass highlighting!
Here is a peeeq version for better readablity:
http://peeeq.de/code.php?id=6537
JASS:
package CustomEvent /*
*************************************************************
* Description:
* This is a package which allows u to create custom events
* and easily register and unregister actions to them.
*************************************************************
* Requirements: None
*************************************************************
* How it works:
* Uses a list of triggers to realizie dynamic function calls.
* As event response data event bound attributs are used so
* nothing can get overwritten and it is also very fast due to
* the fact that just two globals need to be set after each
* action.
*************************************************************
* How to use:
* Basics:
* -Create an instance of the class Event to create a new event.
* -You can add actions to this event:
* yourevent.add(function myActionFunction)
* -To run all actions on an event just use:
* yourevent.fire()
* -To remove an action just destroy the action object that
* the add function returns.
* -To remove an event just destroy it, all refering actions
* get deletet aswell.
*
* Attach data to an action:
* Save the action which is returned by the add function:
* Action a = myEvent.add(function myActionFunction)
* Now u can set the data of the action:
* a.setData(myObject to int)
*
* Get attached data from an action in the action function:
* First of all get and save the current action:
* Action a = getAction()
* Now call get the data from the action:
* MyClass obj = a.getData() castTo MyClass
*
* Set event response data:
* To set the event response data just set the Event attributes:
* //This are just some examples
* myEvent.u1 = triggerUnit
* myEvent.v1 = target.getPos()
*
* Read event response data in the action function:
* Get and safe the Event:
* Event e = getEvent()
* Read out the object attributes:
* //This is just an example what u could do
* e.u1.setPos(e.v1)
* You can also write new information back into the response data:
* e.s1 = "Teleport successful"
*
* If u need other datatypes as response data u can
* just add them.
*
* If you got still don't understand how it works take a look
* at the example down there.
*************************************************************
* Bugs / Warnings / Hints:
* -No bugs know
* -Keep the instance limit in mind
* -Remember u need to destroy the action by urself
* or destroy the event
* -You should use a convention for the event data, so
* u won't get confused by the meanless names. You also can
* change the names.
*************************************************************
* Credits goes to all members of the inwc IRC who helped me a lot
*************************************************************/
import HashMap
import TList
import Setup
//Global event response data
HashMap<int, Event> eventStore = new HashMap<int, Event>()
Action currentAction = null
Event currentEvent = null
/**Gets the current running action, use this to destroy the action or to get the stored data in the action*/
public function getAction() returns Action
return currentAction
/**Gets the current firing event, use this to read out the event response data*/
public function getEvent() returns Event
return currentEvent
public class Event
//Event response data
unit u1 = null
unit u2 = null
vec2 v1 = vec2(0, 0)
vec2 v2 = vec2(0, 0)
int i1 = 0
int i2 = 0
real r1 = 0
real r2 = 0
player p1 = null
player p2 = null
boolean b1 = false
boolean b2 = false
string s1 = null
string s2 = null
Action first = null
Action last = null
boolean destructIfEmtpy = false
/**Adds an new action to this Event, returns and Action object on which u can save data.
Destroy the returned object to remove the action*/
function add(code actionFunc) returns Action
trigger t = CreateTrigger().addCondition(Condition(actionFunc))
if first == null
first = new Action(t, null, null, this)
last = first
else
Action buffer = last
last = new Action(t, null, buffer, this)
buffer.next = last
return last
/**Calls all to the event refering actions, don't forget to set the response data before*/
function fire()
Action e = first
while (e != null)
Action buffer = e
e = e.next
currentAction = buffer
currentEvent = this
buffer.content.evaluate()
ondestroy
Action e = first
while (e != null)
Action buffer = e
e = e.next
destroy buffer
public class Action
Action next
Action prev
Event referingEvent
trigger content
int objData = 0
construct(trigger content, Action next, Action prev, Event referingEvent)
this.content = content
this.next = next
this.prev = prev
this.referingEvent = referingEvent
/**Attaches data to the action.
You can save each kind of objects by cast them to ints: (myObject castTo int)*/
function setData(int objData)
this.objData = objData
/**Retrieves data back from the action, don't forget to cast it back*/
function getData() returns int
return objData
ondestroy
DestroyTrigger(content)
if prev != null
prev.next = next
if next != null
next.prev = prev
if referingEvent.first == this
referingEvent.first = next
if referingEvent.last == this
referingEvent.last = prev
if referingEvent.destructIfEmtpy and referingEvent.first == null and referingEvent.last == null
destroy referingEvent
//Example/Snipped: Cast Event
init
//Trigger Init
trigger t = CreateTrigger()
t.addAction(function fireCastEvent)
t.registerAnyUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST)
t = null
/**The action function will be just called if the desired ability is casted*/
public function registerSpellCastAction(int abiCode, code actionFunc) returns Action
Event e = eventStore.get(abiCode)
if e == null
e = new Event()
eventStore.put(abiCode, e)
return e.add(actionFunc)
function fireCastEvent()
Event e = eventStore.get(GetSpellAbilityId())
if e != null
e.u1 = GetTriggerUnit()
e.u2 = GetSpellTargetUnit()
e.v1 = vec2(GetSpellTargetX(), GetSpellTargetY())
eventStore.get(GetSpellAbilityId()).fire()
endpackage
Some example spell where the system is used:
peeeq version: http://peeeq.de/code.php?id=6538
JASS:
package CriticalSlow /*
************************************************************
* An very easy spell which slows the enemy down if u hit it
* with a critical hit. This should just demonstrate the use
* of custom events.
************************************************************/
import CustomEvent
init
//No need to save the Action because we never want to destroy it
registerSpellCastAction('A001', function onCast)
//This is the action function
function onCast()
//Here we get the event
Event e = getEvent()
//Create an instance of our spell
new CritSlow(e.u1)
public class CritSlow
timer t
Action a
unit u
construct(unit u)
this.u = u
//Imaginie an event which fires when this unit cause a critical hit
//(A damage system which supports this will be realeased soon)
a = u.registerCauseCritHit(function onCrit)
//Set Action data
a.setData(this castTo int)
//SpellStuff
t = getTimer()
t.setData(this castTo int)
t.start(30., function destr)
static function destr()
destroy GetExpiredTimer().getData() castTo CritSlow
static function onCrit()
//Reading out Event and Action data, and call the target function
(getAction().getData()) castTo thistype.onCrit(getEvent().u2)
function onCrit(unit target)
//System which supports this will be also realeased soon
target.bonusMovespeedTimed(-50, 2)
ondestroy
t.release()
destroy a
endpackage
Last edited: