ScriptingExamples/AddVehicle: Difference between revisions
No edit summary |
m (Removed 'addToWorld()' function invoke as the webpage for 'addToWorld()' (https://wiki.gtaconnected.com/addToWorld) states that it no longer needs to be invoked.) |
||
Line 22: | Line 22: | ||
var model = parseInt(parameters); | var model = parseInt(parameters); | ||
var vehicle = gta.createVehicle(model, client.player.position); | var vehicle = gta.createVehicle(model, client.player.position); | ||
} | } | ||
});}} | });}} |
Latest revision as of 02:22, 9 April 2025
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);
}
});