Sign in to follow this  
Mateox

OnPlayerConnected event does not work

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

are you using c# on server-side?

If so, are you referencing your classes with GtaNetworkAPI.Script?

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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 😉

Share this post


Link to post
Share on other sites

Had exact same problem. What I did is I copied bootstrapper from RageMP runtimes to NuGet package and it worked perfectly. 

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.