get_player_distance - ryzom/ryzomcore GitHub Wiki


title: Get Player Distance description: published: true date: 2023-03-12T23:27:57.218Z tags: editor: markdown dateCreated: 2023-03-12T23:27:54.313Z

getPlayerDistance

The getPlayerDistance native AI script function calculates the distance between a player and a bot in meters.

Syntax

(distance: f)getPlayerDistance(PlayerEidAsString: s, BotIndex: f) // getPlayerDistance_fs_f

Arguments

  • PlayerEidAsString (string): The EntityId of the player, passed as a string.
  • BotIndex (float): The index of the bot, where 0 refers to the first bot in the current group.

Return Value

This function returns the distance between the player and the bot in meters, or -1 if there was an error.

Example

($playerEid)getCurrentPlayerEid(); (index)getBotIndexByName("toto"); (distance)getPlayerDistance($playerEid, index);

This example code gets the EntityId of the current player, gets the index of the bot named "toto", and calculates the distance between the player and the bot.

⚠️ **GitHub.com Fallback** ⚠️