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:
[1] Able to check the nearest enemy and return the event's id.
[2] Able to list down a list of enemy event's ids and their distance from the player.
[3] Able to check any event's distance from player.
How to Use:
[1] Script itself is plug and play, simply paste it below Material and above Main.
[2] To make an event scan-able by the radar, you will need to add
<enemy> tag to the event's name.
[3] Script calls for scanning:
Spoiler
Get 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: [0001] = 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:# [1] Put this script below Material and above Main# [2] Put this name tag on events you want to scan: <enemy># [3] Use Script Calls "nearest" to get the nearest enemy#==============================================================================class Game_Map def distance_from(id) $game_player.distance_x_from($game_map.events[id].x).abs + $game_player.distance_y_from($game_map.events[id].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[meowtarget] = meowscan end end meowradar end def scan_nearest scan_target.min_by{|k,v| v}[0] 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/