SetVehicleHealth: Difference between revisions

From Onset Developer Wiki
28days (talk | contribs)
No edit summary
m Corrected the 5.000 to 5000
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|Set the specified health for the specified vehicle.}}
{{FuncDescription|Set the specified health for the specified vehicle. The default health is '''5000'''}}


{{FuncSyntax|SetVehicleHealth(vehicle, health)}}
{{FuncSyntax|SetVehicleHealth(vehicle, health)}}
Line 7: Line 7:
{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|The vehicle identifier}}
{{FuncParam|vehicle|The vehicle identifier}}
{{FuncParam|health|The vehicle health in float value between 0 to 5000.}}
{{FuncParam|health|The vehicle health in float value between 0 to 10000.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|This function '''true''' on success.}}


== Example ==
== Example ==
Line 21: Line 21:
health = tonumber(health)
health = tonumber(health)


if (health == nil or health < 0.0 or health > 5000.0) then
if (health == nil or health < 0.0 or health > 10000.0) then
return AddPlayerChat(player, "Parameter \"health\" 0.0-5000.0")
return AddPlayerChat(player, "Parameter \"health\" 0.0-10000.0")
end
end



Latest revision as of 20:32, 4 January 2022

SetVehicleHealth

Type: Function
Context: Server
Introduced: v1.0

Description

Set the specified health for the specified vehicle. The default health is 5000

Syntax

SetVehicleHealth(vehicle, health)

Parameters

  • vehicle
    The vehicle identifier
  • health
    The vehicle health in float value between 0 to 10000.

Return Value

  • This function true on success.

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 > 10000.0) then
		return AddPlayerChat(player, "Parameter \"health\" 0.0-10000.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