Object::getClosestObjectOfType: Difference between revisions

From RAGE Multiplayer Wiki
m (Edited my Example due to some formating mistakes and some wrong code)
m (Example: forgot to define player)
Line 16: Line 16:
I use it for interaction with objects of type. E.g. atms, vending machines, bins, etc...
I use it for interaction with objects of type. E.g. atms, vending machines, bins, etc...
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
const player = mp.players.local;
// atms
// atms
// There are four different types of atms, so I will create this array with hashes of them
// There are four different types of atms, so I will create this array with hashes of them

Revision as of 03:28, 1 July 2021

Has 8 params in the latest patches.

isMission - if true doesn't return mission objects

Syntax

mp.game.object.getClosestObjectOfType(x, y, z, radius, modelHash, isMission, p6, p7);

Required Arguments

  • x: float
  • y: float
  • z: float
  • radius: float
  • modelHash: Model hash or name
  • isMission: Boolean
  • p6: Boolean
  • p7: Boolean

Return value

  • Object handle

Example

I use it for interaction with objects of type. E.g. atms, vending machines, bins, etc...

const player = mp.players.local;
// atms
// There are four different types of atms, so I will create this array with hashes of them
atms = [
mp.game.joaat("prop_atm_01"), 
mp.game.joaat("prop_atm_02"),
mp.game.joaat("prop_atm_03"),
mp.game.joaat("prop_fleeca_atm")
];
// I need a range. I make this variable to ease any configuration
var atmRange = 1.5;
nextToAtm = function(player) {
    // We want to iterate over every type of atm
    atms.forEach(atmHash => {
        // any atm withing range our check object, or nothing
        var check = mp.game.object.getClosestObjectOfType(player.position.x, player.position.y, player.position.z, atmRange, atmHash, false, true, true);
        // object -> true, nothing -> false
        if (check) {
            object = check;
            return true;
        }
    });
    // If none of the types of atms is in reach, we'll return false
    return false;
}

See also

  • [[Object::disableGlow|mp.game.object.disableGlow