Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Need help with view range script!

I have Near's View Range script but I don't know how to use it!
I little tutorial would help, please. :D

Thanks in advance!
 
Version 4, SDK version:
Code:
#==============================================================================
# â–  View Range Module
#==============================================================================
# Near Fantastica
# Version 4
# 29.11.05
#==============================================================================

#--------------------------------------------------------------------------
# * SDK Log Script
#--------------------------------------------------------------------------
SDK.log("View Range", "Near Fantastica", 4, "29.11.05")

#--------------------------------------------------------------------------
# * Begin SDK Enable Test
#--------------------------------------------------------------------------
if SDK.state("View Range") == true
  module VR
    #----------------------------------------------------------------------------
    def VR.in_range?(element, object, range)
      x = (element.x - object.x) * (element.x - object.x)
      y = (element.y - object.y) * (element.y - object.y)
      r = x + y
      if r <= (range * range)
        return true
      else
        return false
      end
    end
    #----------------------------------------------------------------------------
    def VR.range(element, object)
      x = (element.x - object.x) * (element.x - object.x)
      y = (element.y - object.y) * (element.y - object.y)
      r = x + y
      r = Math.sqrt(r)
      return r.to_i
    end
  end
  
  #==============================================================================
  class Interpreter
    #----------------------------------------------------------------------------
    def event
      return $game_map.events[@event_id]
    end
  end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
 
It is rather simple. Just uses some basic trig.

First off, test if event 3 is within 5 tiles to event 4

Code:
VR.in_range?(element, object, range)

element is event 4
object is event 3
range is 5

Code:
VR.in_range?($game_map.events[4], $game_map.events[3], 5)

That line will return true or false, depending on if the events are within 5 tiles of eachother.


Then, to get the range from event 2 to event 7, you use the range method.

Code:
VR.range(element, object)

just replace element and object with your events

Code:
VR.range($game_map.events[2], $game_map.events[7])

That will return how ever many tiles it is from one event to another.


This will work with anything that has x and y attributes (so windows, custom classes, etc.)
 

Aran

Member

well i kno that part... but what if you wanna check if the actor is in range?

i tried data_actor, but that has no x or y value

then i tried game_character, which somehow didn't work...

i knew the rest from decoding Prexus' ABS
 
The event syntax just returns the event that the Interpreter belongs to (Map, battle, common events, and events all have interpreters).

You can see in Game_Event

@interpreter.setup(@list, @event.id)

So the setup method in the interpreter class assigns the @event_id variable.


Anyways, I am still not sure what you are trying to accomplish...

What are you talking about with "actor"?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top