Log in to reply
 

Broken Spawn Mechanic, some experienced eyes for a review would help.



  • only some are, not all of them



  • @xhiyikfkox And that mod stops some of them from disappearing.



  • of the vehicles I have tested spawning, none are listed on that mod page in its description.



  • @xhiyikfkox Okay... all I know is that if I was writing a mod that spawned vehicles (which I currently am, 2 of), I would not be trying to do it without a mod installed that fixes a known problem with vehicles that have been spawned. That's just asking for a whole heap of trouble that will do nothing but complicate the problem... but that's your choice.



  • @LeeC2202 Good point, and I was wrong, the Virgo3 is one of the vehicles I was having trouble with, just tested and rechecked the list, virgo3 is listed... downloading and installing now XD



  • @xhiyikfkox I could recognise several on that list, Virgo, Slamvan... if you remember, I ran your code so saw what was in that list of muscle hashes.



  • gg true, when i gave the list a look over didnt register the fact that the virgo3 was first car in my list XD. With the mod you suggested installed the virgo3 is an instant spawn. The other cars however... first attempt to spawn and wait a few seconds, nothing, second time hitting spawn and it pops in.



  • so after a little playing around with this menu, it seems the mod menu has trouble spawning in the aspect of, when I select getVehicle the game has a little trouble or delay in getting the info the first time, second time it works, but its just having a bit of trouble getting all the vehicle info first time where second time it has already acquired the vehicle info from first try and so it spawns it the second time.



  • @xhiyikfkox My next approach would be to determine if the method of spawning is the problem or not, or whether any of the code in the spawning section is a potential cause.

    The way I would do that, is to add another UIMenuItem to your menu, that does one thing and that is to spawn one of the problem vehicles by model name. Just something as simple as:

    Vehicle v = World.CreateVehicle("virgo3", Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0,5,0)), Game.Player.Character.Heading);

    It really shouldn't make a difference but that doesn't necessarily mean that it doesn't. It's quick and easy to add and it will just give you another spawn method to compare against.



  • @LeeC2202 Just implemented the code blow and that even had trouble... the code resulted in the null error again. It crashed the script trying to spawn the Dominator via the code below. Returned on the log as System.NullReferenceException: Object reference not set to an instance of an object.

    UIMenuItem getDominator = new UIMenuItem("Get a Dominator");
    submenu.AddItem(getDominator);

            submenu.OnItemSelect += (sender, item, index) =>
            {
                if (item == getDominator)
                {
                    Ped gamePed = Game.Player.Character;
                    Vector3 spawnPos = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0));
                    Vehicle v = World.CreateVehicle("Dominator", spawnPos, gamePed.Heading);
                    if (v.PlaceOnGround())
                        UI.Notify("Vehicle Placed");
                    else
                        UI.Notify("Vehicle Null");
                }
            };


  • @xhiyikfkox All you needed was this line:

    Vehicle v = World.CreateVehicle("dominator", Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0,5,0)), Game.Player.Character.Heading);

    The whole idea behind doing simple tasks to test code, is you are trying to eliminate every other element that might cause a problem. The more you add to the task, the more chances you will have of getting a failure, from something unrelated to the actual thing you're trying to test.

    You don't need the PlaceOnGround() code, it's irrelevant for this test and is just a place where v might not exist, thus causing a crash.

    And if you've gone to the trouble of getting gamePed, you might as well use it in all the places where it can be used, like here:

    Vector3 spawnPos = gamePed.GetOffsetInWorldCoords(new Vector3(0, 5, 0));



  • Ok I basically took my code, commented it out and rewrote it simpler, listed below. The Vehicle still has the delay and will not spawn on first attempt, actually takes 3 attempts to spawn. There is no place on ground but the vehicle is spawning on me. I setup a notify to let me know if the vehicle returned null and it never runs that notify so it is getting the info.

    UIMenuItem getDominator = new UIMenuItem("Get a Dominator");
    submenu.AddItem(getDominator);

            submenu.OnItemSelect += (sender, item, index) =>
            {
                if(item == getDominator)
                {
                    Ped gamePed = Game.Player.Character;
                    Vehicle v = World.CreateVehicle("Dominator", gamePed.Position, gamePed.Heading);
                    if(v != null)
                        UI.Notify("Vehicle Null");
                }
            };


  • @xhiyikfkox That sounds like it could just be taking a while to access the file and is falling back out of the CreateVehicle() after a timeout period.

    I don't have the time to stop what I'm doing right at this moment to try it in my own code... I'm trying to get a set of car badges exported for one of my mods and I've still got 10 to do.

    When I have finished this, I will try spawning the same vehicle, see if I get the same problem.



  • @LeeC2202 That's ok, do your thing I do appreciate the help, I will keep playing around with my code and see if I can get it to work.



  • @xhiyikfkox Ok, just tested spawning the Dominator with the line of code I posted and it was almost instantly spawned on the first press. But I am running the game off an SSD, which does influence things a bit.



  • @LeeC2202 My system has no ssd's installed, im running on basic hdd's and system is on C while game is located on E



  • So I do have to ask something, the line your said to try, are you putting that in a button? or just tossing that line in there randomly? Placement on that line is what I am not understanding.



  • @xhiyikfkox I just added it to a MenuItem, so basically, when I select that menu item, it does that line of code.

    The only other difference is that I am using my own menu system, not NativeUI but I wouldn't have thought that would make too much difference, although NativeUI has been proven to cause anything up to (and over in some cases) a 50fps performance hit in some cases.

    You could try adding it to a keypress in your OnKeyDown() event, see if that makes any difference.



  • @LeeC2202 Took you up on that setting it to a key press. Set the dominator instead of the virgo3, even on keypress the first press does nothing, after that it spawns every time... Not sure why only first press does nothing...



  • @xhiyikfkox If you want me to try that code on my machine, host the dll somewhere (Google Drive or something) and PM me the link.

    I've finished my 34 badges now, so I'm coding and testing stuff anyway, so dropping a script in to test is no hassle.



  • @xhiyikfkox Well, this could be none of my business, and I could be totally wrong, but in your code, you have mentioned
    if(v != null)
    UI.Notify("Vehicle Null");

    Did you mean if(v == null)?
    Cause, you are passing the parameter which may conflict the above line of code, if vehicle exists?

    P.S. Out of all different context, I liked your comment where you mentioned your father helping you in this activity of yours.
    Made me an emotional fool a bit for a while.
    Its always good to know when you have someone to back you up. Happy modding. (:



  • @ashishcw said in Broken Spawn Mechanic, some experienced eyes for a review would help.:

    Did you mean if(v == null)?

    That would result in the code being run if v was null, which would cause a crash.

    != means is not equal to or does not equal



  • @LeeC2202 Exactly that's what my point.

    In the initial code, v is already been assigned
    Vehicle v = World.CreateVehicle("Dominator", gamePed.Position, gamePed.Heading);
    So script may produce some unexpected results, since v is no more null now, and that's what the below code is checking for. Though no adverse effect since, only UI notification is called in that case, but still.
    if(v != null)
    UI.Notify("Vehicle Null");

    Sorry, if I am being a noob.



  • Just saw the comment on the if(v != null) thing, yea its my misstype it needs to be if == null.

    @ashishcw, yes my father has worked with code for years as he is a software developer, so if there are things I don't understand or can't get to work I ask him for help. He is not familiar with how SHVDN works and that not every thing needs to be called. Also he dose not work with modding games, I am due to it being a medium, field im interested in, thus it is easy for me to focus on it.

    @LeeC2202 I posted the scripts to google drive, I am sending you a pm with the link.



  • my script is bigger than what is actually running but that is due to me having commented most of it out yesterday trying to test to see what the issue is. The UI is set to F10, Its a menu that will open mainMenu, then select Vehicles, Spawner and the button is Dominator, so it will spawn a dominator. Also I have NumPad 0 set to spawn a dominator too, as I was trying to set it to a key press to see if it still had the delay too.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.