Raised This Month: $7 Target: $400
 1% 

Access SourceMod core?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-10-2012 , 16:23   Access SourceMod core?
Reply With Quote #1

I'm really new to SourceMod extensions, but I'm well versed with c++. How would I access the g_Players global from an extension? For example:

PHP Code:
static cell_t SomeExtensionFunction(IPluginContext *pContext, const cell_t *params)
{
    
int client params[1];

// g_Players is inside another class-- can't do it
// Is CPlayer in the HL2SDK-l4d2?
    
CPlayer *pPlayer g_Players.GetPlayerByIndex(client);
    if (!
pPlayer)
    {
        return 
pContext->ThrowNativeError("Client index %d is invalid"client);
    }

    
// etc.

    
return 1;

I guess what I'm really trying to ask is if it's possible to use the nifty functions Sourcemod already provides. Instead of hooking void Hook_ClientPutInServer(edict_t *pEntity, char const *playername) with SH_ADD_HOOK_STATICFUNC/SH_DECL_HOOK2_void etc to reinvent the wheel. Do we use the interface system? I was reading the tutorial but it was very vague.

Also, I know about forwarding to plugins, but is it possible the other way around? Can we use natives created by plugins in extensions?

Thanks

Last edited by ajr1234; 06-10-2012 at 18:10.
ajr1234 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-10-2012 , 18:26   Re: Access SourceMod core?
Reply With Quote #2

Look in smsdk_config.h and uncomment
Code:
#define SMEXT_ENABLE_PLAYERHELPERS
You can then use playerhelpers->GetGamePlayer, which returns an IGamePlayer pointer.
This is the public version of g_Players / CPlayer.

Quote:
Also, I know about forwarding to plugins, but is it possible the other way around? Can we use natives created by plugins in extensions?
No. The point of the extension API is to extend what SourcePawn plugins can do, so that's what the API is designed to expose.
__________________

Last edited by asherkin; 06-10-2012 at 18:28.
asherkin is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-10-2012 , 21:52   Re: Access SourceMod core?
Reply With Quote #3

Thanks. Makes sense now. Short and simple

Is there an easy way to hook client connect, disconnect, map start, player move, etc? I'm making an extension where certain information is added to a stack every time these actions take place. I would do that in a plugin, but I need an external library to do calculations, and the library isn't opensource so I am not able to make a wrapper.

What does this mean anyway?
SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);

I know it's a sourcehook, but how would someone know what kind of macro to use? I looked through the extensions forum but I am not sure how people are finding out how to form their hooks.
ajr1234 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-11-2012 , 07:17   Re: Access SourceMod core?
Reply With Quote #4

Quote:
Originally Posted by ajr1234 View Post
Thanks. Makes sense now. Short and simple

Is there an easy way to hook client connect, disconnect, map start, player move, etc? I'm making an extension where certain information is added to a stack every time these actions take place. I would do that in a plugin, but I need an external library to do calculations, and the library isn't opensource so I am not able to make a wrapper.

What does this mean anyway?
SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);

I know it's a sourcehook, but how would someone know what kind of macro to use? I looked through the extensions forum but I am not sure how people are finding out how to form their hooks.
For client connect and disconnect as well as map start (OnServerActivated), you can use the IClientListener interface in IPlayerHelpers.h. (add yourself with playerhelpers->AddClientListener, and don't forget to remove on unload).

For movement, I'm not sure offhand what the best way to check would be (other than checking position each frame).
psychonic is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-11-2012 , 14:50   Re: Access SourceMod core?
Reply With Quote #5

There is a OnPlayerRunCmd forward in pawn, so I basically need the same hook. Anyhow, I'll look through the documentation. Thanks again.
ajr1234 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-11-2012 , 15:10   Re: Access SourceMod core?
Reply With Quote #6

Quote:
Originally Posted by ajr1234 View Post
There is a OnPlayerRunCmd forward in pawn, so I basically need the same hook. Anyhow, I'll look through the documentation. Thanks again.
Players telling the server where they believed they moved to or holding down move buttons shoudn't be confused with them actually moving.

However,

If you still want that function despite that, you can use SourceHook to hook it much like SDKTools does in extensions/sdktools/hooks.cpp.
psychonic is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-11-2012 , 16:48   Re: Access SourceMod core?
Reply With Quote #7

Wonderful. Just what I needed.

I just realized something. You're the person that took SDK Hooks from 1.0 to 2.1. Thanks a lot for working so hard on that I wanted to let you know that your work doesn't go unappreciated.

By the way, if I want to retrieve the model name (if it exists) of every entity that is loaded during level initialization, I use IEntityFactoryDictionary with Bintools and create a hook, right?
ajr1234 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-11-2012 , 18:48   Re: Access SourceMod core?
Reply With Quote #8

Quote:
Originally Posted by ajr1234 View Post
Wonderful. Just what I needed.

I just realized something. You're the person that took SDK Hooks from 1.0 to 2.1. Thanks a lot for working so hard on that I wanted to let you know that your work doesn't go unappreciated.

By the way, if I want to retrieve the model name (if it exists) of every entity that is loaded during level initialization, I use IEntityFactoryDictionary with Bintools and create a hook, right?
Entities won't typically have a model set until right before or during Spawn. To get the model on every one created, you would need to hook both creation and spawn. For creation, you an use the IEntityFactoryDictionary method used on old SDK Hooks versions or do what the newer builds do and add yourself as an IEntityListener. For spawn, just add a vhook on the entity's Spawn function.
psychonic is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-11-2012 , 19:00   Re: Access SourceMod core?
Reply With Quote #9

On second thought, you could just use a manual VPHook on CBaseEntity::Spawn. I think that most or all overrides will also call the one in the base class, or you could also add them for the specific classes that you need to check the model of.
psychonic is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-11-2012 , 20:02   Re: Access SourceMod core?
Reply With Quote #10

This right?:

SH_ADD_MANUALVPHOOK(manual hook name, representative instance pointer, handler, post or not)

EDIT: nvm, figured it out. I did the first thing you suggested. I just realized I posted in the wrong forum. I'll create a different thread in the coding forum.

Last edited by ajr1234; 06-12-2012 at 15:43.
ajr1234 is offline
Reply


Thread Tools
Display Modes

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 03:25.


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