Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    2. News

    1. Red Dead Redemption 2

      1. News
      2. Red Dead Online
      3. The Armadillo Inn
    1. GTA Online

      1. After Hours
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

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

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Site Suggestions

Sign in to follow this  
TomilovSenya

Sh*tcode Fix Needed

Recommended Posts

TomilovSenya
Posted (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 by TomilovSenya

Share this post


Link to post
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);

Share this post


Link to post
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.

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  

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

×

Important Information

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