Object::getClosestObjectOfType: Difference between revisions

From RAGE Multiplayer Wiki
(yay)
 
(→‎Example: should work now, apparently, forEach messes with return...)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Has 8 params in the latest patches.<br><br>isMission - if true doesn't return mission objects
Has 8 params in the latest patches.<br><br>isMission - if true doesn't return mission objects
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">object.getClosestObjectOfType(x, y, z, radius, modelHash, isMission, p6, p7);</syntaxhighlight>
<syntaxhighlight lang="javascript">mp.game.object.getClosestObjectOfType(x, y, z, radius, modelHash, isMission, p6, p7);</syntaxhighlight>
=== Required Arguments ===
=== Required Arguments ===
*'''x:''' float
*'''x:''' float
Line 12: Line 12:
*'''p7:''' Boolean
*'''p7:''' Boolean
===Return value===
===Return value===
*'''Object handle or object'''
*'''Object handle'''
==Example==
==Example==
I use it for interaction with objects of type. E.g. atms, vending machines, bins, etc...
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
todo
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
    for (let i = 0; i < atms.length; i++) {
        const atmHash = atms[i];
        // 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) {
            return true;
        }
    });
    // If none of the types of atms is in reach, we'll return false
    return false;
}
</syntaxhighlight>
</syntaxhighlight>
==See also==
==See also==
{{Object_function_c}}
{{Object_s_function_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]
[[Category:TODO: Example]]

Latest revision as of 15:25, 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
    for (let i = 0; i < atms.length; i++) {
        const atmHash = atms[i];
        // 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) {
            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