CreateVehicle: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
if (model < 1 or model > 12) then | if (model < 1 or model > 12) then | ||
return AddPlayerChat(player, "Vehicle model "..model.." does not exist.") | return AddPlayerChat(player, "Vehicle model "..model.." does not exist.") | ||
end | end | ||
Line 35: | Line 30: | ||
if (vehicle == false) then | if (vehicle == false) then | ||
return AddPlayerChat(player, "Failed to spawn your vehicle") | return AddPlayerChat(player, "Failed to spawn your vehicle") | ||
end | end | ||
Line 49: | Line 36: | ||
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) | ||
Revision as of 15:00, 24 February 2019
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: The direction 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)
if (model < 1 or model > 12) then
return AddPlayerChat(player, "Vehicle model "..model.." does not exist.")
end
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, "HORIZON")
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)