GetVehicleEntryPoints: Difference between revisions
Jump to navigation
Jump to search
Megadreams (talk | contribs) (Added note explaining that vehicle needs to be streamed in) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 22: | Line 22: | ||
==Example== | ==Example== | ||
'''Example 1''': This example renders 3D (''text & circle'') on each '''streamed-in''' vehicle entry point | |||
<syntaxhighlight lang="lua"> | |||
addEventHandler("onClientRender", root, function() | |||
for _, vehicle in pairs(getElementsByType("vehicle", root, true)) do | |||
local entryX, entryY, entryZ = getElementPosition(vehicle) | |||
for index, position in pairs(getVehicleEntryPoints(vehicle)) do | |||
local drawX, drawY, distance = getScreenFromWorldPosition( | |||
position[1], position[2], position[3], 100 | |||
) | |||
if (drawX ~= false) then | |||
local cameraX, cameraY, cameraZ = getCameraMatrix() | |||
dxDrawCircle(drawX, drawY, 8 / (distance * 0.1), 0, 360, tocolor(255, 0, 0, 255)) | |||
dxDrawText(tostring(index), drawX, drawY + ((8 / (distance * 0.1)) / 2) + ((2 / (distance * 0.1)) + 0.5), 0, 0, tocolor(255, 0, 0, 255), | |||
3 / (distance * 0.1), "default-bold") | |||
end | |||
end | |||
end | |||
end) | |||
</syntaxhighlight> | |||
'''Example 2''': This example checks if the player is near the vehicle door to ''enter'' | |||
<syntaxhighlight lang="lua"> | |||
addEventHandler("onClientVehicleStartEnter", root, function(thePlayer, seat, door) | |||
if thePlayer == localPlayer then | |||
local entryPoints = getVehicleEntryPoints(source) | |||
if entryPoints then | |||
local entryPoint = entryPoints[door + 1] | |||
if entryPoint then | |||
local distance = getDistanceBetweenPoints3D(Vector3(getElementPosition(localPlayer)), unpack(entryPoint)) | |||
if distance > 2.5 then | |||
outputChatBox("You are too far away from the door to enter this vehicle!") | |||
cancelEvent() | |||
end | |||
end | |||
end | |||
end | |||
end) | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{Client vehicle functions}} | {{Client vehicle functions}} |
Revision as of 15:14, 1 August 2024
Syntax
table getVehicleEntryPoints(vehicle)
OOP Syntax Help! I don't understand this!
- Method: vehicle:getEntryPoints(...)
Required arguments
- vehicle: The vehicle from which we want to get entry points.
Returns
If the vehicle has entry points, it returns a table containing the positions of the 4 possible entry points to the vehicle, otherwise it returns false.
Example
Example 1: This example renders 3D (text & circle) on each streamed-in vehicle entry point
addEventHandler("onClientRender", root, function() for _, vehicle in pairs(getElementsByType("vehicle", root, true)) do local entryX, entryY, entryZ = getElementPosition(vehicle) for index, position in pairs(getVehicleEntryPoints(vehicle)) do local drawX, drawY, distance = getScreenFromWorldPosition( position[1], position[2], position[3], 100 ) if (drawX ~= false) then local cameraX, cameraY, cameraZ = getCameraMatrix() dxDrawCircle(drawX, drawY, 8 / (distance * 0.1), 0, 360, tocolor(255, 0, 0, 255)) dxDrawText(tostring(index), drawX, drawY + ((8 / (distance * 0.1)) / 2) + ((2 / (distance * 0.1)) + 0.5), 0, 0, tocolor(255, 0, 0, 255), 3 / (distance * 0.1), "default-bold") end end end end)
Example 2: This example checks if the player is near the vehicle door to enter
addEventHandler("onClientVehicleStartEnter", root, function(thePlayer, seat, door) if thePlayer == localPlayer then local entryPoints = getVehicleEntryPoints(source) if entryPoints then local entryPoint = entryPoints[door + 1] if entryPoint then local distance = getDistanceBetweenPoints3D(Vector3(getElementPosition(localPlayer)), unpack(entryPoint)) if distance > 2.5 then outputChatBox("You are too far away from the door to enter this vehicle!") cancelEvent() end end end end end)
See Also
- areVehicleLightsOn
- getHeliBladeCollisionsEnabled
- getHelicopterRotorSpeed
- getVehicleAdjustableProperty
- getVehicleComponentPosition
- getVehicleComponentRotation
- getVehicleComponents
- getVehicleComponentScale
- getVehicleComponentVisible
- getVehicleCurrentGear
- getVehicleDummyPosition
- getVehicleGravity
- getVehicleLandingGearDown
- getVehicleModelDummyDefaultPosition
- getVehicleModelDummyPosition
- getVehicleModelExhaustFumesPosition
- getVehicleModelWheelSize
- getVehicleNitroCount
- getVehicleNitroLevel
- getVehicleWheelFrictionState
- getVehicleWheelScale
- isTrainChainEngine
- isVehicleNitroActivated
- isVehicleNitroRecharging
- isVehicleOnGround
- isVehicleWheelOnGround
- isVehicleWindowOpen
- resetVehicleComponentPosition
- resetVehicleComponentRotation
- resetVehicleComponentScale
- resetVehicleDummyPositions
- setHeliBladeCollisionsEnabled
- setHelicopterRotorSpeed
- setVehicleAdjustableProperty
- setVehicleComponentPosition
- setVehicleComponentRotation
- setVehicleComponentScale
- setVehicleComponentVisible
- setVehicleDummyPosition
- setVehicleGravity
- setVehicleLandingGearDown
- setVehicleModelDummyPosition
- setVehicleModelExhaustFumesPosition
- setVehicleModelWheelSize
- setVehicleNitroActivated
- setVehicleNitroCount
- setVehicleNitroLevel
- setVehicleWheelScale
- setVehicleWheelStates
- setVehicleWindowOpen
- Shared
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates