AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Metamod:Source Questions (https://forums.alliedmods.net/forumdisplay.php?f=74)
-   -   Access SourceMod core? (https://forums.alliedmods.net/showthread.php?t=187245)

ajr1234 06-10-2012 16:23

Access SourceMod core?
 
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 :mrgreen:

asherkin 06-10-2012 18:26

Re: Access SourceMod core?
 
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.

ajr1234 06-10-2012 21:52

Re: Access SourceMod core?
 
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.

psychonic 06-11-2012 07:17

Re: Access SourceMod core?
 
Quote:

Originally Posted by ajr1234 (Post 1726482)
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).

ajr1234 06-11-2012 14:50

Re: Access SourceMod core?
 
There is a OnPlayerRunCmd forward in pawn, so I basically need the same hook. Anyhow, I'll look through the documentation. Thanks again.

psychonic 06-11-2012 15:10

Re: Access SourceMod core?
 
Quote:

Originally Posted by ajr1234 (Post 1726882)
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.

ajr1234 06-11-2012 16:48

Re: Access SourceMod core?
 
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?

psychonic 06-11-2012 18:48

Re: Access SourceMod core?
 
Quote:

Originally Posted by ajr1234 (Post 1726938)
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 06-11-2012 19:00

Re: Access SourceMod core?
 
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.

ajr1234 06-11-2012 20:02

Re: Access SourceMod core?
 
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.


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

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