Difference between revisions of "HandlingSetABS"

From Multi Theft Auto: Wiki
Jump to: navigation, search
(Example)
(Example)
Line 18: Line 18:
 
==Example==
 
==Example==
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function turnABS(thePlayer)
+
function turnABS(thePlayer)
local theVehicle = getPedOccupiedVehicle(thePlayer) -- Get thePlayer vehicle
+
local theVehicle = getPedOccupiedVehicle(thePlayer) -- Get thePlayer vehicle
if not theVehicle then return end -- if the player is not in the vehicle then cancel
+
if not theVehicle then return end -- if the player is not in the vehicle then cancel
local ABS = getVehicleHandlingProperty(theVehicle,"ABS") -- We will use the additional function that you will find under this one. That will be more convenient.
+
local ABS = getVehicleHandlingProperty(theVehicle,"ABS") -- We will use the additional function that you will find under this one. That will be more convenient.
if ABS == true then -- Check, if ABS is turn on then turn its off.
+
if ABS == true then -- Check, if ABS is turn on then turn its off.
setVehicleHandling(theVehicle,"ABS",false)
+
setVehicleHandling(theVehicle,"ABS",false)
outputChatBox("You turn off ABS")
+
outputChatBox("You turn off ABS")
else -- ABS is off. Turn on this.
+
else -- ABS is off. Turn on this.
setVehicleHandling(theVehicle,"ABS",true)
+
setVehicleHandling(theVehicle,"ABS",true)
outputChatBox("You turn on ABS")
+
outputChatBox("You turn on ABS")
end
 
 
end
 
end
 +
end
 
addCommandHandler("ABS",turnABS)
 
addCommandHandler("ABS",turnABS)
 
 
Line 44: Line 44:
 
     return false -- Not an element, not a vehicle or no valid property string. Return failure
 
     return false -- Not an element, not a vehicle or no valid property string. Return failure
 
end
 
end
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
==See Also==
 
==See Also==
 
{{Handling_functions}}
 
{{Handling_functions}}

Revision as of 09:18, 9 April 2018

Accessories-text-editor.png Script Example Missing Function HandlingSetABS needs a script example, help out by writing one.

Before submitting check out Editing Guidelines Script Examples.

Turns ABS on or off for a handling element.

Syntax

bool handlingSetABS ( handling theHandling, bool ABS )

Required Arguments

  • theHandling: the handling of which you want to toggle the ABS.
  • ABS: true to turn ABS on, false to turn it off.

Returns

Returns true on success, false in case of failure.

Example

	function turnABS(thePlayer)
		local theVehicle = getPedOccupiedVehicle(thePlayer) -- Get thePlayer vehicle
		if not theVehicle then return end -- if the player is not in the vehicle then cancel
			local ABS = getVehicleHandlingProperty(theVehicle,"ABS") -- We will use the additional function that you will find under this one. That will be more convenient.
			if ABS == true then -- Check, if ABS is turn on then turn its off.
				setVehicleHandling(theVehicle,"ABS",false)
				outputChatBox("You turn off ABS")
			else -- ABS is off. Turn on this.
		setVehicleHandling(theVehicle,"ABS",true)
		outputChatBox("You turn on ABS")
	end
end
	addCommandHandler("ABS",turnABS)
	
	function getVehicleHandlingProperty ( element, property )
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string
        local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable
        local value = handlingTable[property] -- Get the value from the table
        
        if value then -- If there's a value (valid property) 
			return value -- Return it
        end
    end
    
    return false -- Not an element, not a vehicle or no valid property string. Return failure
end

See Also