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

Need some basic help with extensions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_mvs
Junior Member
Join Date: Oct 2019
Old 10-17-2019 , 10:19   Need some basic help with extensions
Reply With Quote #1

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!
_mvs is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 10-17-2019 , 10:27   Re: Need some basic help with extensions
Reply With Quote #2

Wrong forum section. Should be here: https://forums.alliedmods.net/forumdisplay.php?f=134
__________________
Silvers is offline
_mvs
Junior Member
Join Date: Oct 2019
Old 10-17-2019 , 10:37   Re: Need some basic help with extensions
Reply With Quote #3

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 :)
_mvs is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-17-2019 , 13:42   Re: Need some basic help with extensions
Reply With Quote #4

So posting in the AMX Mod X section is better?
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
_mvs
Junior Member
Join Date: Oct 2019
Old 10-17-2019 , 15:30   Re: Need some basic help with extensions
Reply With Quote #5

Oops. My bad, thought it was SourceMod general discussion. Is there a way to move the topic?
_mvs is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-17-2019 , 21:16   Re: Need some basic help with extensions
Reply With Quote #6

Moved to SM Extensions forum
__________________

Last edited by Bugsy; 10-17-2019 at 21:16.
Bugsy is online now
_mvs
Junior Member
Join Date: Oct 2019
Old 10-18-2019 , 12:22   Re: Need some basic help with extensions
Reply With Quote #7

Well if this is appropriate to post a basic questions in this section. Thanks!
_mvs is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 10-18-2019 , 14:50   Re: Need some basic help with extensions
Reply With Quote #8

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.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
_mvs
Junior Member
Join Date: Oct 2019
Old 10-19-2019 , 12:32   Re: Need some basic help with extensions
Reply With Quote #9

I guess I missed that part somehow thanks

How do you then write a function that tells when a players says something in a chat?
_mvs is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 10-20-2019 , 04:47   Re: Need some basic help with extensions
Reply With Quote #10

Quote:
Originally Posted by _mvs View Post
I guess I missed that part somehow 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.
__________________
asherkin 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 07:33.


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