CreateVehicle: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
== Syntax == | == Syntax == | ||
<syntaxhighlight lang="Lua"> | <syntaxhighlight lang="Lua"> | ||
CreateVehicle(modelid, x, y, z [, heading]) | CreateVehicle(modelid, x, y, z [, heading]) | ||
Line 6: | Line 5: | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | <syntaxhighlight lang="Lua"> | ||
function cmd_v(player, model) | function cmd_v(player, model) |
Revision as of 10:32, 23 February 2019
Syntax
CreateVehicle(modelid, x, y, z [, heading])
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
if (PlayerData[player].vehicle ~= 0) then
DestroyVehicle(PlayerData[player].vehicle)
PlayerData[player].vehicle = 0
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
PlayerData[player].vehicle = vehicle
-- Do not change color of the taxi or police car
if (model ~= 2 and model ~= 3) then
--local color = RGB(math.random(1, 220), math.random(1, 220), math.random(1, 220))
--SetVehicleColor(vehicle, NiceColors[ math.random( #NiceColors ) ])
end
SetVehicleLicensePlate(vehicle, "HORIZON")
AttachVehicleNitro(vehicle, true)
if (model == 8) then
-- Ambulance
SetVehicleColor(vehicle, RGB(0.0, 60.0, 240.0))
SetVehicleLicensePlate(vehicle, "EMS-02")
end
SetPlayerInVehicle(player, vehicle)
AddPlayerChat(player, "Vehicle spawned! (New ID: "..vehicle..")")
end
AddCommand("v", cmd_v)