AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Need some basic help with extensions (https://forums.alliedmods.net/showthread.php?t=319173)

_mvs 10-17-2019 10:19

Need some basic help with extensions
 
Hello! I'm very new to sourcemod and just passed through these tutorials:

https://wiki.alliedmods.net/Introduc...rceMod_Plugins
https://wiki.alliedmods.net/Writing_Extensions

However, I still have some questions which I did not find answers to.

Code from the tutorial (extension.cpp):

PHP Code:

#include "extension.h"

/**
 * @file extension.cpp
 * @brief Implement extension code here.
 */

FirstExtension g_FirstExtension;        /**< Global singleton for extension's main interface */

SMEXT_LINK(&g_FirstExtension);

IForward *g_pSayChat NULL;

cell_t SquareNumber(IPluginContext *pContext, const cell_t *params)
{
    
cell_t number params[1];
    return 
number number;
}

const 
sp_nativeinfo_t MyNatives[] =
{
    { 
"SquareNumber",    SquareNumber },
    { 
NULL,            NULL },
};

void FirstExtension::SDK_OnAllLoaded()
{
    
sharesys->AddNatives(myselfMyNatives);
    
g_pSayChat forwards->CreateForward("OnPlayerSayChat"ET_Event2NULLParam_CellParam_String);
}

void FirstExtension::SDK_OnUnload()
{
    
forwards->ReleaseForward(g_pSayChat);
}

/** Fires the say chat event in plugins.  Returns true to allow the text, false to block. */
bool FireChatEvent(int client, const char *text)
{
    if (!
g_pSayChat)
    {
        return 
true;
    }

    
cell_t result 0;
    
g_pSayChat->PushCell(client);
    
g_pSayChat->PushString(text);
    
g_pSayChat->Execute(&result);

    if (
result == Pl_Handled)
    {
        return 
false;
    }

    return 
true;


I don't understand, when exactly FireChatEvent gets called?

I tried to include this simple extension in tutorial plugin's code:
first_ext.inc:
PHP Code:

#if defined _firstext_included
#endinput
#endif
#define _firstext_included

/**
 * Returns the square of a number.
 *
 * @param num    Number to square.
 * @return    The square of num.
 */
native int SquareNumber(num);


/**
* @brief Called whenever a client says something in chat.
*
* @param client    Index of the client.
* @param text        String containing the say text.
* @return         Plugin_Handled to block text from printing, Plugin_Continue otherwise.
*/
forward Action OnPlayerSayChat(int client, const char[] text);

/**
 * Do not edit below this line!
 */
public Extension:__ext_firstext 
{
    
name "First extension",
    
file "first.ext.2.csgo",
#if defined AUTOLOAD_EXTENSIONS
    
autoload 1,
#else
    
autoload 0,
#endif
#if defined REQUIRE_EXTENSIONS
    
required 1,
#else
    
required 0,
#endif
}; 

helloworld.sp:

PHP Code:

#include <sourcemod>
#include <sdktools>
#include <first_ext>

public Plugin myinfo =
{
    
name "My First Plugin",
    
author "Me",
    
description "My first plugin ever",
    
version "1.0",
    
url "http://www.sourcemod.net/"
};

ConVar g_cvarMySlapDamage null;

public 
void OnPluginStart()
{
    
PrintToServer("Hello world!");
    
RegAdminCmd("sm_myslap"Command_MySlapADMFLAG_SLAY);
    
    
g_cvarMySlapDamage CreateConVar("sm_myslap_damage""1""Default slap damage");
    
AutoExecConfig(true"plugin_myslap");
    
    
LoadTranslations("common.phrases.txt"); // Required for FindTarget fail reply
}
 
public 
Action OnPlayerSayChat(int client, const char[] text)
{
    
PrintToChat(client"[SM] %d"SquareNumber(5)); 
    return 
Plugin_Continue;


REQUIRE_EXTENSIONS is defined in core.inc and my plugin loads successfully so I assume that the extension is also loaded. However, when I say something in chat I don't get "[SM] 25" printed as I expected.

So, either `OnPlayerSayChat` is never fired (in that case, what sould I do to actually get it working?) or it is fired and I just made some mistakes so I don't get expected result. If latter, what are these mistakes and how to fix them?

Thanks!

Silvers 10-17-2019 10:27

Re: Need some basic help with extensions
 
Wrong forum section. Should be here: https://forums.alliedmods.net/forumdisplay.php?f=134

_mvs 10-17-2019 10:37

Re: Need some basic help with extensions
 
Yeah I saw that section but its description says "Post your own custom extensions here" and I'm not actually going to post an extension and rather search for help :)

OciXCrom 10-17-2019 13:42

Re: Need some basic help with extensions
 
So posting in the AMX Mod X section is better?

_mvs 10-17-2019 15:30

Re: Need some basic help with extensions
 
Oops. My bad, thought it was SourceMod general discussion. Is there a way to move the topic?

Bugsy 10-17-2019 21:16

Re: Need some basic help with extensions
 
Moved to SM Extensions forum

_mvs 10-18-2019 12:22

Re: Need some basic help with extensions
 
Well if this is appropriate to post a basic questions in this section. Thanks!

DJ Tsunami 10-18-2019 14:50

Re: Need some basic help with extensions
 
Quote:

For simplicity, let's assume you already have a function that tells you when a player says say chat.
So you would call FireChatEvent inside that function.

_mvs 10-19-2019 12:32

Re: Need some basic help with extensions
 
I guess I missed that part somehow :oops: thanks

How do you then write a function that tells when a players says something in a chat?

asherkin 10-20-2019 04:47

Re: Need some basic help with extensions
 
Quote:

Originally Posted by _mvs (Post 2670234)
I guess I missed that part somehow :oops: thanks

How do you then write a function that tells when a players says something in a chat?

You wouldn’t - Extensions are designed to extended the SourceMod API with additional functionality, they have access to a very limited set of game API helpers. If you wanted to do it you would need to replicate SM’s OnClientSayCommand implementation.


All times are GMT -4. The time now is 14:11.

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