alexmohor1996 Posted January 20, 2023 Posted January 20, 2023 Hi. Can someone pls help me understand what am I doing wrong here? I am unable to find topics that are both C# server and client for event triggering... I have 2 events but only one of them is being called. I have the Freeze Player and a Vehicle UI and only the freeze event is being called. I have watched a tutorial for making a Vehicle UI and I compared every line of code between the tutorial and what I wrote and it is 1:1 match.. I know that both events have the same outcome, I have just put the SpawnVehicle one in here as a test, because I could not understand whether the code for the vehicle menu was wrong, or it's just mine not being called. It seems that it is not being called at all. I have even commented the Freeze Player from "Events.Add" (I thought it would interfere ) and still nothing. Both of the events are the same, so I can't figure out why SpawnVehicle is not being called. This is the part from the client-side public class Main : Events.Script { public Main() { Events.Add("NativeVehicleMenu", SpawnVehicle); Events.Add("FreezePlayer", PlayerFreeze); } public void PlayerFreeze(object[] args) { RAGE.Elements.Player.LocalPlayer.FreezePosition((bool)args[0]); } public void SpawnVehicle(object[] args) { RAGE.Elements.Player.LocalPlayer.FreezePosition((bool)args[0]); } } This is the part from the server-side [Command("vehicle")] public void CMD_Vehicle(Player player) { NAPI.ClientEvent.TriggerClientEvent(player, "NativeVehicleMenu"); player.SendChatMessage("You have tried to invoke a car, but you have frozen yourself"); } [Command("freeze", "[USAGE] /freeze [target] [true/false]")] public void CMD_Freeze(Player player, Player target, bool isFrozen) { NAPI.ClientEvent.TriggerClientEvent(player, "FreezePlayer", isFrozen); string str = (isFrozen) ? "frozen" : "unfrozen"; player.SendChatMessage($"You have {str} {target.Name}!"); target.SendChatMessage($"{player.Name} has {str} you!"); }
Xabi Posted January 20, 2023 Posted January 20, 2023 You have an error in your code, you should be checking cliendata/clientside_cs.txt file. You're not passing any argument to SpawnVehicle function: NAPI.ClientEvent.TriggerClientEvent(player, "NativeVehicleMenu");
alexmohor1996 Posted January 21, 2023 Author Posted January 21, 2023 (edited) On 1/20/2023 at 3:09 PM, Xabi said: You have an error in your code, you should be checking cliendata/clientside_cs.txt file. You're not passing any argument to SpawnVehicle function: NAPI.ClientEvent.TriggerClientEvent(player, "NativeVehicleMenu"); Thank you so much for the reply. The thing is that the tutorial I have followed does not have any argument and it is working for that guy. I don't know what argument should I pass ... Also I don't know which file you are referring to, as I don't have any "clientside_cs.txt" file, sorry. Edited January 21, 2023 by alexmohor1996
Xabi Posted January 21, 2023 Posted January 21, 2023 In that case a boolean, as you did with freeze command. The arguments/parameters will depend on what you need to develop.
alexmohor1996 Posted January 23, 2023 Author Posted January 23, 2023 On 1/22/2023 at 12:16 AM, Xabi said: In that case a boolean, as you did with freeze command. The arguments/parameters will depend on what you need to develop. Hello. Ok, this is the full method I have written from the tutorial. public void PlayerVehicleMenu(object[] args) { Chat.Show(false); RAGE.Ui.Cursor.Visible = true; MenuPool mPool = new MenuPool(); UIMenu VehicleMenu = new UIMenu("Spawner", "Spawn your desired vehicle"); mPool.Add(VehicleMenu); bool locked = false; bool engine = true; UIMenuCheckboxItem Locked = new UIMenuCheckboxItem("Vehicle Lock?", locked); UIMenuCheckboxItem Engine = new UIMenuCheckboxItem("Engine On", engine); VehicleMenu.AddItem(Locked); VehicleMenu.AddItem(Engine); var vNames = new List<dynamic> { "Infernus", "Cheetah", "Dominator" }; string selectedVeh = vNames[0]; UIMenuListItem VehicleName = new UIMenuListItem("Vehicle", vNames, 0); VehicleMenu.AddItem(VehicleName); UIMenuItem CreateButton = new UIMenuItem("Create Vehicle!"); VehicleMenu.AddItem(CreateButton); VehicleMenu.OnCheckboxChange += (sender, item, flag) => { if (sender == VehicleMenu) { if (item == Locked) locked = flag; else if (item == Engine) engine = flag; } }; VehicleMenu.OnListChange += (sender, item, index) => { if (sender == VehicleMenu) { if (item == VehicleName) { selectedVeh = item.IndexToItem(index).ToString(); } } }; CreateButton.Activated += (sender, item) => { if (sender == VehicleMenu) { if (item == CreateButton) { Events.CallRemote("VehicleSpawnFromClient", locked, engine, selectedVeh); Chat.Show(true); VehicleMenu.Visible = false; VehicleMenu.FreezeAllInput = false; RAGE.Ui.Cursor.Visible = false; } } }; VehicleMenu.Visible = true; VehicleMenu.FreezeAllInput = true; VehicleMenu.RefreshIndex(); Events.Tick += (name) => { mPool.ProcessMenus(); }; VehicleMenu.OnMenuClose += (sender) => { if (sender == VehicleMenu) { Chat.Show(true); VehicleMenu.Visible = false; VehicleMenu.FreezeAllInput = false; RAGE.Ui.Cursor.Visible = false; } }; } And this is the command trying to call the event. I have let the old message I had from SendChatMessage so I know that the command works [Command("vehicle")] public void CMD_Vehicle(Player player, bool args) { NAPI.ClientEvent.TriggerClientEvent(player, "VehicleMenu", args); string str = (args) ? "Menu opened" : "Menu closed"; player.SendChatMessage($"{str}"); } The SendChatMessage appears and I have tried to put a boolean... I have also tried to put a "null" parameter. It simply won't call the method.. It also have a RemoveEvent which is being called when pressing the "Create Car" button, as follows: However, I can see that this is only related to the "Events.CallRemote" method, but it does not even reach there.. [RemoteEvent("VehicleSpawnFromClient")] public void NativeVehicleSpawn(Player player, bool locked, bool engine, string vName) { uint vHash = NAPI.Util.GetHashKey(vName); NAPI.Vehicle.CreateVehicle(vHash, player.Position.Around(5), 0.0f, 0, 0, locked: locked, engine: engine); player.SendNotification($"Vehicle {vName} created"); }
Xabi Posted January 24, 2023 Posted January 24, 2023 Are you using the same client event names you used before? Also you need to find the clientside_cs.txt file located on your RAGE installation path (clientdata folder)
alexmohor1996 Posted January 25, 2023 Author Posted January 25, 2023 (edited) 22 hours ago, Xabi said: Are you using the same client event names you used before? Also you need to find the clientside_cs.txt file located on your RAGE installation path (clientdata folder) After your reply with the 3rd parameter, I have tried to write the exact same method (TriggerClientEvent & Event.Add, have the same name ..... Event.CallRemote & [RemoteEvent], with the same other name) that the guy wrote in the video, but I have added either a "null" parameter (I saw this works in C++), or a boolean, so the command would be something like "/vehicle true", for testing. I can see that neither of them works and with another parameter, like "int" or something, I have no idea how to write, because the original script that I saw does not take parameters.. Also, thank you so much for guiding with the file, I have found it ^^. But I am not sure whether these are errors, or just warnings, it's my first time looking into this file C#: No scripts compiled or no RAGE.Events.Script classes found C#: compiling scripts.. CS0234: The type or namespace name 'Collection' does not exist in the namespace 'System' (are you missing an assembly reference?) -> cs_packages/Main.cs:1 C#: No scripts compiled or no RAGE.Events.Script classes found C#: compiling scripts.. CS0234: The type or namespace name 'Collection' does not exist in the namespace 'System' (are you missing an assembly reference?) -> cs_packages/Main.cs:1 C#: No scripts compiled or no RAGE.Events.Script classes found C#: compiling scripts.. Unable to cast object of type 'System.Int32' to type 'System.Boolean'. ServerPackage at ClientSide.Main.FreezePlayer(Object[] args) in cs_packages/Main.cs:line 15 Edited January 25, 2023 by alexmohor1996
Xabi Posted January 25, 2023 Posted January 25, 2023 All the messages in that file are clientside script errors, in your case it seems that you're getting and int from the server, not a boolean: Unable to cast object of type 'System.Int32' to type 'System.Boolean'. ServerPackage at ClientSide.Main.FreezePlayer(Object[] args) in cs_packages/Main.cs:line 15
alexmohor1996 Posted January 25, 2023 Author Posted January 25, 2023 (edited) 33 minutes ago, Xabi said: All the messages in that file are clientside script errors, in your case it seems that you're getting and int from the server, not a boolean: Unable to cast object of type 'System.Int32' to type 'System.Boolean'. ServerPackage at ClientSide.Main.FreezePlayer(Object[] args) in cs_packages/Main.cs:line 15 It is a boolean (Screenshot below) https://imgur.com/Q38vvSG Also this is from the guy's tutorial, the freezing event. It's 1:1 https://imgur.com/CTYHMHs Edited January 25, 2023 by alexmohor1996
Xabi Posted January 25, 2023 Posted January 25, 2023 Well, you should be debugging the args[0] value on client then, so you make sure it's a boolean at all.
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