IsPedInVehicle: Difference between revisions
Jump to navigation
Jump to search
(New page: __NOTOC__ {{Client function}} Checks whether or not a given ped is currently in a vehicle. ==Syntax== <syntaxhighlight lang="lua"> bool isPedInVehicle ( ped thePed ) </syntaxhighlight> ===Required Arguments=== *''...) |
Zangomangu (talk | contribs) (Changed note to explain differences in client/server version) |
||
(11 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{ | {{Server client function}} | ||
Checks whether or not a given ped is currently in a vehicle. | Checks whether or not a given ped is currently in a vehicle. | ||
{{Note|1=Client side [[IsPedInVehicle]] only returns ''true'' if the ped is physically inside a vehicle. To check if the ped is entering or exiting a vehicle, use: <code>[[getPedOccupiedVehicle]](ped) ~= false</code> }} | |||
{{Note|1=Server side [[IsPedInVehicle]] returns whether the ped is entering, inside or exiting a vehicle. }} | |||
==Syntax== | ==Syntax== | ||
Line 8: | Line 10: | ||
bool isPedInVehicle ( ped thePed ) | bool isPedInVehicle ( ped thePed ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[ped]]:isInVehicle|inVehicle}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 14: | Line 17: | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if the ped is in a vehicle, ''false'' if he is on foot or an invalid element was passed. | Returns ''true'' if the ped is in a vehicle, ''false'' if he is on foot or an invalid element was passed. | ||
==Example== | |||
This code defines an ''isinvehicle'' command which tells a player whether another player is in a vehicle or not. | |||
<syntaxhighlight lang="lua"> | |||
-- we create our handler function, where sourcePlayer is the player who sent the command, | |||
-- and checkedPlayerName is the player name specified. | |||
function outputIsInVehicle ( sourcePlayer, commandName, checkedPlayerName ) | |||
-- we get the player element from the nick specified | |||
local checkedPlayer = getPlayerFromName ( checkedPlayerName ) | |||
-- if there exists a player with that nick | |||
if ( checkedPlayer ) then | |||
-- if he's in a vehicle, | |||
if isPedInVehicle ( checkedPlayer ) then | |||
-- tell the source player | |||
outputChatBox ( checkedPlayerName .. " is in a vehicle.", sourcePlayer ) | |||
-- if he's not in a vehicle, | |||
else | |||
-- tell the source player | |||
outputChatBox ( checkedPlayerName .. " is not in a vehicle.", sourcePlayer ) | |||
end | |||
-- if it doesn't exist, | |||
else | |||
-- tell the source player | |||
outputChatBox ( "Invalid player name.", sourcePlayer ) | |||
end | |||
end | |||
-- define a handler for the isinvehicle command | |||
addCommandHandler ( "isinvehicle", outputIsInVehicle ) | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{Client_ped_functions}} | {{Client_ped_functions}} |
Latest revision as of 20:49, 11 April 2021
Checks whether or not a given ped is currently in a vehicle.
Syntax
bool isPedInVehicle ( ped thePed )
OOP Syntax Help! I don't understand this!
- Method: ped:isInVehicle(...)
- Variable: .inVehicle
Required Arguments
- thePed: the ped you want to check.
Returns
Returns true if the ped is in a vehicle, false if he is on foot or an invalid element was passed.
Example
This code defines an isinvehicle command which tells a player whether another player is in a vehicle or not.
-- we create our handler function, where sourcePlayer is the player who sent the command, -- and checkedPlayerName is the player name specified. function outputIsInVehicle ( sourcePlayer, commandName, checkedPlayerName ) -- we get the player element from the nick specified local checkedPlayer = getPlayerFromName ( checkedPlayerName ) -- if there exists a player with that nick if ( checkedPlayer ) then -- if he's in a vehicle, if isPedInVehicle ( checkedPlayer ) then -- tell the source player outputChatBox ( checkedPlayerName .. " is in a vehicle.", sourcePlayer ) -- if he's not in a vehicle, else -- tell the source player outputChatBox ( checkedPlayerName .. " is not in a vehicle.", sourcePlayer ) end -- if it doesn't exist, else -- tell the source player outputChatBox ( "Invalid player name.", sourcePlayer ) end end -- define a handler for the isinvehicle command addCommandHandler ( "isinvehicle", outputIsInVehicle )
See Also
- canPedBeKnockedOffBike
- getPedAnalogControlState
- getPedAnimation
- getPedBonePosition
- getPedCameraRotation
- getPedControlState
- getPedMoveState
- getPedOxygenLevel
- getPedSimplestTask
- getPedTargetCollision
- getPedTargetEnd
- getPedTargetStart
- getPedTask
- getPedVoice
- getPedWeaponMuzzlePosition
- givePedWeapon
- isPedBleeding
- isPedDoingTask
- isPedReloadingWeapon
- isPedTargetingMarkerEnabled
- setAnalogControlState
- setPedAimTarget
- setPedAnalogControlState
- setPedBleeding
- setPedCameraRotation
- setPedCanBeKnockedOffBike
- setPedControlState
- setPedEnterVehicle
- setPedExitVehicle
- IsPedFootBloodEnabled
- setPedFootBloodEnabled
- setPedLookAt
- setPedOxygenLevel
- setPedTargetingMarkerEnabled
- setPedVoice
- Shared
- addPedClothes
- getPedClothes
- removePedClothes
- createPed
- getPedAmmoInClip
- getPedArmor
- getPedFightingStyle
- getPedOccupiedVehicle
- getPedOccupiedVehicleSeat
- getPedStat
- getPedTarget
- getPedTotalAmmo
- getPedWalkingStyle
- getPedWeapon
- getPedWeaponSlot
- getPedContactElement
- getValidPedModels
- isPedChoking
- isPedDead
- isPedDoingGangDriveby
- isPedDucked
- isPedHeadless
- isPedInVehicle
- isPedOnFire
- isPedOnGround
- isPedWearingJetpack
- killPed
- removePedFromVehicle
- setPedAnimation
- setPedAnimationProgress
- setPedAnimationSpeed
- setPedArmor
- setPedDoingGangDriveby
- setPedFightingStyle
- setPedHeadless
- setPedOnFire
- setPedStat
- setPedWalkingStyle
- setPedWeaponSlot
- warpPedIntoVehicle