Sign in to follow this  
Corlesi

Send js Array to c# server

Recommended Posts

Hello, I'm having trouble sending an array from js to c# server:

Client:

let getVehiclesNearbyMe = (range) => {
	const returnVehicles = [];
	
	mp.vehicles.forEachInRange(mp.players.local.position, range,
		(vehicle) => {
			returnVehicles.push(vehicle);
		}
	);	
	return returnVehicles;
};


mp.events.add('EinparkenJS', () => {
    let vehicles = getVehiclesNearbyMe(50)
    if(vehicles.length >= 1) {mp.events.callRemote("EinparkEvent", vehicles);}
    else {mp.gui.chat.push("no vehicle found");}
});

Server:

[RemoteEvent("EinparkEvent")]
		public void OnEinparkEvent(Player player, object[] vehicles)
		{
			player.SendNotification("einparken called");	
			
			if (vehicles != null)
			{
				player.SendNotification(vehicles.GetType().ToString());
				//player.SendChatMessage(vehicles.Length.ToString());
			}
			else player.SendNotification("vehicles is null");
		}

Vehicles is always null..

When I send the first element however I can receive it:

if(vehicles.length >= 1) {mp.events.callRemote("EinparkEvent", vehicles[0]);}

How can I get the whole array?

 

 

Oh also: Is there a c# clientside equivalent to mp....forEachInRange? :D

 

Thanks

Edited by Corlesi

Share this post


Link to post
Share on other sites
On ‎2‎/‎27‎/‎2020 at 12:51 AM, Corlesi said:

Hello, I'm having trouble sending an array from js to c# server:

Client:

let getVehiclesNearbyMe = (range) => {
	const returnVehicles = [];
	
	mp.vehicles.forEachInRange(mp.players.local.position, range,
		(vehicle) => {
			returnVehicles.push(vehicle);
		}
	);	
	return returnVehicles;
};


mp.events.add('EinparkenJS', () => {
    let vehicles = getVehiclesNearbyMe(50)
    if(vehicles.length >= 1) {mp.events.callRemote("EinparkEvent", vehicles);}
    else {mp.gui.chat.push("no vehicle found");}
});

Server:

[RemoteEvent("EinparkEvent")]
		public void OnEinparkEvent(Player player, object[] vehicles)
		{
			player.SendNotification("einparken called");	
			
			if (vehicles != null)
			{
				player.SendNotification(vehicles.GetType().ToString());
				//player.SendChatMessage(vehicles.Length.ToString());
			}
			else player.SendNotification("vehicles is null");
		}

Vehicles is always null..

When I send the first element however I can receive it:

if(vehicles.length >= 1) {mp.events.callRemote("EinparkEvent", vehicles[0]);}

How can I get the whole array?

 

 

Oh also: Is there a c# clientside equivalent to mp....forEachInRange? :D

 

Thanks

 

Ok, I don't know which entities you're using. So I'll make a basic array in the js side and pass it to the server-side as reference. You can use that to determine how to utilize it.

  • Like 1

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.