Перейти к содержанию

Object::getClosestObjectOfType

Материал из RAGE MP Wiki Archive

Has 8 params in the latest patches.

isMission - if true doesn't return mission objects

Syntax

<syntaxhighlight lang="javascript">mp.game.object.getClosestObjectOfType(x, y, z, radius, modelHash, isMission, p6, p7);</syntaxhighlight>

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... <syntaxhighlight lang="javascript"> 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>

See also

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