miniet 2 Posted July 15, 2020 (edited) Does anybody knows how to check nearest Event ID from this Event(@event_id)? ex) This Event(1) -> Event(2) is nearest distance from event(1) need to know Event(2)'s ID with script down below or another script can run this. I use meawface's script but it is player based so wanna change "player" part to "this_event". but changing "$game_player" to "$game_map.events[@event_id]" doesn't seem to work. and nametag based searching event ID could be more helpful. attached meawface's full script and link below https://forums.rpgmakerweb.com/index.php?threads/enemy-distance-scanner-radar.46115/ ==================================================================== # ■ Meow Face Enemy Distance 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 this Script Call to get the closest enemy's id (in Control Variables Script box) # closest # eg. # Control Variables 1 = closest #=================================================================== 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? end end class Game_Event < Game_Character def enemy? @event.name.include?('<enemy>') end end class Game_Interpreter def nearest_enemy $game_map.scan_nearest end end Edited July 15, 2020 by miniet Share this post Link to post Share on other sites
PhoenixSoul 1,404 Posted July 17, 2020 Hmmm... I actually don't see how changing that doesn't work as I do not see any Game_Player specific calls in the script (as in calling from the Game_Player class). Maybe...@Kayzee would know a bit more, or mayhaps @roninator2 or @Rikifive? I honestly think that this should also be a 'comment_tag' script, but that's just me. Share this post Link to post Share on other sites
roninator2 257 Posted July 17, 2020 (edited) 39 minutes ago, PhoenixSoul said: or mayhaps @roninator2 Nope. Not going to touch it. I see this outside my expertise. I also see that if you got the $game_map.events(id) to work it might come back and report itself with the comment on it. My only suggestion would be $game_map.events[id of the event that is checking].distance_x_from($game_map.events[id].x).abs + $game_map.events[id of the event that is checking].distance_y_from($game_map.events[id].y).abs But that's a guess and it would need to be run as a script call not part of the script. Edited July 17, 2020 by roninator2 1 Share this post Link to post Share on other sites
roninator2 257 Posted July 19, 2020 On 7/16/2020 at 9:19 PM, PhoenixSoul said: Maybe... would know a bit more @shaz does know more. She gave the answer here https://forums.rpgmakerweb.com/index.php?threads/how-to-check-nearest-event-id-from-this-event.124230/ 1 Share this post Link to post Share on other sites
PhoenixSoul 1,404 Posted July 20, 2020 Hmmm... $game_map.events[id1].distance_x_from($game_map.events[id2].x).abs + $game_map.events[id1].distance_y_from($game_map.events[id2].y).abs This appears to be the same script call that you came up with, Ronin. Share this post Link to post Share on other sites
miniet 2 Posted July 20, 2020 (edited) I've changed script like this $game_map.events[$game_variables[1]].distance_x_from($game_map.events[id].x).abs + $game_map.events[$game_variables[1]].distance_y_from($game_map.events[id].y).abs and in the game for event(1) - self $game_variables[1] == event_id and use script call like below $game_variables[2] == nearest_enemy when playing it, game doesn't crash but i'm not sure this solves the problem perfectly. and Shaz said this formula doesn't get nearest distance. so i'm little bit confused. How to get nearest distance? Is there any other formula? so far changing player to event based is solved i guess. Edited July 20, 2020 by miniet 1 Share this post Link to post Share on other sites
miniet 2 Posted July 20, 2020 (edited) Oh. and I found distance formula calculated by pythagoras theorem Distance = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) I will adapt a new formula to script then watch it can gives. Edited July 20, 2020 by miniet 1 Share this post Link to post Share on other sites