OldScriptingExamples/AddObject: Difference between revisions
Jump to navigation
Jump to search
m (Mex moved page ScriptingExamples/AddObject to OldScriptingExamples/AddObject) |
No edit summary |
||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:Add Object}} | {{DISPLAYTITLE:Add Object}} | ||
'''Warning'''<br> | |||
This example is outdated, and only works on ancient versions of GTA Connected. | |||
== Description == | == Description == | ||
Latest revision as of 19:08, 15 June 2026
Warning
This example is outdated, and only works on ancient versions of GTA Connected.
Description
This code adds an object of the specified model index when typing /o model
The model index defaults to 583 (a ramp) if it isn't specified or it isn't a number.
A chat message is also displayed for all players when the command is used.
Code
Lua, Server-Side, GTAC versions 1.0.71 and below:
addCommandHandler("o",function(commandName,arguments,client)
local player = client.player
local model = arguments:len() > 0 and tonumber(arguments) or 583
local object = game.createElement(ELEMENT_OBJECT, player.game)
object.modelIndex = model
object.game = player.game
object.position = getPositionInFrontOfRad(player.position, player.heading, 8.0)
object.heading = player.heading
addToWorld(object)
outputChatBox(player.name .. ' added an object with model ID ' .. model .. '.', COLOUR_GREEN)
end)
function getPositionInFrontOfRad(pos, rad, radius)
rad = rad + math.pi / 2
pos.x = pos.x + radius * math.cos(rad)
pos.y = pos.y + radius * math.sin(rad)
return pos
end