efeberk Detector Script

I am having a bit of a problem with this script.
Spoiler
Code:
# -------------------------------------------------
# Script Name : Detector
# Scripter : efeberk
# Date : 08.08.2012
# Version : RPG Maker VX Ace(RGSS3)
# Special Thanks to Bird Eater
# ------------------------------------------------
#
# Features :
#
# This script allows an event detects player when player near to event.
#
# Introductions :
#
# Make a "Conditional Branch" event command and select Script.
# ------------------------------------------------------------------------
# Script : detected?(e, d, true)
#
# e : event id
#
# 0 => Current Event
# 1+ => Event ID
#
# d => distance range from player.
#
# Example : Conditional Branch : detected?(3, 4, true)
#
# This means : returns true if distance 4 from 3. event to player and
# 3.event saw player.

#~ -----------------------------------------------------------------------
#~ Script : region_reached?(a)
#~
#~ This method allows to return true if player reached a
#~ specific region ID.
#~
#~ a => region ID
#~
#~ Example : region_reached?(6)

#~ This means : True if player is on region 6.
#~
#~ -------------------------------------------------------------------------
#~ Script : saw_player?(e)
#~
#~ This method allows to return true if an event saw the player.
#~
#~ e => event ID
#~
#~ 0 = event that used script.
#~ 1+ = event ID
#~
#~ Example : saw_player?(3)
#~
#~ Returns true if 3.event saw player.


class Game_Event < Game_Character

def move_type_toward_player
if near_the_player?
move_toward_player

else
move_random
end
end
end


class Game_Interpreter

def get_event(i)
if i == 0
return $game_map.events[@event_id]
end
if i > 0
return $game_map.events[i]
end

end


def detected?(a, d, k = false)
if k == true
return distance(a, d) && saw_player?(a)
else
return distance(a, d)
end
end

def distance(a,d)
ax = (get_event(a).x - $game_player.x).abs
ay = (get_event(a).y - $game_player.y).abs
if((ax + ay) <= d)
return true
else
return false
end
end


def region_reached?(a)
if $game_player.region_id == a
return true
else
return false
end

end

def saw_player?(e)
sx = distance_x_from(e, $game_player.x)
sy = distance_y_from(e, $game_player.y)
if sx.abs > sy.abs
direction = sx > 0 ? 4 : 6
else
direction = sy > 0 ? 8 : 2
end
if (direction == get_event(e).direction)
return true
else
return false
end

end

def distance_x_from(e, x)
result = get_event(e).x - x
if $game_map.loop_horizontal? && result.abs > $game_map.width / 2
if result < 0
result += $game_map.width
else
result -= $game_map.width
end
end
result
end

def distance_y_from(e, y)
result = get_event(e).y - y
if $game_map.loop_vertical? && result.abs > $game_map.height / 2
if result < 0
result += $game_map.height
else
result -= $game_map.height
end
end
result
end

end
So my problem is when I go passed one of my events that needs to see me in order for him to activate, when he is facing down and I am one block cross ways from him:
Here:
1588189314403.png
Or here:
1588189351939.png

He turns into an autorun event and the screen freezes.
Here is the event setup:
1588189428005.png

1588189456360.png

Thank you for any help.
@slickdeath97 It looks like you already made a thread for this and it was locked at your request. I'll leave this one open, but in the future please do not make multiple threads for the same thing.
I had to recreate this from your previous demo.
You only need to specify one condition you have two.
detected?(0, 2, true)

If you read through the script, what the true value does is only do detection if the event sees the player. So basically he has to be facing the player.
It didn't work for you because you had the two conditions in there and probably confused the script.
detected?(0, 1, true)

If you used detected?(0, 2) then the event does not need to be facing the player to catch him.

Other wise the script works fine. A little limited in that it doesn't do diagonal as easily as straight vision.
I had to recreate this from your previous demo.
You only need to specify one condition you have two.
detected?(0, 2, true)

If you read through the script, what the true value does is only do detection if the event sees the player. So basically he has to be facing the player.
It didn't work for you because you had the two conditions in there and probably confused the script.
detected?(0, 1, true)

If you used detected?(0, 2) then the event does not need to be facing the player to catch him.

Other wise the script works fine. A little limited in that it doesn't do diagonal as easily as straight vision.
Ok, so I took out the (0,1,true) part and kept the other part. The problem is still happening, how would I fix it?
The problem is still happening
Are you referring to the freezing? If so, that's part of your eventing.
Are you referring to the freezing? If so, that's part of your eventing.
Yes, the freezing: here is the event:
1588627318375.png

1588627340049.png

1588627365272.png

1588627391135.png

1588627426120.png
here is the event
And that is only half the event. Like I said before I'm not going to create the event for you or tell you how to do your events, but here it is obvious in one aspect, You are specifying different directions. The detector script will do detection when facing the player. There is no need to use directions. "this event is facing right".
Also why do you need to specify the position??
Game_Player.x == 8
the dector script doesn't care where the player is.

You're eventing like the program will do nothing if you don't have specific directions.

code line 1 - print "hi"
code line 2. access display output
code line 3. transmit message output to display
code line 4. draw message output to display
code line 5. return to next process
etc
etc

Make it simpler. the event auto-runs when you are detected. done. Now what happens.
message, you are caught blah blah.
options run bribe beg fight.
do actions for options

Now I see you have switches for boy or girl etc.
that looks like it plays after defeating the enemy. So put it at the bottom. and you only need it once then.

Carry on
And that is only half the event. Like I said before I'm not going to create the event for you or tell you how to do your events, but here it is obvious in one aspect, You are specifying different directions. The detector script will do detection when facing the player. There is no need to use directions. "this event is facing right".
Also why do you need to specify the position??
Game_Player.x == 8
the dector script doesn't care where the player is.

You're eventing like the program will do nothing if you don't have specific directions.

code line 1 - print "hi"
code line 2. access display output
code line 3. transmit message output to display
code line 4. draw message output to display
code line 5. return to next process
etc
etc

Make it simpler. the event auto-runs when you are detected. done. Now what happens.
message, you are caught blah blah.
options run bribe beg fight.
do actions for options

Now I see you have switches for boy or girl etc.
that looks like it plays after defeating the enemy. So put it at the bottom. and you only need it once then.

Carry on
I have the x and y so it knows wheather to move or not this way if the player is seen and they are two blocks away then it will have the npc move towards the player.
Since the distance is 2, you could just use the move route command to move the event two spaces 'toward player' and check to skip if cannot move. Should work.
Since the distance is 2, you could just use the move route command to move the event two spaces 'toward player' and check to skip if cannot move. Should work.
I will try it. It worked, had to mess around with it so if the player was not right in front of the npc it would turn to the player

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/efeberk-detector-script.120838/