Raised This Month: $ Target: $400
 0% 

IEntityListener help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 12-04-2012 , 10:48   IEntityListener help
Reply With Quote #1

Hey guys,

I decided to create a VSP for the first time with MetaMod support and copied the sig scanner in the wiki. Then I found the g_EntityList or whatever (using LevelShutdown and the offset) and then the offset for the entity listener. The funny thing is, it compiles and works fine in MetaMod but crashes with the VSP. I'll post the code when I get back home, but anyone have any clues as to why this may be happening?


Thanks
ajr1234 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-04-2012 , 11:00   Re: IEntityListener help
Reply With Quote #2

Quote:
Originally Posted by ajr1234 View Post
Hey guys,

I decided to create a VSP for the first time with MetaMod support and copied the sig scanner in the wiki. Then I found the g_EntityList or whatever (using LevelShutdown and the offset) and then the offset for the entity listener. The funny thing is, it compiles and works fine in MetaMod but crashes with the VSP. I'll post the code when I get back home, but anyone have any clues as to why this may be happening?


Thanks
I thought the signature-based function calling code was part of MM:S...
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 12-04-2012 , 15:23   Re: IEntityListener help
Reply With Quote #3

This? I think it can be used elsewhere too...

Last edited by ajr1234; 12-04-2012 at 15:23.
ajr1234 is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 12-04-2012 , 17:30   Re: IEntityListener help
Reply With Quote #4

Got it to stop crashing, but nothing seems to be happening. (Sorry for the double post as well! The edit button doesn't work on my phone)

EDIT (back home now): No more crashing, properly adds the listener, but my OnEntityCreated() in my class never gets called... Here is the code:

EDIT 2: Solved it. I was retarded and added the listener when the plugin loaded instead of on levelinit.

Code:
// the code for adding the listener
if (LevelShutdownSig.is_set)
{
	void* entList = FromLevelShutdown(spt_vfuncs.GetOffset(0, "gEntList"));
	int offset = virtualfuncs->FindOffset("EntityListener");
	CUtlVector<IEntityListener*> *pListeners = (CUtlVector<IEntityListener*> *)((intptr_t)entList + offset);
	pListeners->AddToTail(this);

	// Entity listener is properly added... I checked the pListeners->Count() and it went up by 1 after adding to tail
}


// the relevant class
class serverplugin: public IServerPluginCallbacks, public IGameEventListener2, public IEntityListener
{
public:
	virtual void OnEntityCreated(CBaseEntity *pEntity);
};

// the function
void serverplugin::OnEntityCreated(CBaseEntity *pEntity)
{
	// This message never shows up :(
	Msg("Some ent created.\n");
}

Last edited by ajr1234; 12-04-2012 at 18:47.
ajr1234 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 10:37.


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