introzen

Server-side OnPlayerCommand event

Recommended Posts

Posted (edited)

It would be nice to have a ServerEvent triggered when a player enters a command. Currently there seems to be one only on client-side, which is dangerous to use for permission checks etc.

While the wiki actually covers the server-side event in JS, it doesn't seem to exist in C#.

Edited by introzen

Share this post


Link to post
Share on other sites
23 minutes ago, introzen said:

Not what I mean. I'm looking for an event that is triggered everytime a player sends a command, which can be used to intercept the command before it executes it's method.

This is literally what i gave you. The server side command event that you gonna use to register your commands and to process what's done when player types the command. It's the equivalent of the playerCommand(the wiki link you posted).

Share this post


Link to post
Share on other sites
Posted (edited)
30 minutes ago, robearded said:

This is literally what i gave you. The server side command event that you gonna use to register your commands and to process what's done when player types the command. It's the equivalent of the playerCommand(the wiki link you posted).

Then can you please let me know how I can utilize that to make an OnPlayerCommand event server-side in C#?

Each time a player writes a command (no specific command, just a command), the method OnPlayerCommand should be called.

Thanks in advance!

Edited by introzen

Share this post


Link to post
Share on other sites
2 hours ago, introzen said:

Then can you please let me know how I can utilize that to make an OnPlayerCommand event server-side in C#?

Each time a player writes a command (no specific command, just a command), the method OnPlayerCommand should be called.

Thanks in advance!

You have to register commands in server-side C#.

If you want to get any command, then try catching the event 'chatMessage' cause that is what the rage.mp chat calls when the message starts with '/' (command)

Share this post


Link to post
Share on other sites
16 minutes ago, robearded said:

You have to register commands in server-side C#.

If you want to get any command, then try catching the event 'chatMessage' cause that is what the rage.mp chat calls when the message starts with '/' (command)

Already tried it. Server-event ChatMessage isn't triggered when the message starts with /.

Share this post


Link to post
Share on other sites
Posted (edited)
3 minutes ago, introzen said:

Already tried it. Server-event ChatMessage isn't triggered when the message starts with /.

Sorry, i gave the wrong event. Here is the event triggered by the chat browser when message starts with /: "command" (without ")

Catch it like any other custom event sent from your client script to your server script (using RemoteEvent)

If that doesn't works try catching the same event as you would do on javascript ('playerCommand') using the same method (RemoteEvent)

Edited by robearded

Share this post


Link to post
Share on other sites
1 minute ago, robearded said:

Sorry, i gave the wrong event. Here is the event triggered by the chat browser when message starts with /: "command" (without ")

No worries, however it doesn't seem to be accessable from the API.

[ServerEvent(Event.command)]
public void OnPlayerCommand(Client player, string cmdText)
{
player.SendChatMessage("You wrote a command");
}

'Event' does not contain a definition for 'command'

That is what I get...

Share this post


Link to post
Share on other sites
Posted (edited)
10 minutes ago, introzen said:

No worries, however it doesn't seem to be accessable from the API.

[ServerEvent(Event.command)]
public void OnPlayerCommand(Client player, string cmdText)
{
player.SendChatMessage("You wrote a command");
}

'Event' does not contain a definition for 'command'

That is what I get...

 

You have to catch it as custom event, not like normal server events.

[RemoteEvent("command")]

if not working with 'command' try with 'playerCommand'

Edited by robearded

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.