Sign in to follow this  
VonHornmeister

Listening for client event in server

Recommended Posts

My server cant seem to receive the data I send from client-side.

Server-side

using GTANetworkAPI;

namespace Login {
public class Login : Script
{
    public Login(API api)
    {
        /*
        Errors I get =>
        
         CS1061: 'API' does not contain a definition for 'onClientEventTrigger' and no extension method 'onClientEventTrigger' accepting a first argument of type 'API' could be found (are you missing a using directive
        or an assembly reference?)
       -> login.cs:7

        CS0103: The name 'OnClientEventTrigger' does not exist in the current context
       -> login.cs:7
         */
         API.onClientEventTrigger += OnClientEventTrigger;
         API.ConsoleOutput("Started");
    }

    public void OnClientEvent(Client player, string eventName, params object[] arguments)
    {
        API.ConsoleOutput("PRessed");
        if (eventName == "Login")
      {
                API.ConsoleOutput(eventName);
            foreach(var item in arguments)
            {
                API.ConsoleOutput(item.ToString());
            }
            API.SendChatMessageToPlayer(player, "Test");
      }
    }
  }
}

 

Client-side

mp.events.add('logInRequest', function() {
    const credentials = JSON.parse(arguments[0]);

    //API.triggerServerEvent("OnExample", credentials.email, credentials.password); <= gives me error that API is not defined
    mp.events.callRemote("OnExample", credentials.email, credentials.password); // <= Wont send or server cant receive
});

 

Any ideas?

 

FIXED:

Server-side code

using GTANetworkAPI;

public class LoginEvents : Script
{

    [RemoteEvent("Login")] // <= I was missing that part 
    public void LoginEvent(Client player, string test)
    {
        API.ConsoleOutput("Pressed: " + test);
    }
}

 

Client-side code

mp.events.add('logInRequest', function() {
	const credentials = JSON.parse(arguments[0]);
	mp.events.callRemote("Login", credentials.email, credentials.password);
});

 

Edited by VonHornmeister
Fixed

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.