TomilovSenya Posted May 7, 2018 Share Posted May 7, 2018 (edited) Hello. I'm rather new to scripting, however, I'm trying to make a mod which would help control the in-game Score, play some sounds and so on. I'm using the RAGE Native UI, and the menu is actually working. The problem is, when I'm trying to play a frontend sound / trigger sound event, the script crashes with the 'System.NullReferenceException' thing. But if I just try to display a notification, it works just fine. Can someone tell me what's the problem here? I'd be very thankful. using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using GTA;using GTA.Native;using RAGENativeUI;using RAGENativeUI.Elements;using Rage;[assembly: Rage.Attributes.Plugin("Score Controller", Author = "TomilovSenya", Description = "Score Controller script.")]public static class EntryPoint { //private static GameFiber MenusProcessFiber; private static UIMenu scoreMain; // Creating the base menu private static UIMenuListItem playScore; // Creating the Play Score list private static UIMenuListItem playSound; // Creating the Play Sound submenu private static UIMenuCheckboxItem muteSounds; // Creating the Disable Sound checkbox private static UIMenuCheckboxItem muteFlying; // Creating the Disable Flying Music checkbox private static UIMenuCheckboxItem muteWanted; // Creating the Disable Wanted Music checkbox private static MenuPool scorePool; // Creating the menu pool public static void Main() { scorePool = new MenuPool(); scoreMain = new UIMenu("Score Controller", "SCORE CONTROLLER"); // TO CHANGE TO BANNER! scorePool.Add(scoreMain); scoreMain.AddItem(playScore = new UIMenuListItem("Select Score", "Select a Score Track to listen to.", "CMH Heist", "Assault", "Bikers")); // Adding the Play Score list scoreMain.AddItem(playSound = new UIMenuListItem("Select Sound", "Select a Frontend Sound to listen to.", "Biker Tip", "CEO Tip", "Wasted", "Loser")); // Adding the Play Sound list scoreMain.AddItem(muteSounds = new UIMenuCheckboxItem("Disable Sound", false)); // Adding the Disable Sound checkbox scoreMain.AddItem(muteFlying = new UIMenuCheckboxItem("Disable Flying Music", false)); // Adding the Disable Flying Music checkbox scoreMain.AddItem(muteWanted = new UIMenuCheckboxItem("Disable Wanted Music", false)); // Adding the Disable Wanted Music checkbox scoreMain.RefreshIndex(); scoreMain.OnItemSelect += OnItemSelect; //scoreMain.OnListChange += OnListChange; scoreMain.MouseControlsEnabled = false; // Mouse control scoreMain.AllowCameraMovement = true; // Camera movement MainLogic(); GameFiber.Hibernate(); } public static void OnItemSelect(UIMenu sender, UIMenuItem selectedItem, int index) // Event on Play Sound pressed { if (sender == scoreMain) { if (selectedItem == playSound) { string soundName = playSound.Collection[playSound.Index].Value.ToString(); if (soundName == "Biker Tip") // If it's Biker TIp { Rage.Game.DisplayNotification("Biker Tip Enabled."); // WORKS FINE Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "Camera_Shoot", "Phone_Soundset_Franklin", 0); // CRASHES; the sound is just a placeholder } } } } public static void MainLogic() // Key etc. { GameFiber.StartNew(delegate { while (true) { GameFiber.Yield(); if (Rage.Game.IsKeyDown(Keys.N)) { scoreMain.Visible = !scoreMain.Visible; } scorePool.ProcessMenus(); }; }); }} A scrap of the RAGE Plugin Hook log: [07.05.2018 22:17:40.945] Score Controller: Exception type: System.NullReferenceException[07.05.2018 22:17:40.946] Score Controller: Exception message: Ссылка на объект не указывает на экземпляр объекта.[07.05.2018 22:17:40.946] Score Controller: ------------------------------[07.05.2018 22:17:40.946] Score Controller: Inner exceptions:[07.05.2018 22:17:40.947] Score Controller: ------------------------------[07.05.2018 22:17:40.947] Score Controller: Stack trace:[07.05.2018 22:17:40.948] Score Controller: в GTA.ScriptDomain.PinString(String string)[07.05.2018 22:17:40.948] в GTA.Native.?A0x55605b1d.ObjectToNative(Object value)[07.05.2018 22:17:40.949] в GTA.Native.InputArgument.op_Implicit(String value)[07.05.2018 22:17:40.949] в EntryPoint.OnItemSelect(UIMenu sender, UIMenuItem selectedItem, Int32 index)[07.05.2018 22:17:40.949] в RAGENativeUI.UIMenu.SelectItem()[07.05.2018 22:17:40.950] в RAGENativeUI.UIMenu.ProcessControl(Keys key)[07.05.2018 22:17:40.950] в RAGENativeUI.MenuPool.ProcessMenus()[07.05.2018 22:17:40.950] в EntryPoint.<>c.<MainLogic>b__9_0()[07.05.2018 22:17:40.951] в Rage.GameFiber.Main()[07.05.2018 22:17:40.951] Score Controller: ============================== Edited May 7, 2018 by TomilovSenya Link to comment Share on other sites More sharing options...
alexguirre Posted May 7, 2018 Share Posted May 7, 2018 The problem here is you're mixing up the SHVDN API with the RPH API. "Function.Call(..." is from SHVDN, while the rest uses RPH. I guess you want to create a RPH plugin, so remove the ScriptHookVDotNet.dll from the project references and delete the "using GTA;" and "using GTA.Native;" lines. For calling natives with RPH you need to use the Rage.Native namespace, so add "using Rage.Native;" at the top, and Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "Camera_Shoot", "Phone_Soundset_Franklin", 0); would be NativeFunction.Natives.PLAY_SOUND_FRONTEND(-1, "Camera_Shoot", "Phone_Soundset_Franklin", 0); Link to comment Share on other sites More sharing options...
TomilovSenya Posted May 8, 2018 Author Share Posted May 8, 2018 The problem here is you're mixing up the SHVDN API with the RPH API. "Function.Call(..." is from SHVDN, while the rest uses RPH. I guess you want to create a RPH plugin, so remove the ScriptHookVDotNet.dll from the project references and delete the "using GTA;" and "using GTA.Native;" lines. For calling natives with RPH you need to use the Rage.Native namespace, so add "using Rage.Native;" at the top, and Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "Camera_Shoot", "Phone_Soundset_Franklin", 0); would be NativeFunction.Natives.PLAY_SOUND_FRONTEND(-1, "Camera_Shoot", "Phone_Soundset_Franklin", 0); Simply wonderful! Thank you so much! Works great now. Link to comment Share on other sites More sharing options...