RMParadise

It seems you either have yet to login or are not a member of RMP. If you are not yet a member, please feel free to sign up so that you can unlock every feature our forums have to offer. If you have yet to login, please do so soon.

Join the forum, it's quick and easy

RMParadise

It seems you either have yet to login or are not a member of RMP. If you are not yet a member, please feel free to sign up so that you can unlock every feature our forums have to offer. If you have yet to login, please do so soon.

RMParadise

Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Paradise for RPGMakers.

Welcome everyone to RMP, your very own RPGMaker Paradise.
If you are reading this, that means that you are one of the select few who have been invited to experience our site as a Beta User.
Being a Beta User only requires that you report any bugs and/or problems upon finding them.
You get the chance to have free roam over the boards before they are public and are further up in line for promotions (which will be happening very soon, so stay on your best behavior).
Check out the thread for the RMP Beta Contest. Lets get some new content rolling.
Chat
Back to Top

2 posters

    Proximity Events

    Vlue
    Vlue
    I'm a new member :)
    I'm a new member :)


    Registered on Registered on : 2012-05-28
    Posts Posts : 30
    Rep. Points Rep. Points : 13

    Proximity Events Empty Proximity Events

    Post by Vlue Wed Jun 06, 2012 6:14 pm

    Proximity Events - v1.2
    by V.M.


    Introduction
    This small script will allow you to use the script portion of conditional branches to activate events based on player proximity. Uses could be monster groups that chase down the player or lights that activate when the player walks near them, or anything else you can manage to do with it.

    How to Use

    Proximity Detection Script
    Configuration consists of setting a default Proximity Range within the script
    Usage: By setting an event to Parallel Process and using a Conditional Branch
    within that does the script call: Proxy.inprox?(@event_id) you can have
    the commands within fire off when the player is within or not within
    proximity.

    Common Usage:
    Proxy.inprox?(@event_id) for checking for player within default range
    Proxy.inprox?(@event_id, #) for checking for player within # range
    Proxy.inprox_d?(@event_id, [#]) for directional checking
    All calls return true if within range and false when not

    Advanced Usage:
    Proxy.inprox?(nil, #, x, y) for checking for player within # range
    of a x,y point on the map

    Any errors involving Game_Interpreter usually means the script call was mispelt
    so double-check if that occurs

    Script
    Code:
    ##Proximity Detection Script
    #Configuration consists of setting a default Proximity Range within the script
    #Usage: By setting an event to Parallel Process and using a Conditional Branch
    #      within that does the script call: Proxy.inprox?(@event_id) you can have
    #      the commands within fire off when the player is within or not within
    #      proximity.
    #
    #Common Usage:
    #    Proxy.inprox?(@event_id)    for checking for player within default range
    #    Proxy.inprox?(@event_id, #) for checking for player within # range
    #    Proxy.inprox_d?(@event_id, [#]) for directional usage
    #    Proxy.inprox_r?(@event_id, width, height)  rectangular checking with event
    #                                              as an origin (works best with
    #                                              odd numbers)
    #
    # All calls return true if within range and false when not
    #
    #Advanced Usage:
    #    Proxy.inprox(nil, #, x, y) for checking for player within # range
    #                              of a x,y point on the map
    #
    #Any errors involving Game_Interpreter usually means the script call was mispelt
    #  so double-check if that occurs
    #------#
    #-- Script by: V.M of D.T
    #--- Free to use in any project with credit given


    class Proxy
      #Default radius of detection:
      PROXYRANGE = 4
      #----#
      def self.inprox?(id, distance = PROXYRANGE, x = 0, y = 0)
        if id != nil
          x = $game_map.events[id].x
          y = $game_map.events[id].y
        end
        iter = x + distance + 1
        iter2 = 0
        half = x
        x = x - distance
        while x < iter
          ylow = y - iter2 
          yhigh = y + iter2
          if $game_player.x == x and $game_player.y >= ylow and $game_player.y <= yhigh
            return true
          end
          x += 1
          if x > half then iter2 -= 1 else iter2 += 1 end
        end
        return false
      end
      def self.inprox_d?(id, distance = PROXYRANGE, x = 0, y = 0)
        if self.inprox?(id, distance, x, y) then else return false end
        x1 = $game_player.x; x2 = $game_map.events[id].x
        y1 = $game_player.y; y2 = $game_map.events[id].y
        x1 > x2 ? xx = x1 - x2 : xx = x2 - x1
        y1 > y2 ? yy = y1 - y2 : yy = y2 - y1
        case $game_map.events[id].direction
        when 2
          if $game_player.y > $game_map.events[id].y then
            if yy >= xx then return true end end
        when 4
          if $game_player.x < $game_map.events[id].x then
            if xx >= yy then return true end end
        when 6
          if $game_player.x > $game_map.events[id].x then
            if xx >= yy then return true end end
        when 8
          if $game_player.y < $game_map.events[id].y then
            if yy >= xx then return true end end
        end
        return false
      end
      def self.inprox_r?(id, width, height)
        width % 2 == 0 ? hwidth = width / 2 : hwidth = (width - 1) / 2
        height % 2 == 0 ? hheight = height / 2 : hheight = (height - 1) / 2
        x = $game_map.events[id].x - hwidth
        y = $game_map.events[id].y - hheight
        if $game_player.x >= x and $game_player.x < (x + width)
          if $game_player.y >= y and $game_player.y < (y + height)
            return true
          end
        end
        return false
      end
    end


    FAQ
    To be announced if necessary?

    Credit and Thanks
    - By V.M.of D.T.
    - Free to use in any project with credit given

    History
    Version 1.2 - Added rectangle function (inprox_r?)
    Version 1.1 - Added directional function (inprox_d?)
    Hyde
    Hyde
    Administrator
    Administrator


    Registered on Registered on : 2012-05-18
    Posts Posts : 101
    Rep. Points Rep. Points : 6

    Proximity Events Empty Re: Proximity Events

    Post by Hyde Wed Jun 06, 2012 6:41 pm

    Oh my lord, I was going to put this on the script ideas thread soon. Talk about timing, lol.

    Anyways, awesome job on the script. I foresee this in near all of my games.

      Current date/time is Wed May 08, 2024 8:50 am