SetVehicleTrunkRatio: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetVehicleTrunkRatio(vehicle, openRatio)}} {{FuncParameters}} {{FuncParam|vehicle|__EDIT_ME__}} {{..."
 
28days (talk | contribs)
No edit summary
 
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Set the vehicle's trunk ratio.}}


{{FuncSyntax|SetVehicleTrunkRatio(vehicle, openRatio)}}
{{FuncSyntax|SetVehicleTrunkRatio(vehicle, openRatio)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|__EDIT_ME__}}
{{FuncParam|vehicle|The vehicle identifier.}}
{{FuncParam|openRatio|__EDIT_ME__}}
{{FuncParam|openRatio|The open ratio in floating point.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|This function does not return anything.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua>
function cmd_trunk(player, ratio)
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
 
if (ratio == nil) then
if (GetVehicleTrunkRatio(vehicle) > 0.0) then
SetVehicleTrunkRatio(vehicle, 0.0)
else
SetVehicleTrunkRatio(vehicle, 60.0)
end
else
ratio = tonumber(ratio)
 
if (ratio > 90.0) then
ratio = 90.0
elseif (ratio < 0.0) then
ratio = 0.0
end
 
SetVehicleTrunkRatio(vehicle, ratio)
end
end
AddCommand("trunk", cmd_trunk)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{Template:VehicleFunctions}}

Latest revision as of 15:31, 19 November 2019

SetVehicleTrunkRatio

Type: Function
Context: Server
Introduced: v1.0

Description

Set the vehicle's trunk ratio.

Syntax

SetVehicleTrunkRatio(vehicle, openRatio)

Parameters

  • vehicle
    The vehicle identifier.
  • openRatio
    The open ratio in floating point.

Return Value

  • This function does not return anything.

Example

function cmd_trunk(player, ratio)
	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

	if (ratio == nil) then
		if (GetVehicleTrunkRatio(vehicle) > 0.0) then
			SetVehicleTrunkRatio(vehicle, 0.0)
		else
			SetVehicleTrunkRatio(vehicle, 60.0)
		end
	else
		ratio = tonumber(ratio)

		if (ratio > 90.0) then
			ratio = 90.0
		elseif (ratio < 0.0) then
			ratio = 0.0
		end

		SetVehicleTrunkRatio(vehicle, ratio)
	end
end
AddCommand("trunk", cmd_trunk)

See also