Jump to content
Vlue

Proximity Events

Recommended Posts

Proximity Events - v1.3

by V.M.

 

Introduction

This 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.

 

Features

- Activate events based on how close the player is to them

 

How to Use

 

All details in the script.

 

Script

Convenient Pastebin: Here

 

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.3 - Simple Line of Sight! Ooooh ahhhh.

Version 1.2 - Added rectangle function (inprox_r?)

Version 1.1 - Added directional function (inprox_d?)

Edited by Vlue

Share this post


Link to post
Share on other sites

Whoa. This is useful. Reminds me of the good ol' Eventer's Toolbox.

 

After copy and pasting your conditional checks, I am still getting errors (undefined for inprox/ Game_Interpreter)

264i0ow.png

Edited by Jon Wei

Share this post


Link to post
Share on other sites

Oh, bad examples! Bad!! They lost their question marks somewhere, I gave them new ones.

 

Clarification.. it's Proxy.inprox? and not Proxy.inprox that's why it's not working.

Share this post


Link to post
Share on other sites

Can you add shapes as well?

Currently it's a single line (in one direction, or all 4 directions).

 

How about triangle scope (one direction, 4 directions)? Perhaps specifying the angle of the line as well? (eg: so I could make sweeping scopes just by looping over the angle)

 

Or perhaps a rectangle? origin is the center of the sprite, takes up the entire width and height of the sprite rounded down to the nearest tile (eg: if it takes up only partial tiles, just forget the ones on the outside). You can round it down to the nearest 32 pixels (tilesize) and then divide by 32 to get the value relative to the tilemap.

 

vHTbD.jpg

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Can you add shapes as well?

Currently it's a single line (in one direction, or all 4 directions).

 

How about triangle scope (one direction, 4 directions)?

Or perhaps a rectangle? origin is the center of the sprite, takes up the entire width of the sprite rounded down to the nearest tile.

 

Actually as it works, inprox_d? isn't a line, it's triangular-y shaped like the first portion of your pic!

If orthogonocologicly directions means not just 4way however, no it doesn't work like that, this uses tiles and not pixels.

And inprox? isn't a line in either direction either, its a circle! (As circly as a bunch of tiles can be anyhow!)((ok more of a diamond, but shsh)

 

Rectangangly would be possible yes, I'll probably throw that in (sometime... eventually)

Share this post


Link to post
Share on other sites

ya it's fine if it's not possible. I was thinking maybe there was a way to quickly calculate diagonal proximity quickly.

 

One day maybe it will be! (It's certainly possible to write in, if I find the time)

 

On the plus side? New version, new function.

 

Proxy.inprox_r?(@event_id, width, height) will check to see if the player is in the rectangle around the event as defined by width/height

Works best with odd numbers!

Share this post


Link to post
Share on other sites

Hmm, when I say

 

(@event_id, 2, 2)

 

if you approach from the left, it works.

If you approach from the top, it works.

If you're standing diagonally to the event in the top-left, it works.

But if you approach from bottom or right or basically anywhere on the other side, it doesn't work.

 

In my head that means "a rectangle of width 2 and height of width 2"

But that doesn't really tell you where the origin is.

 

The origin should be centered at the middle of the tile (eg: x*32 + 16, y*32 + 16).

It is not an easy problem with tiles because you are working with 32 pixels each, where you have to first convert to pixels to determine the size of the box, and the convert it back to tiles to determine what the actual range is.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Hey, I am just having an issue with "Proxy.inprox_d?(@event_id, [#])", it always comes up with an error: game interpreter line 450: type error occurred. Array can't be coerced into a Fixnnum.

 

I tried it out a on a completely fresh project, no other scripts and get the same issue. All the other calls work perfectly though (this is one incredibly useful script by the way! Thanks a bunch for it!).

Share this post


Link to post
Share on other sites

Hrm I actually posted it as [#] with the brackets and all... oops.

Yah, just use a number, don't use brackets. Post edited to reflect that.

My bad~

Share this post


Link to post
Share on other sites

Just have a suggestion: is it possible to make it so these can be based off the player as opposed to an event? I just want to use it with directional checking, so certain events will act differently when the player is facing them.

 

EDIT: And maybe add a feature that allows events to detect each other? So if one event is in within range of another, it will give chase for example.

Edited by Tobyej

Share this post


Link to post
Share on other sites

Haha, this script is so much fun. :D I was wondering, is it possible so that events can't see you when you're behind specific tiles, like walls and crates, etc?

Share this post


Link to post
Share on other sites

That's a tad unfortunate. But it's not like this is still short of its uses. Right now I've thought of so many ways I could make my project more fun using this script, so cheers for that. :)

 

EDIT: Been fiddling around with the events I've been using for this script, and I've figured out a way to "hide" behind certain tiles. It's quite simple, and makes use of regions. All you need to do is assign a conditional branch for the script call, so it only gets triggered when you're on a specific tile. Kinda like this:

 

Control Variables: [0001: Region] = $game_player.region_id

Conditional Branch: Variable [0001: Region] = 1

Conditional Branch: Script: Proxy.inprox_d?(@event_id, 5)

 

And then follow on from that. As for scripting that in for the sake of simplicity, I think it's possible to add another section, where you could input the ID for any region that you don't want to trigger off the event. I'm pretty clueless with scripting myself, but I know you had something very similar with your climate and day/night scripts.

Edited by Paddy

Share this post


Link to post
Share on other sites

There is one major flaw with this script... If you have a mouse, it detects the proximity of the mouse cursor as the player proximity.

 

I don't quite understand, this script has nothing to do with the mouse, unless you mean when using a particular mouse script that fancily plays around with how player location works, in which case it wouldn't be a flaw with this script but with their compatibility with each other.

Share this post


Link to post
Share on other sites

Updated to 1.3 to include a basic sort of line of sight component to the detection (which you can say doesn't apply to specific checks)

Can also use regions to declare certain obstacles as transparent so they don't interfere with los, like pits and small boulders.

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.

×