Jump to content
miniet

Find nearest Event ID with nametag script

Recommended Posts

Posted (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 by miniet

Share this post


Link to post
Share on other sites

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
Posted (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 by roninator2

Share this post


Link to post
Share on other sites

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
Posted (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 by miniet

Share this post


Link to post
Share on other sites
Posted (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 by miniet

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×