Page 1 of 1

Help with CreateListener

Posted: Tue May 13, 2003 10:37 am
by Parts
Anyone know how this works?

I'm hoping to pick up events and act according to that event, e.g. damage or killed.

I think to pick up these events you need to create a listener waiting for that event to happen but I'm not sure!

Anyone got any idea?

Posted: Tue May 13, 2003 10:46 am
by jv_map
There's two ways to create a listener:

local.mylistener = local CreateListener

or

local.mylistener = spawn listener

Posted: Tue May 13, 2003 10:47 am
by mohaa_rox
What's a listener?

Posted: Tue May 13, 2003 10:49 am
by jv_map
It's one of the most primitive classes (see Bjarne's class tree in his command documentation page).

Almost all other classes depend on listeners, for example entities.

Basically a listener is anything that can hold a variable.

Posted: Tue May 13, 2003 10:53 am
by Parts
maybe if I put this into context it will help.

I know there are player events for damage and killed. I know you can do waittill dead, however I have no idea of how to pick up the event damage or killed and analyse the parameters.

The killed event is defined as:

killed( Entity attacker, Integer damage, Entity inflictor, Vector position, Vector direction, Vector normal, Integer knockback, Integer damageflags, Integer meansofdeath, Integer location )


below is the code from the killed.scr script in global. This seems to a handler for the killed event, I've no idea if this actually gets called and how.

Code: Select all

start local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.dflags local.meansofdeath local.location:
self.fact = local CreateListener
self.fact.attacker = local.attacker
self.fact.damage = local.damage
self.fact.inflictor = local.inflictor
self.fact.position = local.position
self.fact.direction = local.direction
self.fact.normal = local.normal
self.fact.knockback = local.knockback
self.fact.dflags = local.dflags
self.fact.meansofdeath = local.meansofdeath
self.fact.location = local.location

Posted: Tue May 13, 2003 10:56 am
by jv_map
It's called by internal game code whenever an actor is killed. Then it creates a .fact listener that holds all variables regarding the killed event. This info is used by anim/killed.scr.