Raised This Month: $32 Target: $400
 8% 

AMXX Suggestion: get_user_msgname in Core or Engine


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 10-19-2004 , 23:44   AMXX Suggestion: get_user_msgname in Core or Engine
Reply With Quote #1

I just wanted to make my point clear about this. I believe there should be a function called get_user_msgname (or whatever other name you see fit) in either the engine module or the core.

The native declaration would look something like this:
Code:
/* Gets name of client message from message id. */ native get_user_msgname(msgid, name[], len);

As you can see, the first argument is a message id. This would be a number greater than 0. The next argument is the string variable that the message name would go in. And finally the third argument is the length of the name you want to return. This function will return 1 if there is a name for the message id or 0 if there isn't a name for it.

At first I thought this might be possible without the native using FakeMeta to hook RegUserMsg and get all the message names from that. But this is not the case as the AMXX plugin is loaded after RegUserMsg is even called.

Here's the code that would need to be implemented for this native:
Code:
static cell AMX_NATIVE_CALL get_user_msgname(AMX *amx, cell *params) /* 3 param */
{
  const char* szName = GET_USER_MSG_NAME(PLID, params[1], NULL);
  if (szName) {
	  return set_amxstring(amx, params[2], szName, params[3]);
  }

  return 0;
}
As you can see, it's not really all that difficult to add because Metamod already provides a macro function for doing this, just as it provides a macro for getting a message ID from a name. This new native would be a complement to get_user_msgid. If you can get a message ID from a name, doesn't it make sense to be able to get a message name from an ID as well?

The reason I am in need of such a function is for a message logging plugin that I am almost finished with. I am well aware of a similar plugin written by Pimp Daddy, however mine is different. My plugin will allow you to log message information to the AMXX log files. But not only that, you can check for for more than one message at a time. Pimp Daddy's plugin lets you only do one at a time realistically. And you have to change the map if you want to every time you want to check a new message. My plugin will allow you check messages on the fly and stop or start message logging for any message you wish. Not only that, but you can filter the messages by an entity ID. You also have the option of just logging all messages that are sent. Because of this, a get_user_msgname native is needed to differentiate between the messages that can be logged. And the best way to do that is by message name. In the mean time, I have been forced to compile a custom copy of AMXX in order to test my plugin. And I'd really like this to become a public plugin in the future.

I'm sure other people could find such a native useful at some point in time. There are other natives in AMXX that are rarely used. I understand that this could be another such one. However, those rarely used natives do truly have a good use and as does get_user_msgname. So I really hope you will consider implementing this.

EDIT
Here's an interesting use for get_user_msgname besides for just simply getting a message name. You can can use it to check if a message id is in fact valid. This will work for all mods as well. The messages reserved by the engine are 1-63. The metamod function has given a few of those engine reserved messages a name. But any messages registered by the mod start at 64. Therefore if the msgid is >= 64 and has no name, that means it's not a valid message id.

Code:
stock bool:is_msg_valid(msgid) {     new name[32]     new retval = get_user_msgname(msgid, name, 31)         if (msgid < 1 || (msgid > 63 && !retval))         return false             return true }
DS 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 12:14.


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