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 an Object - GTA Connected

Add an Object

Description

This code adds an object to the game when a player types /object model in-game.
model must be an integer representing an object model ID.
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 object model ID is valid.

Code

JavaScript, Server-Side

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