Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

Sh*tcode Fix Needed


TomilovSenya
 Share

Recommended Posts

TomilovSenya

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 by TomilovSenya
Link to comment
Share on other sites

alexguirre

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

TomilovSenya

 

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

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
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.