Object::getClosestObjectOfType: Difference between revisions

From RAGE Multiplayer Wiki
(returns object handle not object)
(Example added)
Line 14: Line 14:
*'''Object handle'''
*'''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
// atms
// There are four different types of atms, so I will create this array with hashes of them
nextToAtm = function(player) {
    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;
    // 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;
}
</syntaxhighlight>
</syntaxhighlight>
==See also==
==See also==
{{Object_s_function_c}}
{{Object_s_function_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]
[[Category:TODO: Example]]

Revision as of 02:59, 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...

// atms
// There are four different types of atms, so I will create this array with hashes of them
nextToAtm = function(player) {
    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;
    // 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