Notice: Failed to invoke Pygments: [Called from MediaWiki\SyntaxHighlight\SyntaxHighlight::highlightInner in /home/pi/www/gtac/wiki/wiki/extensions/SyntaxHighlight_GeSHi/includes/SyntaxHighlight.php at line 334] in /home/pi/www/gtac/wiki/wiki/includes/debug/MWDebug.php on line 507
Add a Vehicle - GTA Connected

Add a Vehicle

Revision as of 00:26, 11 December 2019 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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);
	}
});