Line of Sight problems

● ARCHIVED · READ-ONLY
Started by JoePro 8 posts View original ↗
  1. Hello all,
    I'm currently (was) working on a script to determine an events line of sight.
     
    The event sees the player, regaurdless of obstructions, as long as it is facing the player. This should not be the case unless the obstruction is marked with a region id to make it become transparent to the event.
     
    Here is the script and a link to the demo so you can see an example of the issue.


    Script

    Spoiler
     #################################################################################↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓##↓                                                                            ↓##↓                     Xpanded Event Control: Version 0.3                     ↓##↓                                                                            ↓##↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕##↑                                                                            ↑##↑                          Written By: Joe Pro                            ↑##↑                        Last Edited: August 3, 2014                         ↑##↑                                                                            ↑##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑##################################################################################◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** Disclaimer                                                              ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙ This script is not for commercial, if you wish to use this script in a     ◙##◙ game please PM me at which ever site you found this script. Either way,    ◙##◙ give me credit as the writer of this script.                               ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** How To Use                                                              ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙ * Use the example below in an event script call to refer to the current    ◙##◙   event. Works like a self ( or the method get_charactor(0) )for scripting ◙##◙   within an event.                                                         ◙##◙                                                                            ◙##◙    event_self                                                              ◙##◙                                                                            ◙##◙ * Use the example below in an event script call to find the proximity of   ◙##◙   the current event to the player.                                         ◙##◙                                                                            ◙##◙    proximity?                                                              ◙##◙                                                                            ◙##◙ * Use the example below in an event script call to find if the current     ◙##◙   event can see the player.                                                ◙##◙                                                                            ◙##◙    viewable?                                                               ◙##◙                                                                            ◙##◙ * Use the example below in an event script call to find the direction of   ◙##◙   the player from the event.                                               ◙##◙                                                                            ◙##◙    player_direction                                                        ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** Updates / Version Notes                                                 ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙   v0.1                                                                     ◙##◙ ~◄◙◙◙◙►~                                                                   ◙##◙ * This script adds more checks and methods for interactions between the    ◙##◙   game player and events. It currently allows for proximity checks and     ◙##◙   and a line of sight system.                                              ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##################################################################################↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓##↓                                                                            ↓##↓                      Keep EXP Save Spots: Version 0.1                      ↓##↑                                                                            ↑##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑##################################################################################==============================================================================# ** Xpanded Event Control Module#------------------------------------------------------------------------------#  This module manages the customizable and function modules.#==============================================================================module Xpanded_Event_Control  #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙Customizeable Area◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#  #=============================================================================  # * Line of Sight Options  #=============================================================================    Transparent_Region_ID = 1    Default_Distance = 8 #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙End Customizeable Area◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#end#==============================================================================# ** Game_Character#------------------------------------------------------------------------------#  A character class with mainly movement route and other such processing# added. It is used as a super class of Game_Player, Game_Follower,# GameVehicle, and Game_Event.#==============================================================================class Game_Character < Game_CharacterBase  #--------------------------------------------------------------------------  # * Public Instance Variables  #--------------------------------------------------------------------------  attr_accessor  :wait_time               # forced move route flag  #--------------------------------------------------------------------------  # * Aliasing_method: Initialize Public Member Variables  #--------------------------------------------------------------------------  alias :gcipv32104506450 :init_public_members      #--------------------------------------------------------------------------  # * Initialize Public Member Variables  #--------------------------------------------------------------------------  def init_public_members    gcipv32104506450()    @wait_time = 0  end end#==============================================================================# ** Game_Event#------------------------------------------------------------------------------#  This class handles events. Functions include event page switching via# condition determinants and running parallel process events. Used within the# Game_Map class.#==============================================================================class Game_Event < Game_Character  #--------------------------------------------------------------------------  # * Aliasing_method: Move Type : Random  #--------------------------------------------------------------------------  alias :gemtr0401000004564 :move_type_random      #--------------------------------------------------------------------------  # * Move Type : Random  #--------------------------------------------------------------------------  def move_type_random    if self.wait_time > 0      self.wait_time -= 1    else      gemtr0401000004564()      self.wait_time = (rand(240) + 60) if rand(6) == 1    end  end   #--------------------------------------------------------------------------  # * Move Type : Approach  #--------------------------------------------------------------------------  def move_type_toward_player    if near_the_player?      move_toward_player    else      move_random    end  end   #--------------------------------------------------------------------------  # * Determine if Player is Within Proximity  #--------------------------------------------------------------------------  def proximity_to_player?    return (x_proximity_to_player? + y_proximity_to_player?)  end   #--------------------------------------------------------------------------  # * Determine if Player is Within X Proximity  #--------------------------------------------------------------------------  def x_proximity_to_player?    return (self.x > $game_player.x) ? self.x - $game_player.x : $game_player.x - self.x  end   #--------------------------------------------------------------------------  # * Determine if Player is Within Y Proximity  #--------------------------------------------------------------------------  def y_proximity_to_player?    return (self.y > $game_player.y) ? self.y - $game_player.y : $game_player.y - self.y  end   #--------------------------------------------------------------------------  # * Returns the Direction of the Player From This Event  #--------------------------------------------------------------------------  def oppisite_direction    case @direction    when 2      return 8    when 4      return 6    when 6      return 4    when 8      return 2    end  end   #--------------------------------------------------------------------------  # * Returns the Direction of the Player From This Event  #--------------------------------------------------------------------------  def player_direction    return (x_proximity_to_player? > y_proximity_to_player? ? (self.x > $game_player.x ? 4 : 6) : (self.y > $game_player.y ? 8 : 2))  end   #------------------------------------------------------------------------  # * Return All Comments  #------------------------------------------------------------------------  def return_all_comments    comments = []    @list.each { |command| comments.push command.parameters[0] if command.code == 108 } if @list    return comments  end    #--------------------------------------------------------------------------  # * Distance Viewable  #--------------------------------------------------------------------------  def distance    comments = return_all_comments    comments.each { |comment|      comment.scan(/distance:\s*(\d*)/im)      return $1.to_i if $1    }    return Xpanded_Event_Control::Default_Distance  end   #--------------------------------------------------------------------------  # * Determine if Player is Within Line of Sight.  #--------------------------------------------------------------------------  def line_of_sight?    return (player_direction != oppisite_direction)  end   #--------------------------------------------------------------------------  # * Determine if Player is Within View Without Obstruction  #--------------------------------------------------------------------------  def viewable?    viewable = true    ex = self.x    ey = self.y    px = $game_player.x    py = $game_player.y  #---------------------------------------------------------#  # * Checking if the Player is in the Events Line of Sight #  #---------------------------------------------------------#    if line_of_sight?  #------------------------------------------#  # * Checking if Within Proximity of Player #  #------------------------------------------#      if distance > proximity_to_player?  #---------------------------------#  # * Checking for any Obstructions #  #---------------------------------#        y_proximity_to_player?.times { |y|          x_proximity_to_player?.times { |x|            case            when (ex < px)              if (ey < py)                viewable = false if !$game_map.passable?((ex + x), (ey + y), @direction)              else                viewable = false if !$game_map.passable?((ex + x), (ey - y), @direction)              end            when (ex > px)              if (ey < py)                viewable = false if !$game_map.passable?((ex - x), (ey + y), @direction)              else                viewable = false if !$game_map.passable?((ex - x), (ey - y), @direction)              end            end          }        }  #----------------------------------------------------------------#  # * Checking for any Obstructions if y_proximity_to_player? == 0 #  #----------------------------------------------------------------#        x_proximity_to_player?.times { |x|          case          when (ex < px)            viewable = false if !$game_map.passable?((ex + x), ey, @direction)          when (ex > px)            viewable = false if !$game_map.passable?((ex - x), ey, @direction)          end          } if y_proximity_to_player? == 0  #----------------------------------------------------------------#  # * Checking for any Obstructions if x_proximity_to_player? == 0 #  #----------------------------------------------------------------#        y_proximity_to_player?.times { |y|          case          when (ey < py)            viewable = false if !$game_map.passable?(ex, (ey - y), @direction)          when (ey > py)            viewable = false if !$game_map.passable?(ex, (ey + y), @direction)          end          } if x_proximity_to_player? == 0  #---------------------------------------------------#  # * Returns false if distance < proximity_to_player?#  #---------------------------------------------------#      else        viewable = false      end  #------------------------------------#  # * Returns false if !line_of_sight? #  #------------------------------------#    else      viewable = false    end    return viewable  end end#==============================================================================# ** Game_Interpreter#------------------------------------------------------------------------------#  An interpreter for executing event commands. This class is used within the# Game_Map, Game_Troop, and Game_Event classes.#==============================================================================class Game_Interpreter  #--------------------------------------------------------------------------  # * Get the Proximity of Event to Player  #--------------------------------------------------------------------------  def proximity?    get_character(0).proximity_to_player?  end  #--------------------------------------------------------------------------  # * Get the Direction of the Player From This Event  #--------------------------------------------------------------------------  def player_direction    get_character(0).player_direction  end  #--------------------------------------------------------------------------  # * Get the Direction of the Player From This Event  #--------------------------------------------------------------------------  def viewable?    get_character(0).viewable?  end  #--------------------------------------------------------------------------  # * Returns Current Event  #--------------------------------------------------------------------------  def event_self    get_character(0)  endend
     
     
    Demo
    Spoiler
    http://www.mediafire.com/download/u3g52k94452voq4/Xpanded_Events_Demo.zip
     
    *****Edit*****​
     ​
    This is a very fast mock up with a screenshot of my problem.
     
    The red squares with X's represent a solid wall. The blue empty squares represent an obstruction that can still be seen through. Basically the rest of the script seems to be working fine, as far as I can tell. My only problem is if I am standing directly in front of the event, it will always see me, even if the path is obstructed.

     
     
    Photos

    Spoiler
    Line of Sight.png
     
    *****Edit*****​
     ​
    I have set up the viewable? method to now print to the console the current event to player cases. I noticed that it is not printing any of the == conditioned cases.
     
    I've fixed the problem above but the event still has a question mark even though it is returning false. Is there something wrong with the event.


    here are the images incase you don't want to download the demo.
     

    Spoiler
    1.png
    2.png
    3.png
    4.png
    5.png
    ***FIXED.

    Mod can close this post, Thank you all!
  2. You mean, "line of sight", for the correct spelling. "Line of site" has no meaning I am aware of. Sight = visual detection. Site = the position or location.


    I understand your meaning from the description, but haven't downloaded the demo or tried the script yet; still, it may help me or others in debugging the script if you include a brief picture of what is intended.
  3. Thank you for the response Onomotopoeia, "Sight = visual detection. Site = the position or location." way to rub it in. ;) I spelled it right in the script. But thank for judging me at a glance and admitting it. If your going to help, please help. I'm tired... I have a baby and I've written 8 scripts in 2 days... Go troll somewhere else Spelling Cop.

    I will try to do that though, I will post it at the top. Incase there are any other non-scripters that want to "See" what I'm talking about.
  4. I'm not 100% familiar with Ace scripts, but I am good at Ruby and this method is probably the problem.

    Spoiler
    #------------------------------------------------------------------------# * Dispose#------------------------------------------------------------------------ def return_all_comments comments = [] list.each { |command| comments.push parameter[0] if command ==108 } if list return comments end  
    So this method doesn't do anything except return an empty array. "list" refers to an empty local variable while you probably meant to use "@list" the object variable. So the method is basically skipping that line since you have the conditional attached to it, and is always returning an empty array. So change both references to @list and hopefully that fixes things. :)  lol, it's always the little things that get screwed up we're you're trying to code while tired am I right?
  5. MobiusXVI, that's right. But this method contains more mistakes. @list is either nil or an array of RPG::EventCommand (which is documented in the help file, so go read it!). The comparison of command with 108 will always be false. RPG::EventCommand#code returns the code. parameter[0] is also wrong. It's plural and an instance method of RPG::EventCommand.

    Here's a fixed version (hopefully because untested; I'm not sure if the if is needed):

      def return_all_comments    if @list      @list.find_all { |command| command.code == 108 }.           map!     { |command| command.parameters[0] }    else      []    end  endNote: It doesn't return all comments. It returns the first line of each comment in the active event page.
  6. Well, cool. Glad I could help at least a little. lol. Like I said I don't know everything about Ace. *Shrugs shoulders and goes back to writing scripts for XP*
  7. Thank you MobiusXVI for your response. I didn't even catch that, however that only has to do with the distance comment and nothing to do with the line of sight, so my problem still exsists. And yes I am writing scripts very very tired, It's my guilty pleasure. I dream about programming anyway I might as well stay up and just do it. I've written 15 scripts in 3 days.

    1. Pro Core MOd
    2. Custom Tags
    3. Switch Timer System
    4. Xpanded Event Control
    5. Stealth System(which is aslo in the demo)
    6. Keep EXP Save Spots
    7. Pause Screen
    8. Teleportion System
    9. Jump SE
    10. Custom Crafting Systems
    11. Map Battleback
    12. Character Select System
    13. Title Command Options
    14. Relic Crafter's Menu System
    15. Event Item Containers
    Im working on two others at the moment too. Xpanded Event Control is the only one that is not finished on that list. I moved my proximity and line of sight systems into it, I figured they were relevant. Anyways thanks again MobiusXVI for the attempt and finding the other typo.

    The bug is being caused by the viewable? method above or this method which is also being call. (from what was a different script.)

      #--------------------------------------------------------------------------  # * Returns the Direction of the Player From This Event  #--------------------------------------------------------------------------  def player_direction    character = $game_player    x = distance_x_from(character.x)    y = distance_y_from(character.y)    if x.abs > y.abs      direction = (x > 0 ? 4 : 6)      direction = (y > 0 ? 8 : 2) if y != 0    elsif y != 0      direction = (y > 0 ? 8 : 2)      direction = (x > 0 ? 4 : 6) if x != 0    end    direction  endI've also updated the original script post above.
  8. Thank you Cremnophobia, you found another typo that I didn't catch.

      #------------------------------------------------------------------------  # * Return All Comments  #------------------------------------------------------------------------  def return_all_comments    comments = []    @list.each { |command| comments.push command.parameters[0] if command.code == 108 } if @list    return comments  end  Now that part works as it should but the "viewable?" method is still an issue.

    Sorry for the double post but they replied mid-message.

    I've updated the demo and the script.