Event Range Conditions
Authors: ForeverZer0
Version: 1.1
Type: Event Add-On
Key Term: Game Utility
IntroductionAllows you to set up conditional branches in events that will be based off the event's coordinates in relation to the player's coordinates without having to create any variables for the X and Y of each.
Features
- Conditions based on distance radius
- Conditions based on if they are ON/OFF screen
- Conditions based on linear distance on each axis
- Conditions based on whether they are above, below, left, or right in relation to player or other event
- Simple to use
ScreenshotsNone.
DemoNone.
ScriptClick here for the script.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Event Range Conditions
# Author: ForeverZer0
# Date: 5.1.2011
# Version: 1.1
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Explanation:
#
# Allows you to set up conditional branches in events that will be based off
# the event's coordinates in relation to the player's coordinates without
# having to create any variables for the X and Y of each.
#
# Here are the new features you can use a conditional branch. Just type these
# into the script box for the branch.
#
# range?(RANGE, EVENT_ID) - Will be true if player is anywhere in the radius
# defined by RANGE from the event with EVENT_ID
#
# on_screen?(EVENT_ID) - Will be true if the event with EVENT_ID is within
# the visible screen
#
# x_dist?(DIST, EVENT_ID) - Returns true if the player's x/y is within DIST
# OR of event's x/y with EVENT_ID. These are absolute
# y_dist?(DIST, EVENT_ID) values, meaning it doesn't matter which direction,
# it just uses the total distance in tiles for that
# axis. Use a DIST of 0 to check if that axis is
# equal.
#
# player_above?(EVENT_ID) - Returns true when player is above event.
# player_below?(EVENT_ID) - Returns true when player is below event.
# player_right?(EVENT_ID) - Returns true when player is right of the event.
# player_left?(EVENT_ID) - Returns true when player is left of the event.
#
# For all of these, if the conditional branch that is using them is within
# the event that it applies to, you do not have to include the EVENT_ID, it
# is assumed to be that event's ID unless otherwise defined.
#
# You can use these as a condition for just about anything, such as having
# an event say something, run away, or run toward the player if it is within a
# specific distance, and it's much easier than using multiple branches and
# game variables to set it up.
#
# Remember that if you use a range condition with a parallel trigger, it will
# continue to execute as long as the condition is met and if the player cannot
# move during the event's code, the game will effectively be stuck.
#
# Compatability:
#
# - You may encounter issues if using a Pixel Movement script, though it
# should still work fine with an 8-Way Movement script. (Not tested)
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
class Interpreter
def range?(range = 4, id = @event_id)
e = $game_map.events[id]
radius = (Math.hypot((e.x - $game_player.x), (e.y - $game_player.y))).abs
return (radius <= range)
end
def on_screen?(id = @event_id)
x, y = $game_map.events[id].real_x, $game_map.events[id].real_y
return ((x - $game_map.display_x + 64) / 4).between?(0, 640) &&
((y - $game_map.display_y) / 4).between?(0, 480)
end
def x_dist?(distance = 0, id = @event_id)
x_dif = ($game_map.events[id].x - $game_player.x).abs
return (x_dif <= distance)
end
def y_dist?(distance = 0, id = @event_id)
y_dif = ($game_map.events[id].y - $game_player.y).abs
return (y_dif <= distance)
end
def player_above?(id = @event_id)
return ($game_map.events[id].y > $game_player.y)
end
def player_below?(id = @event_id)
return ($game_map.events[id].y < $game_player.y)
end
def player_right?(id = @event_id)
return ($game_map.events[id].x < $game_player.x)
end
def player_left?(id = @event_id)
return ($game_map.events[id].x > $game_player.x)
end
end
InstructionsPlace script anywhere below the Interpreter scripts, and above "Main"
The different script calls are listed within the script.
CompatibilityPossible compatibility issues with pixel-movement scripts.
Credits and Thanks
- ForeverZer0, for the script
Author's NotesPlease report any bugs/issues you find.
Hope you enjoy!
"# Remember that if you use a range condition with a parallel trigger, it will
# continue to execute as long as the condition is met and if the player cannot
# move during the event's code, the game will effectively be stuck."
I dont get that part S:, the game is stuck for me when I put a range condition, I cant move the player, I dont really get what is cousing it, S:.
can you explain that part just alittle bit better? like an example of what can cause that.
ex.
You have an event with a parallel trigger. There is "range?(4)" condition that will show a text box, which the player cannot move while it is displayed. If you do not set a switch use a self switch or something to stop this checking this condition, the second the player exits the message, the event condition is re-checked, and since the player is still in the same location since control was lost, the condition is still true and the message pops up again. It will continue to do this.
It can easily be stopped by a self-switch or something to switch to stop checking after it is first executed, you just need to be conscious of these possible scenarios when building your events.
I love you. No homo.
That is all.
Whoa, that's a real time saver, thank you!
If it interests anyone, aparently works fine with cogwheel's pixel movement :)
range?(RANGE, EVENT_ID)
I know that this line only checks for if EVENT_ID is in defined range distance away from PLAYER then it returns true.... Is there a way to use this line or perhaps another line in the script so it can be use for EVENT_ID checks another EVENT_ID if within range and not the player? Im trying to make an event check the distance range with another event and if within specified range between both events then condition is true and will say "Hi!" between both events...
Add this method to the script. Its pretty self-explanatory, just use this call:
event_range?(EVENT1_ID, EVENT2_ID, RANGE)
def event_range?(event1_id, event2_id, range)
e1, e2 = $game_map.events[event1_id], $game_map.events[event2_id]
radius = (Math.hypot((e1.x - e2.x), (e1.y - e2.y))).abs
return (radius <= range)
end
Thanks a bunch! It worked -) kudos! :shy: now u have a new version LoL :haha:
When the player approaches an event, a self-switch will be set.
When the player moves away from the event, the self-switch should be turned off.
Currently the first page uses range condition to activate the self-switch, but then I do all sorts of things just to get the self to turn off when I move away.
Is there an easy way to deal with this?
Just use the inverse condition on the page that is activated by the first page.
Got it. Didn't know "not" would do the trick. :)
Hello, I'm kinda new and a total scripting Noob...
I wanted to use your Range Conditions with your Custom Event Triggers (http://forum.chaos-project.com/index.php/topic,6893.0.html) but it never works. I'm too dumb to get it to run I think. Could you please tell me how I should set it up? I tried something like this:
Comment: Custom Trigger
: player_above?(14)
But it always gives me an error like this: "undefined method `player_above?ยด for ..."
edit
I got it to work for me.
/edit
I'm using this great script in my project and it's doing wonders! Can make events conflict with other events :evil:
Anyway would it be possible to make an event follow/chase another event?
It would be very great if it would be possible.
Thanks for the help.
I suppose you could use this for chasing, though it would require a bit of an expansive event. The easiest way would be to have an event set a variable determining the direction it is from the second event, then branch to determine what direction to make the chasing event turn, then use "One Step Forward".
Or you can just use a pathfinding script like this (http://forum.chaos-project.com/index.php/topic,9784.0.html) or this (http://forum.chaos-project.com/index.php/topic,10661.0.html) variation of it that allows for using event names.
Ok thanks for the help will try one of them tomorrow.
(Trying to make the wildlife fight each other if x beast gets near y beast territories, etc)
Ok tried the variation one using the example in the thread and getting an error like the last guy posted on the thread without getting a response :S
The first is my original script. The second link is my script which someone else modified, and the error appears to be with his edits. You can always use the original, just won't be able to call using the event's name.
I could but I didn't understand how to do it on your version (Even on the other one if it wasn't for the example he gave) as the description doesn't clearly say how to make x event follow y event but only go on z location or maybe I got it wrong don't know.
Create an event that tracks the coordinates of the first event and have the second pathfind to it.
But the type I wanted to do was not on an event that stood still waiting for the other event to reach it that's the problem.
Say for example there's a cat on the fields and a mouse gets too close the cat starts chasing it but the mouse won't stand still and that script (Checked the demo) only makes x event/player move to y coordinates.
Anyways if it's too trouble no need to do it and thanks for the help nonetheless :).
Its a single parallel process event and two variables. I didn't think it was too difficult unless you are just misunderstanding what I suggested.
Yes and sorry for flooding your thread with something about this script.
I don't really get what you mean and I don't use much variables usually it's from tutorials or something as I kinda get confused on them.
Sorry foreverzer0 for bugging you again for this script.
The only way to make the conditions is by parallel process for the events to spot you when your near? because I tried making custom movement and adding the line of script but after a second of playtesting I get an error undefined method range? for game_event:0x9288f50.
Having parallel process for every npc would probably lag the game.
Quote from: Vexus on February 01, 2012, 04:20:51 am
Sorry foreverzer0 for bugging you again for this script.
The only way to make the conditions is by parallel process for the events to spot you when your near? because I tried making custom movement and adding the line of script but after a second of playtesting I get an error undefined method range? for game_event:0x9288f50.
Having parallel process for every npc would probably lag the game.
script lines in custom move route don't use interpreter methods.
put it in game_map for instance to call it with $game_map.range?(range,id) like this:
class Game_Map
def range?(range = 4, id = @event_id)
e = $game_map.events[id]
radius = (Math.hypot((e.x - $game_player.x), (e.y - $game_player.y))).abs
return (radius <= range)
end
end
just add this below the script, however it won't automatically put in the event's id anymore so you'll always have to add it.
class Game_Character
def range?(range = 4, id = @id)
e = $game_map.events[id]
radius = (Math.hypot((e.x - $game_player.x), (e.y - $game_player.y))).abs
return (radius <= range)
end
end
Add that, and you can should be able to use the method normally in move routes. * I think *
Thanks will try it out hopefully it works.
Dang, I was hoping that this was made by someone else :s Well anyone can answer it though.
In the features section of the post, it says
"Conditions based on whether they are above, below, left, or right in relation to player or other event"
But I don't see anything in the script about checking an event's range to x event.
By simply using this script is this possible?
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * New method: character_above?
#--------------------------------------------------------------------------
def character_above?(character)
return (character.y > @y)
end
#--------------------------------------------------------------------------
# * New method: character_below?
#--------------------------------------------------------------------------
def character_below?(character)
return (character.y < @y)
end
#--------------------------------------------------------------------------
# * New method: character_right?
#--------------------------------------------------------------------------
def character_right?(character)
return (character.x < @x)
end
#--------------------------------------------------------------------------
# * New method: character_left?
#--------------------------------------------------------------------------
def character_left?(character)
return (character.x > @x)
end
end
event1 = get_character(1) # event with ID 1
event2 = get_character(2) # event with ID 2
$game_switches[1] = event1.character_above?(event2)