ScriptingExamples/AddObject: Difference between revisions
Jump to navigation
Jump to search
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 object = gta.createObject(model, client.player.position); | var object = gta.createObject(model, client.player.position); | ||
} | } | ||
});}} | });}} |
Latest revision as of 02:22, 9 April 2025
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);
}
});