Add a Vehicle

From GTA Connected
Revision as of 00:26, 11 December 2019 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description

This code adds a vehicle to the game when a player types /vehicle model in-game.
model must be an integer representing a vehicle model ID, this command example does not work with vehicle model names.
Validation included in this code: Check that the player is spawned, and check that the player typed at least some text after the command name.
Validation not included in this code: Check that the vehicle model ID is valid.

Code

JavaScript, Server-Side

addCommandHandler('vehicle', function(command, parameters, client)
{
	if(!client.player)
	{
		messageClient('You must be spawned to spawn a vehicle!', client);
	}
	else if(parameters.trim() == '')
	{
		messageClient('You must type a model number! Command syntax: /vehicle model', client);
	}
	else
	{
		var model = parseInt(parameters);
		var vehicle = gta.createVehicle(model, client.player.position);
		addToWorld(vehicle);
	}
});