Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial messages support #3

Merged
merged 2 commits into from
Jun 14, 2018
Merged

initial messages support #3

merged 2 commits into from
Jun 14, 2018

Conversation

Mistrick
Copy link
Collaborator

@Mistrick Mistrick commented Jun 13, 2018

copy from amxmodx

Description

Motivation and Context

How has this been tested?

#include <spmod>

public PluginInfo pluginInfo =
{
	name = "test2",
	version = "0.0.0",
	author = "author",
	url = "https://github.com/Amaroq7/SPMod"
};

public void OnPluginInit()
{
	int SayText = GetUserMsgId("SayText");
	printToServer("Message SayText = %d\n", SayText);
	char msgname[32];
	GetUserMsgName(SayText, msgname, sizeof msgname - 1);
	printToServer("Message %d = %s\n", SayText, msgname);
}

public void OnClientPutInServer(int client)
{
	int SayText = GetUserMsgId("SayText");
	MessageBegin(MSG_ALL, SayText, {0, 0, 0});
	WriteByte(client);
	WriteString("\1Test\3Hello");
	MessageEnd();
}

Other cases difficult to test without own cmd registration

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

copy from amxmodx
Copy link
Owner

@Amaroq7 Amaroq7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some small objections, but overall looks good.
If you also could add to readme in Acknowledgments section that AMXX code has been used.

#define MSG_PVS_R 6 // Reliable to PVS
#define MSG_PAS_R 7 // Reliable to PAS
#define MSG_ONE_UNRELIABLE 8 // Send to one client, but don't put in reliable stream, put in unreliable datagram (could be dropped)
#define MSG_SPEC 9 // Sends to all spectator proxies
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces?


native void MessageBegin(int dest, int msgid, const int origin[3] = {0,0,0}, int player = 0);

native void MessageBegin(int dest, int msgid, const float origin[3] = {0,0,0}, int player = 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be MessageBeginF?
const float origin[3] = {0,0,0} -> const float origin[3] = {0.0,0.0,0.0} to prevent tag mismatch.

{
enum { arg_dest = 1, arg_msg_type, arg_origin, arg_player };

int numparam = *params / sizeof(cell_t);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was correct in Pawn, this should be replaced with int numparam = *params;

#include "spmod.hpp"

// int GetUserMsgId(const char[] msgname);
static cell_t GetUserMsgId(SourcePawn::IPluginContext *ctx, const cell_t *params) /* 1 param */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep styling that every function parameter is in separate line.

static cell_t GetUserMsgId(SourcePawn::IPluginContext *ctx,
                           const cell_t *params) /* 1 param */

if (params[arg_msg_type] < 1 || ((params[arg_msg_type] > 63) // maximal number of engine messages
&& !GET_USER_MSG_NAME(PLID, params[2], NULL)))
{
// LogError(amx, AMX_ERR_NATIVE, "Plugin called message_begin with an invalid message id (%d).", params[2]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that this and others LogError weren't converted to ctx->ReportError?

case MSG_ALL:
case MSG_SPEC:
case MSG_INIT:
MESSAGE_BEGIN(params[arg_dest], params[arg_msg_type], NULL);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

return 0;
}

MESSAGE_BEGIN(params[arg_dest], params[arg_msg_type], NULL, INDEXENT(params[arg_player]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

}

// native void MessageEnd();
static cell_t MessageEnd(SourcePawn::IPluginContext *ctx, const cell_t *params)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing [[maybe_unused]].
In other functions as well.

{
enum { arg_msg = 1, arg_str, arg_len };

const char* string = GET_USER_MSG_NAME(PLID, params[arg_msg], NULL);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@Amaroq7
Copy link
Owner

Amaroq7 commented Jun 14, 2018

LGTM. Thanks!

@Amaroq7 Amaroq7 merged commit f52f11b into Amaroq7:master Jun 14, 2018

native int GetUserMsgId(const char[] msg_name);

native void GetUserMsgName(int msgid, char[] str, int len);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here must be a return type int

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, I overlooked it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in master.

Amaroq7 added a commit that referenced this pull request Jun 14, 2018
@Mistrick Mistrick deleted the messages branch June 14, 2018 12:17
@Amaroq7 Amaroq7 added this to the v0.1.0-alpha milestone Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants