1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

Vehicle Array | Car spawner

Discussion in 'Snippets' started by Vektor42O, Feb 6, 2017.

  1. Vektor42O

    Vektor42O Active Member

    Messages:
    77
    Likes Received:
    54
    Joined:
    Jan 24, 2017
    Hi!
    I wanted to create a command where i can spawn a vehicle just by the part of the model name, so i created an array of vehicle models.

    Download: http://gtan.codeshock.hu/index.php?page=vehicles

    Example:
    Code:
        [Command("v")]
        public void SpawnCarCommand(Client sender, string model)
        {
            int modelindex = -1;
            for(int i=0; i<VehicleModels.Length; i++)
            {
                if(VehicleModels[i].IndexOf(model, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    modelindex = i;
                    break;
                }
            }
            if(modelindex == -1)
            {
                API.sendChatMessageToPlayer(sender, "Vehicle model on name " + model + " not found!");
                return;
            }
    
            var rot = API.getEntityRotation(sender.handle);
            var veh = API.createVehicle(API.vehicleNameToModel(VehicleModels[modelindex]), sender.position, new Vector3(0, 0, rot.Z), 0, 0);
    
            API.setPlayerIntoVehicle(sender, veh, -1); 
            API.sendChatMessageToPlayer(sender, "Vehicle model " + VehicleModels[modelindex] + " spawned!");   
        }
    Usage: /v [part of the vehicle model]
    /v inf -> will spawn an infernus

    Thanks for the wiki page creators!
     
    Last edited: Feb 28, 2017
    kova98 and MrPancakers like this.
  2. MrPancakers

    MrPancakers Active Member

    Messages:
    90
    Likes Received:
    19
    Joined:
    Aug 2, 2016
    Very useful command and easy to understand. Thanks for compiling a whole list of vehicles!
     

Share This Page