Help with CreateListener

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Help with CreateListener

Post 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?
[VS-UK]Capt.Parts[BnHQ]
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

There's two ways to create a listener:

local.mylistener = local CreateListener

or

local.mylistener = spawn listener
Image
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post by mohaa_rox »

What's a listener?
Live to map, not map to live.
-mohaa_rox, .map
moderator
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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.
Image
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post 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
[VS-UK]Capt.Parts[BnHQ]
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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.
Image
Post Reply