SetVehicleHealth: Difference between revisions
From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetVehicleHealth(vehicle, health)}} {{FuncParameters}} {{FuncParam|vehicle|__EDIT_ME__}} {{FuncPar..." |
No edit summary |
||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | {{Info|Function|Server|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Set the specified health for the specified vehicle.}} | ||
{{FuncSyntax|SetVehicleHealth(vehicle, health)}} | {{FuncSyntax|SetVehicleHealth(vehicle, health)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|vehicle| | {{FuncParam|vehicle|The vehicle identifier}} | ||
{{FuncParam|health| | {{FuncParam|health|The vehicle health in float value between 0 to 5000.}} | ||
{{FuncReturnValue|__EDIT_ME__}} | {{FuncReturnValue|__EDIT_ME__}} | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | |||
AddCommand("vhealth", function(player, health) | |||
if (health == nil) then | |||
return AddPlayerChat(player, "Usage: /vhealth <health>") | |||
end | |||
health = tonumber(health) | |||
if (health == nil or health < 0.0 or health > 5000.0) then | |||
return AddPlayerChat(player, "Parameter \"health\" 0.0-5000.0") | |||
end | |||
local vehicle = GetPlayerVehicle(player) | |||
if (vehicle == 0) then | |||
return AddPlayerChat(player, "You must be in a vehicle") | |||
end | |||
if (GetPlayerVehicleSeat(player) ~= 1) then | |||
return AddPlayerChat(player, "You must be the driver of the vehicle") | |||
end | |||
local oldhealth = GetVehicleHealth(vehicle) | |||
SetVehicleHealth(vehicle, health) | |||
AddPlayerChat(player, "Old health: "..oldhealth..", new health: "..GetVehicleHealth(vehicle)) | |||
end) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{VehicleFunctions}} |
Revision as of 07:31, 16 November 2019
Description
Set the specified health for the specified vehicle.
Syntax
SetVehicleHealth(vehicle, health)
Parameters
- vehicle
The vehicle identifier - health
The vehicle health in float value between 0 to 5000.
Return Value
- __EDIT_ME__
Example
AddCommand("vhealth", function(player, health)
if (health == nil) then
return AddPlayerChat(player, "Usage: /vhealth <health>")
end
health = tonumber(health)
if (health == nil or health < 0.0 or health > 5000.0) then
return AddPlayerChat(player, "Parameter \"health\" 0.0-5000.0")
end
local vehicle = GetPlayerVehicle(player)
if (vehicle == 0) then
return AddPlayerChat(player, "You must be in a vehicle")
end
if (GetPlayerVehicleSeat(player) ~= 1) then
return AddPlayerChat(player, "You must be the driver of the vehicle")
end
local oldhealth = GetVehicleHealth(vehicle)
SetVehicleHealth(vehicle, health)
AddPlayerChat(player, "Old health: "..oldhealth..", new health: "..GetVehicleHealth(vehicle))
end)
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