CreateVehicle: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
(36 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | |||
{{FuncDescription|This function creates a vehicle at a desired location. | |||
CreateVehicle(modelid, x, y, z [, heading]) | '''Vehicles automatically respawn after 5 minutes. Use [[SetVehicleRespawnParams]] to control this behavior.'''}} | ||
</ | |||
{{FuncSyntax|CreateVehicle(modelid, x, y, z [, heading])}} | |||
<div class="noprint" style="float:right;"> | |||
[[File:vehicle_spawn.gif]] | |||
</div> | |||
{{FuncParameters}} | |||
{{FuncParam|modelid|The [[Vehicles|model identifier]] for which vehicle to spawn.}} | |||
{{FuncParam|x, y, z|The location/coordinates of where this vehicle is going to spawn.}} | |||
{{FuncParamOptional|heading|The direction (yaw axis) in which this vehicle is going to be positioned.}} | |||
{{FuncReturnValue|Returns an identifier to the new vehicle. '''false''' on error.}} | |||
== Example == | == Example == | ||
Line 13: | Line 23: | ||
model = tonumber(model) | model = tonumber(model) | ||
local x, y, z = GetPlayerLocation(player) | local x, y, z = GetPlayerLocation(player) | ||
Line 31: | Line 32: | ||
end | end | ||
SetVehicleLicensePlate(vehicle, "ONSET") | |||
SetVehicleLicensePlate(vehicle, " | |||
AttachVehicleNitro(vehicle, true) | AttachVehicleNitro(vehicle, true) | ||
if (model == 8) then | if (model == 8) then | ||
-- Ambulance | -- Set Ambulance blue color and license plate text | ||
SetVehicleColor(vehicle, RGB(0.0, 60.0, 240.0)) | SetVehicleColor(vehicle, RGB(0.0, 60.0, 240.0)) | ||
SetVehicleLicensePlate(vehicle, "EMS-02") | SetVehicleLicensePlate(vehicle, "EMS-02") | ||
end | end | ||
-- Set us in the driver seat | |||
SetPlayerInVehicle(player, vehicle) | SetPlayerInVehicle(player, vehicle) | ||
Line 54: | Line 48: | ||
AddCommand("v", cmd_v) | AddCommand("v", cmd_v) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{RelatedFunctions}} | |||
{{VehicleFunctions}} |
Latest revision as of 10:58, 4 November 2020
Description
This function creates a vehicle at a desired location. Vehicles automatically respawn after 5 minutes. Use SetVehicleRespawnParams to control this behavior.
Syntax
CreateVehicle(modelid, x, y, z [, heading])
Parameters
- modelid
The model identifier for which vehicle to spawn. - x, y, z
The location/coordinates of where this vehicle is going to spawn. - heading (optional)
The direction (yaw axis) in which this vehicle is going to be positioned.
Return Value
- Returns an identifier to the new vehicle. false on error.
Example
function cmd_v(player, model)
if (model == nil) then
return AddPlayerChat(player, "Usage: /v <model>")
end
model = tonumber(model)
local x, y, z = GetPlayerLocation(player)
local h = GetPlayerHeading(player)
local vehicle = CreateVehicle(model, x, y, z, h)
if (vehicle == false) then
return AddPlayerChat(player, "Failed to spawn your vehicle")
end
SetVehicleLicensePlate(vehicle, "ONSET")
AttachVehicleNitro(vehicle, true)
if (model == 8) then
-- Set Ambulance blue color and license plate text
SetVehicleColor(vehicle, RGB(0.0, 60.0, 240.0))
SetVehicleLicensePlate(vehicle, "EMS-02")
end
-- Set us in the driver seat
SetPlayerInVehicle(player, vehicle)
AddPlayerChat(player, "Vehicle spawned! (New ID: "..vehicle..")")
end
AddCommand("v", cmd_v)
See also
- CreateVehicle
- DestroyVehicle
- IsValidVehicle
- GetVehicleCount
- GetAllVehicles
- GetVehicleModel
- GetVehicleModelName
- SetVehicleRespawnParams
- IsVehicleStreamedIn
- GetStreamedVehiclesForPlayer
- GetStreamedVehicles
- SetVehicleLocation
- GetVehicleLocation
- SetVehicleRotation
- GetVehicleRotation
- SetVehicleHeading
- GetVehicleHeading
- SetVehicleHealth
- GetVehicleHealth
- SetVehicleLicensePlate
- GetVehicleVelocity
- GetVehicleDriver
- GetVehiclePassenger
- GetVehicleNumberOfSeats
- SetVehicleColor
- GetVehicleColor
- SetVehicleLinearVelocity
- SetVehicleAngularVelocity
- GetVehicleGear
- SetVehicleHoodRatio
- GetVehicleHoodRatio
- SetVehicleTrunkRatio
- GetVehicleTrunkRatio
- StartVehicleEngine
- StopVehicleEngine
- GetVehicleEngineState
- SetVehicleLightEnabled
- GetVehicleLightState
- SetVehicleDamage
- GetVehicleDamage
- AttachVehicleNitro