Corlesi Posted February 26, 2020 Posted February 26, 2020 (edited) 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? Thanks Edited February 27, 2020 by Corlesi
$kylar Posted February 28, 2020 Posted February 28, 2020 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? 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. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now