Log in to reply
 

Automatic vehicle spawn and rotation



  • Hi all,
    I am a phd student in computer vision and machine learning. Our group is collecting car images for research.
    The data should be like this : images of a stationary car from different viewpoints (maybe 20 viewpoints) are a group of data, which means within one group the car is the same and only the viewpoint changes. We need tens of thousands of groups captured for different cars in different scenes. Obviously, it can not be done manually.
    It is nice that Script Hook can spawn cars and change scenes. Is it possible to customize the script so that it can automatically spawn a car, change the scene, rotate the view in 360 degrees and this cycle repeats?
    We appreciate any suggestions. Thank you for your reply!



  • @hnwxc00 You can either move the car, or move the camera, or both. If it was me, I would be just moving the camera.

    The problem comes from the fact that each vehicle is a different size, so one camera view might work for a small compact but that same view would be too close for a larger vehicle. That would mean you need to write code that gets the size of the vehicle and then modifies the camera position based on the scale of that model. Or you could possibly place the camera relative to vehicle bone positions (like wheels, doors etc...), which would probably work a bit easier for your needs.

    The rest of it would be fairly straight forward, have a list of vehicle names, go through the list one-by-one and spawn each one in turn. You would have the same thing for a list of camera positions, that you then go through one-by-one. Once you have done all the camera positions, you move onto the next vehicle in the list and so on, so forth. The spawning code I have already got as I am working on a data-collection mod that does exactly that. The camera code I haven't got though...

    There's probably a fair bit of prep-work involved getting the desired camera positions but once you have them, the rest isn't too bad.



  • @hnwxc00 The next few comments will contain the code and instructions for reading a sequence of vehicle names from a file and spawning them in turn, this might get you started.

    Copy the following text into a file called spawn-names.txt and place it in your scripts folder.

    adder
    airbus
    airtug
    akuma
    alpha
    ambulance
    annihilator
    asea
    asea2
    asterope
    avarus
    bagger
    baller
    baller2
    baller3
    baller4
    baller5
    baller6
    banshee
    banshee2
    barracks
    barracks2
    barracks3
    bati
    bati2
    benson
    besra
    bestiagts
    bf400
    bfinjection
    


  • Place the following code into a file called SpawnModeTest.cs and also place it in your scripts folder. Ignore the wonky formatting, it will be fine when you paste it into a document.

    using System;
    using System.IO;
    using System.Windows.Forms;
    using GTA;
    using GTA.Math;
    using GTA.Native;
    
    namespace SpawnModeTest
    {
        public class cSpawnModeTest : Script
        {
            private int CurrentGameTime;
            private int ElapsedGameTime;
            private int LastGameTime;
    
            private Ped PlayerPed;
            private bool SpawnMode = false;
    
            private Vector3 SpawnLocation;
    
            private int SpawnTimer;
            private int SpawnCounter;
            private int SpawnMax;
    
            private string[] SpawnNames;
    
            public cSpawnModeTest()
            {
                this.Tick += onTick;
                this.KeyUp += OnKeyUp;
                Interval = 0;
    
                Initialise();
            }
    
    
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            // Initialise the mod here
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            private void Initialise()
            {
                UI.Notify("~g~Sequential Spawn Test");
    
                PlayerPed = Game.Player.Character;
    			
    			// Get the names of the vehicles from the text file
    			SpawnNames = File.ReadAllLines("scripts\\spawn-names.txt");
    			
    			// Set the end counter to be equal to the number of vehicles in the text file
    			SpawnMax = SpawnNames.Length;
    			
    			UI.Notify(SpawnNames.Length + " names read from file.");
            }
    
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            // OnTick event fires every frame
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            private void onTick(object sender, EventArgs e)
            {
                CurrentGameTime = Game.GameTime;
                ElapsedGameTime = CurrentGameTime - LastGameTime;
                LastGameTime = CurrentGameTime;
    
    			// If we are in spawn mode
                if (SpawnMode)
                {
                    DoSpawn(ElapsedGameTime);
                }
    			else
    			{
    				// Get the spawn location relative to the player
    				SpawnLocation = PlayerPed.GetOffsetInWorldCoords(new Vector3(0, 10, 0));
    				
    				// Draws a marker on the ground to show where the vehicles will spawn
    				Function.Call(Hash.DRAW_MARKER, 0, SpawnLocation.X, SpawnLocation.Y, SpawnLocation.Z, 0f, 0f, 0f, 0f, 0f, 0f, 0.75f, 0.75f, 0.75f, 255, 255, 0, 255, false, false, 2, false, false, false);
    			}
            }
    
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            private void DoSpawn(int _elapsedGameTime)
            {
    			// decrement the timer by the number of milliseconds that have elapsed
                SpawnTimer -= _elapsedGameTime;
    
                if (SpawnTimer < 0)
                {
                    // Check the spawn location for vehicles
                    Vehicle NearbyVehicle = World.GetClosestVehicle(SpawnLocation, 10);
    
    				// If there is a vehicle nearby...
                    if (NearbyVehicle != null)
                    {
                        // Delete that vehicle to make space for the new one
                        NearbyVehicle.MarkAsNoLongerNeeded();
                        NearbyVehicle.Delete();
                    }
    				
    				// Get the spawn name from the list
                    string _spawnName = SpawnNames[SpawnCounter];
    
                    // Create the new vehicle and put it on the ground
                    Vehicle SpawnVehicle = World.CreateVehicle(_spawnName, SpawnLocation, 0);
                    SpawnVehicle.PlaceOnGround();
    				
    				// Just a notification of what is being spawned and the counter number
    				UI.Notify(string.Format("[{0:00}] Spawned " + SpawnVehicle.FriendlyName, SpawnCounter.ToString()));
    				
                    // Reset the spawn timer
                    SpawnTimer = 3000;
    				
                    // move to the next spawn name
                    SpawnCounter++;
    
                    if (SpawnCounter == SpawnMax)
                    {
                        UI.Notify("All Vehicles Spawned");
                        SpawnMode = false;
                    }
                }
            }
    		
    		// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            private void OnKeyUp(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F10)
                {
    				// Toggle the mode flag
    				SpawnMode = !SpawnMode;
    				
                    if (SpawnMode)
                    {
    					// Set the SpawnTimer to 0 so that the first vehicle spawns straight away.
                        SpawnTimer = 0;
    					
    					// Set the counter to the first vehicle
                        SpawnCounter = 0;
                    }
                }
            }
        }
    }
    


  • Press F10 to toggle the spawn mode on and off. When it is off, you will see a yellow marker on the ground in front of you, this is where the vehicles will spawn.

    SpawnTimer is set to 3000 milliseconds (3 seconds) and it will go once through the list and then stop.



  • Well as it's been 4 days since this was posted and the OP has done a runner, I guess we can call this time wasted... thanks OP.

    I wonder if the words "Chinese" and "University" have anything to do with this... :\



  • I'll post a request soon @LeeC2202
    Promise I won't hit and run :squid:
    .
    .
    .
    .
    .

    Or kiss and tell for that matter....



  • @LeeC2202 said in Automatic vehicle spawn and rotation:

    I wonder if the words "Chinese" and "University" have anything to do with this... :\

    What did you mean? Anything to do with what?



  • @Akila_Reigns A while back rappo mentioned the "first post" moderation thing to combat the Chinese university spammers (I think a few people have at some point, including myself) and I looked at the username (pretty random collection of letters and a numeric suffix of 00) and wondered if this might be a copy & paste from somewhere else to bypass that.

    I can't think of many reasons why someone would post such a technical and specific request and not even bother to return to the site for four days. It just all seemed a bit odd. :\

    Or maybe I really am becoming too [sceptical/cynical/suspicious] (delete as appropriate) for my own good. :D



  • @LeeC2202 I understand now. Thanks for the explanation. :)



  • This forum could seriously use a class-based user system imho. Probably one of the reasons it's already on its decline :fearful:



  • @ReNNie In which sense do you mean class-based, do you mean software wise? Or do you mean class-based as in a tiered structure where users are promoted etc...?



  • The latter, although I doubt @rappo will see it like that or ever want to go that way...
    To me the unlimited and unrestricted downloads offer a safe haven for hit and run kids and lack of respect for the work done by others.
    If you want to connected a group of commited users into a community imo you'll have to separate the wheat from the chaff.

    We had a little forum like this in 2012&2013 ran by two Irirsh blokes in IV days: gta-mad.com. With supporting facebook and twitter, https://twitter.com/gtamadofficial.
    Unfortunately the site litteraly died on us when they both moved to NYC and stopped all their admin activities :/

    So, tiered something like this (mods and admin hand out the priviliges) with differences in priviliges on posting, downloads, access to restricted forum sections (eg discussions on site functionality, request for code, cars, whathaveyou):

    1. User: ability to post in certain sections after 1 week and after an introductionary post, not able to make requests;
    2. Dweller: # posts above 100 and/or reputation above 50;
    3. Contributor: # posts above 200 and/or reputation above 100 OR written tutorials and showing a helping hand in problem-solving for users;
    4. Creator: uploaded multiple contributions to the download-section with a certain quality, has access to restricted forum areas and gets some more perks;
    5. ViP: donated to the server costs and/or patreon to some creators, instant access to restricted forum areas, gets the all-wanted yellow 'featured' star displayed at his nickname.

    Not too many around (and still active) from that era @Carrythxd @Neophyte-Industries @PacketOverload @tall70 (?) @jackrobot @tiagoesanto, etc.



  • @ReNNie Hmmm, can't say as I like that kind of system either. I don't think what you do on a site should earn you anything above what other users can do. I think any user should be able to ask or contribute the same, I think hit and run posters are just a small minority we have to deal with.

    Even though this person has disappeared, I still ended up with a mod I learned things from and what that I actually like. :D It's annoying when people do this but hey, that's people for ya. :D I do my own fair share of being annoying.


  • MODERATOR

    @ReNNie Completely off-topic (sorry :P) but I really miss GTA-Mad, it was one of the best websites I've ever been a part of. Every now and then I hope that it'll come back some day but it most likely won't


Log in to reply
 

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