Entity::freezePosition: Difference between revisions
No edit summary |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{ClientsideJsFunction}} | |||
{{JSContainer| | |||
===Required Params=== | |||
*'''toggle:''' {{RageType|boolean}} — A boolean value indicating whether to freeze (true) or unfreeze (false) the entity's position. | |||
===Return value=== | |||
*'''void''' — This function does not return a value. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
// Freeze player position | // Function to freeze the player's position | ||
let | function freezePlayerPosition(toggle) { | ||
mp.keys.bind( | let player = mp.players.local; // Reference to the local player | ||
player.freezePosition(toggle); // Freeze or unfreeze the player's position | |||
mp.players. | mp.gui.chat.push("Your position " + (toggle ? "frozen" : "unfrozen") + "."); | ||
mp.gui.chat.push( | } | ||
// Function to freeze the player's position by ID | |||
function freezePlayerPositionById(playerId, toggle) { | |||
let player = mp.players.at(playerId); // Get the player by ID | |||
if (player) { // Check if the player exists | |||
player.freezePosition(toggle); // Freeze or unfreeze the player's position | |||
mp.gui.chat.push("Player ID " + playerId + " position " + (toggle ? "frozen" : "unfrozen") + "."); | |||
} else { | |||
mp.gui.chat.push("Player with ID " + playerId + " not found."); | |||
} | |||
} | |||
// Bind the function to the "E" key (freeze/unfreeze self) | |||
mp.keys.bind(69, false, function() { // 69 is the key code for "E" | |||
let player = mp.players.local; // Reference to the local player | |||
let isFrozen = player.isPositionFrozen; // Check if the player's position is currently frozen | |||
freezePlayerPosition(!isFrozen); // Toggle freeze state | |||
}); | |||
// Bind the function to the "X" key (freeze/unfreeze player by ID) | |||
mp.keys.bind(88, false, function() { // 88 is the key code for "X" | |||
let playerId = 0; // Set the player ID to 0 (you can change this to any ID) | |||
let player = mp.players.at(playerId); // Get the player by ID | |||
if (player) { // Check if the player exists | |||
let isFrozen = player.isPositionFrozen; // Check if the player's position is currently frozen | |||
freezePlayerPositionById(playerId, !isFrozen); // Toggle freeze state | |||
} else { | |||
mp.gui.chat.push("Player with ID " + playerId + " not found."); | |||
} | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
==See also== | ==See also== | ||
{{ | {{Entity_functions_c}} | ||
[[Category:Clientside API]] | [[Category:Clientside API]] | ||
[[Category:TODO: Example]] | [[Category:TODO: Example]] | ||
Latest revision as of 22:18, 6 October 2024
Client-Side Function
JavaScript Syntax
Required Params
- toggle: boolean — A boolean value indicating whether to freeze (true) or unfreeze (false) the entity's position.
Return value
- void — This function does not return a value.
Syntax
// Function to freeze the player's position
function freezePlayerPosition(toggle) {
let player = mp.players.local; // Reference to the local player
player.freezePosition(toggle); // Freeze or unfreeze the player's position
mp.gui.chat.push("Your position " + (toggle ? "frozen" : "unfrozen") + ".");
}
// Function to freeze the player's position by ID
function freezePlayerPositionById(playerId, toggle) {
let player = mp.players.at(playerId); // Get the player by ID
if (player) { // Check if the player exists
player.freezePosition(toggle); // Freeze or unfreeze the player's position
mp.gui.chat.push("Player ID " + playerId + " position " + (toggle ? "frozen" : "unfrozen") + ".");
} else {
mp.gui.chat.push("Player with ID " + playerId + " not found.");
}
}
// Bind the function to the "E" key (freeze/unfreeze self)
mp.keys.bind(69, false, function() { // 69 is the key code for "E"
let player = mp.players.local; // Reference to the local player
let isFrozen = player.isPositionFrozen; // Check if the player's position is currently frozen
freezePlayerPosition(!isFrozen); // Toggle freeze state
});
// Bind the function to the "X" key (freeze/unfreeze player by ID)
mp.keys.bind(88, false, function() { // 88 is the key code for "X"
let playerId = 0; // Set the player ID to 0 (you can change this to any ID)
let player = mp.players.at(playerId); // Get the player by ID
if (player) { // Check if the player exists
let isFrozen = player.isPositionFrozen; // Check if the player's position is currently frozen
freezePlayerPositionById(playerId, !isFrozen); // Toggle freeze state
} else {
mp.gui.chat.push("Player with ID " + playerId + " not found.");
}
});
See also
- mp.game.entity.doesExist
- mp.game.entity.doesBelongToThisScript
- mp.game.entity.doesHaveDrawable
- mp.game.entity.doesHavePhysics
- mp.game.entity.hasAnimFinished
- mp.game.entity.hasBeenDamagedByAnyObject
- mp.game.entity.hasBeenDamagedByAnyPed
- mp.game.entity.hasBeenDamagedByAnyVehicle
- mp.game.entity.hasBeenDamagedByEntity
- mp.game.entity.hasClearLosToEntity
- mp.game.entity.hasClearLosToEntity2
- mp.game.entity.hasClearLosToEntityInFront
- mp.game.entity.hasCollidedWithAnything
- mp.game.entity.getLastMaterialHitBy
- mp.game.entity.getCollisionNormalOfLastHitFor
- mp.game.entity.forceAiAndAnimationUpdate
- mp.game.entity.getAnimCurrentTime
- mp.game.entity.getAnimTotalTime
- mp.game.entity.getAnimDuration
- mp.game.entity.getEntityAnimDuration
- mp.game.entity.getAttachedTo
- mp.game.entity.getCoords
- mp.game.entity.getForwardVector
- mp.game.entity.getForwardX
- mp.game.entity.getForwardY
- mp.game.entity.getHeading
- mp.game.entity.getPhysicsHeading
- mp.game.entity.getHealth
- mp.game.entity.getMaxHealth
- mp.game.entity.setMaxHealth
- mp.game.entity.getHeight
- mp.game.entity.getHeightAboveGround
- mp.game.entity.getMatrix
- mp.game.entity.getModel
- mp.game.entity.getOffsetFromGivenWorldCoords
- mp.game.entity.getOffsetFromInWorldCoords
- mp.game.entity.getPitch
- mp.game.entity.getQuaternion
- mp.game.entity.getRoll
- mp.game.entity.getRotation
- mp.game.entity.getRotationVelocity
- mp.game.entity.getScript
- mp.game.entity.getSpeed
- mp.game.entity.getSpeedVector
- mp.game.entity.getUprightValue
- mp.game.entity.getVelocity
- mp.game.entity.getObjectIndexFromIndex
- mp.game.entity.getPedIndexFromIndex
- mp.game.entity.getVehicleIndexFromIndex
- mp.game.entity.getWorldPositionOfBone
- mp.game.entity.getNearestPlayerTo
- mp.game.entity.getNearestPlayerToOnTeam
- mp.game.entity.getType
- mp.game.entity.getPopulationType
- mp.game.entity.isAn
- mp.game.entity.isAnEntity
- mp.game.entity.isAPed
- mp.game.entity.isAMissionEntity
- mp.game.entity.isAVehicle
- mp.game.entity.isAnObject
- mp.game.entity.isAtCoord
- mp.game.entity.isAtEntity
- mp.game.entity.isAttached
- mp.game.entity.isAttachedToAnyObject
- mp.game.entity.isAttachedToAnyPed
- mp.game.entity.isAttachedToAnyVehicle
- mp.game.entity.isAttachedToEntity
- mp.game.entity.isDead
- mp.game.entity.isInAir
- mp.game.entity.isInAngledArea
- mp.game.entity.isInArea
- mp.game.entity.isInZone
- mp.game.entity.isInWater
- mp.game.entity.getSubmergedLevel
- mp.game.entity.isOnScreen
- mp.game.entity.isPlayingAnim
- mp.game.entity.isStatic
- mp.game.entity.isTouchingEntity
- mp.game.entity.isTouchingModel
- mp.game.entity.isUpright
- mp.game.entity.isUpsidedown
- mp.game.entity.isVisible
- mp.game.entity.isVisibleToScript
- mp.game.entity.isOccluded
- mp.game.entity.wouldBeOccluded
- mp.game.entity.wouldEntityBeOccluded
- mp.game.entity.isWaitingForWorldCollision
- mp.game.entity.applyForceToCenterOfMass
- mp.game.entity.applyForceTo
- mp.game.entity.attachToEntity
- mp.game.entity.attachBoneToEntityBone
- mp.game.entity.attachBoneToEntityBonePhysically
- mp.game.entity.attachToEntityPhysically
- mp.game.entity.processAttachments
- mp.game.entity.getBoneIndexByName
- mp.game.entity.clearLastDamageEntity
- mp.game.entity.delete
- mp.game.entity.detach
- mp.game.entity.freezePosition
- mp.game.entity.setCleanupByEngine
- mp.game.entity.playAnim
- mp.game.entity.playSynchronizedAnim
- mp.game.entity.playSynchronizedMapAnim
- mp.game.entity.playSynchronizedMapEntityAnim
- mp.game.entity.stopSynchronizedMapAnim
- mp.game.entity.stopSynchronizedMapEntityAnim
- mp.game.entity.stopAnim
- mp.game.entity.stopSynchronizedAnim
- mp.game.entity.hasAnimEventFired
- mp.game.entity.findAnimEventPhase
- mp.game.entity.setAnimCurrentTime
- mp.game.entity.setAnimSpeed
- mp.game.entity.setAsMissionEntity
- mp.game.entity.setAsNoLongerNeeded
- mp.game.entity.setPedAsNoLongerNeeded
- mp.game.entity.setVehicleAsNoLongerNeeded
- mp.game.entity.setObjectAsNoLongerNeeded
- mp.game.entity.setCanBeDamaged
- mp.game.entity.getCanBeDamaged
- mp.game.entity.setCanBeDamagedByRelationshipGroup
- mp.game.entity.setCanBeTargetedWithoutLos
- mp.game.entity.setCollision
- mp.game.entity.getCollisionDisabled
- mp.game.entity.setCompletelyDisableCollision
- mp.game.entity.setCoords
- mp.game.entity.setCoordsWithoutPlantsReset
- mp.game.entity.setCoordsNoOffset
- mp.game.entity.setDynamic
- mp.game.entity.setHeading
- mp.game.entity.setHealth
- mp.game.entity.setInvincible
- mp.game.entity.setIsTargetPriority
- mp.game.entity.setLights
- mp.game.entity.setLoadCollisionFlag
- mp.game.entity.hasCollisionLoadedAround
- mp.game.entity.setMaxSpeed
- mp.game.entity.setOnlyDamagedByPlayer
- mp.game.entity.setOnlyDamagedByRelationshipGroup
- mp.game.entity.setProofs
- mp.game.entity.getProofs
- mp.game.entity.setQuaternion
- mp.game.entity.setRecordsCollisions
- mp.game.entity.setRotation
- mp.game.entity.setVisible
- mp.game.entity.setVelocity
- mp.game.entity.setAngularVelocity
- mp.game.entity.setHasGravity
- mp.game.entity.setLodDist
- mp.game.entity.getLodDist
- mp.game.entity.setAlpha
- mp.game.entity.getAlpha
- mp.game.entity.resetAlpha
- mp.game.entity.setAlwaysPrerender
- mp.game.entity.setRenderScorched
- mp.game.entity.setTrafficlightOverride
- mp.game.entity.createModelSwap
- mp.game.entity.removeModelSwap
- mp.game.entity.createModelHide
- mp.game.entity.createModelHideExcludingScriptObjects
- mp.game.entity.removeModelHide
- mp.game.entity.createForcedObject
- mp.game.entity.removeForcedObject
- mp.game.entity.setNoCollisionEntity
- mp.game.entity.setMotionBlur
- mp.game.entity.setCanAutoVaultOn
- mp.game.entity.setCanClimbOn
- mp.game.entity.setDecalsDisabled
- mp.game.entity.getBoneRotation
- mp.game.entity.getBonePosition2
- mp.game.entity.getBoneRotationLocal
- mp.game.entity.getBoneCount
- mp.game.entity.enableUnk
- mp.game.entity.getPickup