Entity::freezePosition: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
Line 14: Line 14:
     let player = mp.players.local; // Reference to the local player
     let player = mp.players.local; // Reference to the local player
     player.freezePosition(toggle); // Freeze or unfreeze the player's position
     player.freezePosition(toggle); // Freeze or unfreeze the player's position
     mp.gui.chat.push("Player position " + (toggle ? "frozen" : "unfrozen") + ".");
     mp.gui.chat.push("Your position " + (toggle ? "frozen" : "unfrozen") + ".");
}
}


// Bind the function to the "E" key
// 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"
mp.keys.bind(69, false, function() { // 69 is the key code for "E"
     let player = mp.players.local; // Reference to the local player
     let player = mp.players.local; // Reference to the local player
     // Check if the player is currently frozen
     let isFrozen = player.isPositionFrozen; // Check if the player's position is currently frozen
    let isFrozen = player.isPositionFrozen;
     freezePlayerPosition(!isFrozen); // Toggle freeze state
     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>

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