Jump to content
RAGE Multiplayer Community

OnPlayerConnected event does not work


Mateox
 Share

Recommended Posts

Hi,

I recently came back to RAGE mp, before that I used GTA:MP.

Events like: OnPlayerConnected, OnPlayerSpawn do not work in C# for me. The only event I can handle is OnResourceStart.

Sometime, when player closes the game, server throws an exception:

Unhandled Exception: System.Reflection.TargetParameterCountException: Parameter count mismatch.
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at GTANetworkInternals.EventHandler.Parse(Event _event, Object[] arguments)

To fix this issue I have tried both Linux and Windows servers. I have also tried to copy Bootstrap.dll from server's runtime the resource

Link to comment
Share on other sites

thats because your parameters given into your method when the server is triggering the event does not match with the expected ones.

You have to do: (C#)

[ServerEvent(Event.PlayerConnect)]
public void OnPlayerConnect(Client player) { 
	//logic
}

If you do not enter the client parameter, you'll get this error message like you've pasted.

Edited by Division
Link to comment
Share on other sites

Thanks for the reply @Division.

Well, unfortunately that's exactly what I have in my code.

But it has to be something wrong with the code or another dll file because original resource 'welcomemessages' which basically is sending message when I am connecting, is working fine.

Link to comment
Share on other sites

Yes, let me post my code 😅

using GTANetworkAPI;

namespace GLP
{
    public class Main : Script
    {
        private Authorisation.Authenticator authenticator;

        [ServerEvent(Event.ResourceStart)]
        public void ResourceStart()
        {
            StartAuthenticator();
        }

        [ServerEvent(Event.PlayerConnected)]
        public void OnPlayerConnected(Client player)
        {
            NAPI.Log.Exception("PlayerConnected");
            authenticator.PlayerConnected(player);
        }

        [ServerEvent(Event.PlayerSpawn)]
        public void OnPlayerSpawn(Client player)
        {
            NAPI.Log.Exception("PlayerSpawned");
            authenticator.PlayerSpawned(player);
        }

        #region authentication
        private void StartAuthenticator()
        {
            authenticator = new Authorisation.Authenticator(this);
        }
        #endregion authentication
    }
}

Actually should... Authenticator class also be referencing to Script?

Link to comment
Share on other sites

That all looks fine.
No need to reference Script to Authenticator because you're already in that event when you use this class.

How do you know ResourceStart is working? Have you done an output for test, if this gamemode is loading?

You need to define this in meta.xml file

Link to comment
Share on other sites

I went through this tutorial

It allowed me to put a break points.

OnResourceStart triggers the break point but other events don't.

That's why I put the logging just to make sure.

Ok, missing reference to Script was the problem!

Thank's for helping me out 😉

Link to comment
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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...