Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Veiw Range Script
#11
So I was gonna try and keep this from taking up a post slot, but apparently I can't message, send email or anything else as a member lol so...
I slapped in the script (ETA) and filled out the script $view_range.enemies_view(ev_id, v_range, sw_id, s_sw_id, block) with: (1, 8, 60, nil, true). when event 1 detects switch 60 is on, it goes nuts and chases the character, which is fine, but, it's refusing to have LOS blocked by non-passable objects.
I tried true and false, just to make sure there wasn't a typo, and even fully encased the character in impassable wall blocks. still the event goes nuts chasing the character. any input?
also, when trying to use a self switch "a" I get an error "undefined local variable or method for 'a' for #<Interpreter:0xa1a3118>" same with "A". (quotes not used)
idea of what i'm doing wrong? everything looks right, script looks right to my half trained eye...
Reply }
#12
I spent about 5 hours working on a similar bug with my own "line of sight" code. Does it work when the walls are 3 tiles thick? if so, then you have the issue where the monsters are peeking through the diagonals of walls. I can give you an alternate algorithm if that turns out the be the problem.
Reply }
#13
tried three blocks thick, and 1st, second and third layer (just in case), and putting the player ON an impassable, and dude just runs himself into the wall repeatedly. Sarcasm
Reply }
#14
perhaps then you have done something wrong? Try putting the player, a wall, and the enemy in a straight line and see what happens.
Reply }
#15
oh my, it IS peeking diagonally.
did the single box in front, and it didn't register, but tried

C = character
B = impassable object
E = event

C
.....B
..........E
and it found me.

edit: this set up doesn't like spaces.
edit again: nope, that wasn't the cause either.
seems to just plain act weirdly. character encased in a square of impassable blocks 7x7 with an open center, or a single square diagonally, it'll see it. but with a single line of blockes, it won't, until the y axis is next to each other. say at the end of a wall 7 long, when...
C
..BBBBBBB
..................E
it won't see, but

CBBBBBBB
...................E

it will.
Reply }
#16
I knew it! See, what is happening is this:
[Image: vfaEb.png]

when it should be doing this:
[Image: XB639.png]
Once I get home from work I'll show you the algorithm that checks for blocked tiles, instead of checking if a direct line is blocked.
Reply }
#17
again, you have to remember the part that's really messed up, is it's also detecting like...

*******
*******
***C***
*******
*******

where * = impassable block. and that shouldn't happen. at all.
Reply }
#18
Does this help any?

Code:
#----------------------------------------------------------------------------
  # * Get line of sight
  #----------------------------------------------------------------------------
  def line_of_sight?(xa, ya, xb, yb)
    dx = (xa - xb).abs
    dy = (ya - yb).abs
    x = xa
    y = ya
    n = 1 + dx + dy
    x_inc = (xb > xa) ? 1 : -1
    y_inc = (yb > ya) ? 1 : -1
    error = dx - dy;
    dx = dx*2 #do this to
    dy = dy*2 #get rid of fractions

    n.downto(0){ |i|
      if !$game_map.passable?(x, y, 0) #$game_map.terrain_tag(x, y) == 5
        return false
      end

      if (error > 0)
        x = x + x_inc
        error = error - dy
      else
        y = y + y_inc
        error = error + dx
      end
    }
    return true
  end
Reply }
#19
makes sense, up until i'm not sure what to do with it. do I form a class for it, and a branch call if true, is it supposed to plug into the script this forum regards? i'm working on the first idea until I know lol
Reply }
#20
sorry, I didn't know you weren't as script-savy as I am (actually I was just too lazy after work and hoped you would just magically know what to do)

Try replacing vr_in_range? with this:
Code:
#--------------------------------------------------------------------------
  # * In Range?
  #     element     : either player or other event
  #     object      : event looking for element
  #     range       : range in tiles
  #     pass_block  : if terrain tiles can block view
  #--------------------------------------------------------------------------

  def vr_in_range?(element, object, range, pass_block = false)
    # Obtain Range
    dx = (element.x - object.x).abs
    dy = (element.y - object.y).abs
    # Obtain values to loop and counter value
    x = xa
    y = ya
    n = 1 + dx + dy
    x_inc = (xb > xa) ? 1 : -1
    y_inc = (yb > ya) ? 1 : -1
    error = dx - dy;
    dx = dx*2 #do this to
    dy = dy*2 #get rid of fractions
    #check range
    r = dx + dy
    if r <= (range * range)
      # If tiles can block view
      if pass_block
        n.downto(0){ |i|
          if !$game_map.passable?(x, y, element.direction)
              return false
          end

          if (error > 0)
              x = x + x_inc
              error = error - dy
          else
              y = y + y_inc
              error = error + dx
          end
        }                  
      end
      # Return system-determined flag      
      return true
    else
      # Return default flag
      return false
    end
  end
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Text Scroll Script - Enhanced DerVVulfman 23 29,459 02-18-2021, 04:16 AM
Last Post: DerVVulfman
   Cursor Script Selwyn 7 12,968 09-28-2019, 02:13 PM
Last Post: DerVVulfman
   ACBS FIX SCRIPT #2: Advanced Cry Correction DerVVulfman 1 3,859 08-09-2019, 03:42 PM
Last Post: aeliath
   ACBS FIX SCRIPT #1: Victory Cries Patch DerVVulfman 1 3,849 08-08-2019, 02:53 PM
Last Post: aeliath
   Archived Script Listings DerVVulfman 9 33,320 01-08-2019, 04:27 AM
Last Post: DerVVulfman
   Spritesheet Generator Conversion Script DerVVulfman 0 3,535 11-21-2018, 04:48 AM
Last Post: DerVVulfman
   Neo Mode 7 Script by MGCaladtogel MGC 59 110,550 09-29-2017, 03:48 AM
Last Post: DerVVulfman
   Longer Script Calls LiTTleDRAgo 0 4,304 05-17-2017, 12:36 AM
Last Post: LiTTleDRAgo
   SLOLS: Snake Look-alike on Load Script Zeriab 3 10,086 05-14-2017, 06:25 PM
Last Post: LiTTleDRAgo
   Character Select Script Selwyn 3 9,399 03-07-2017, 04:14 AM
Last Post: JayRay



Users browsing this thread: