じ☆ve冰风 发表于 2026-8-2 17:53:12

Enemy Distance Scanner (Radar)

Made for a request here.

This script acts like a radar/scanner to check the distance of the player from the enemy events on the map.

Features:

Able to check the nearest enemy and return the event's id.

Able to list down a list of enemy event's ids and their distance from the player.

Able to check any event's distance from player.

How to Use:

Script itself is plug and play, simply paste it below Material and above Main.

To make an event scan-able by the radar, you will need to add <enemy> tag to the event's name.

      http://s30.postimg.org/79ddzbvhp/enemytag.png

Script calls for scanning:

SpoilerGet distance value of Event X from Player

$game_map.distance_from(id)id = any event's id (works for event without name tag)

Get distance of all Enemies from Player

$game_map.scan_targetThis will list all the enemy event's id and their distance from the player

Get the nearest enemy event's id

nearest_enemythis will return the event's id of the nearest enemy



Pair these with Control Variables' Script box to output the result to game variable.

eg. Control Variables: = nearest_enemy

Compatibility:

Should be compatible with other custom scripts.

Terms of Use:

Free for both Commercial and Non-commercial

Script:

Spoiler                Code:       
#==============================================================================# ■ Meow Face Enemy Scanner#------------------------------------------------------------------------------# Return the ID of the nearest Event (from player position)#==============================================================================# How to Use:# Put this script below Material and above Main# Put this name tag on events you want to scan: <enemy># Use Script Calls "nearest" to get the nearest enemy#==============================================================================class Game_Map  def distance_from(id)    $game_player.distance_x_from($game_map.events.x).abs + $game_player.distance_y_from($game_map.events.y).abs  end  def scan_target    meowradar = {}    @events.values.each do |meow|      if meow.enemy?        meowscan = distance_from(meow.id)        meowtarget = (meow.id).to_s        meowradar = meowscan      end    end    meowradar  end  def scan_nearest    scan_target.min_by{|k,v| v} if !scan_target.empty?  endendclass Game_Event < Game_Character  def enemy?    @event.name.include?('<enemy>')  endendclass Game_Interpreter  def nearest_enemy    $game_map.scan_nearest  endend








本贴来自国际rpgmaker官方论坛作者:MeowFace处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/enemy-distance-scanner-radar.46115/
页: [1]
查看完整版本: Enemy Distance Scanner (Radar)