Raised This Month: $12 Target: $400
 3% 

Creating a Game Event Listener


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-28-2008 , 06:35   Creating a Game Event Listener
Reply With Quote #1

I couldn't find much on using this. Most of the code snippets I found were simply to fire an event. I just need to find a way to prehook the player_hurt event so I can stop damage taken.

I have included <igameevents.h>

IGameEventManager2 *m_GameEventManager = NULL;
GET_V_IFACE_CURRENT(GetEngineFactory, m_GameEventManager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);

And I attempted to add a listener in my SDK_OnMetamodLoad function, but it's not seeming to recognize my pointer. (Not getting the drop down box and getting errors)

m_GameEventManager->AddListener(this, "player_hurt", true);

I've finally figured out sourcehook, but not to sure on how to go about turning player_hurt into a forward, or even why this isn't currently working. Could use some help.
CrimsonGT is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 05-28-2008 , 14:27   Re: Creating a Game Event Listener
Reply With Quote #2

I don't think the player_hurt event will help you. I think you need to hook the OnTakeDamage_Alive instead to control the damage amount.


But to answer your other question ... I do this in the LevelInit:
Code:
m_GameEventManager->AddListener( this, "player_hurt", true );
Does your plugin class inherit the IGameEventListener2 class?
Keeper is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 05-28-2008 , 14:54   Re: Creating a Game Event Listener
Reply With Quote #3

Keeper@: OnTakeDamage_Alive is not his best chance because of the issues with CTakeDamageInfo in ob based games...
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 05-28-2008 , 15:04   Re: Creating a Game Event Listener
Reply With Quote #4

Rut roh, that doesn't sound good. I haven't ported over yet and I do use that. What kind of issues?

/me runs to search

EDIT: Is this the issue? http://forums.alliedmods.net/showthread.php?t=62785

Last edited by Keeper; 05-28-2008 at 15:07.
Keeper is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-28-2008 , 15:08   Re: Creating a Game Event Listener
Reply With Quote #5

Well right now my sourcemod plugin is using player_hurt and ongameframe. It stores their health in an array every gameframe, and then when they take damage, if its self inflicted or fall damage, I return it to them. I would just like to pre-hook player_hurt instead so I can get rid of ongameframe.
CrimsonGT is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 05-28-2008 , 15:11   Re: Creating a Game Event Listener
Reply With Quote #6

Quote:
Originally Posted by CrimsonGT View Post
Well right now my sourcemod plugin is using player_hurt and ongameframe. It stores their health in an array every gameframe, and then when they take damage, if its self inflicted or fall damage, I return it to them. I would just like to pre-hook player_hurt instead so I can get rid of ongameframe.
You don't need to hook anything to use an event in that way. Just add your plugin as a listener the way keeper showed you. If you get errors, read them and see what they say. You're most likely missing the FireEvent (or is it FireGameEvent, the error will tell you either way). You need to make sure you're plugin is inheriting from IGameEventListener2 and then add add that function. Then check the event name and if it matches player_hurt, do your thing.
__________________
"Good grammar is essential, Robin."
- Batman
L. Duke is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 06-01-2008 , 10:10   Re: Creating a Game Event Listener
Reply With Quote #7

Alright, I still cannot get it to work, and I am not sure what I am doing wrong. Here is a link to my header and source file, maybe you guys can take a look and let me know what im doing wrong?

http://*.ampaste.net/232640
http://*.ampaste.net/232644
CrimsonGT is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 06-01-2008 , 17:04   Re: Creating a Game Event Listener
Reply With Quote #8

You might want to recheck those links
Keeper is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 17:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode