Skip to main content

Entity::freezePosition

Client-side function

JavaScript​

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.");
}
});