Entity::freezePosition: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(3 intermediate revisions by 2 users 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">entity.freezePosition(toggle);</syntaxhighlight>
=== Required Arguments ===
*'''toggle:''' Boolean
===Return value===
*'''Undefined'''
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// Freeze player position on pressing F2 key
// Function to freeze the player's position
let freeze = false;
function freezePlayerPosition(toggle) {
mp.keys.bind(0x71, true, function() {
    let player = mp.players.local; // Reference to the local player
     freeze = !freeze;
    player.freezePosition(toggle); // Freeze or unfreeze the player's position
     mp.players.local.freezePosition(freeze);
    mp.gui.chat.push("Your position " + (toggle ? "frozen" : "unfrozen") + ".");
     mp.gui.chat.push(`FreezePosition status: ${freeze}`);
}
 
// 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_function_c}}
{{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



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