Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Event Sighting

I need a little help with scripting. I don't think it can be done with events.

What I want to do is make it so that if someone sees you, then you get "caught". Is there a way to make it so that the event knows that it sees you without adding events beside the character that has to be stepped on?
 
At least 2-3 spots away...

I think it would require random variables to be set to a direction, and when an event is stepped, it would check to see if that variable(direction) is looking at you. But that's just too much, and I want less events then I can make possible on the map to prevent slowdowns..
 
Just made this, hope it helps :)

Copy and Paste this above main.
Code:
class Game_Event

  def get_vision(range)

    result = false

    p = $game_player

    case @direction

    when 2

      if p.x == @x and p.y > @y and p.y <= @y+range

        result = true

      end

    when 4

      if p.y == @y and p.x < @x and p.x <= @x-range

        result = true

      end

    when 6

      if p.y == @y and p.x > @x and p.x <= @x+range

        result = true

      end

    when 8

      if p.x == @x and p.y < @y and p.y <= @y-range

        result = true

      end

    end

    return result

  end

end

 

class Interpreter

  def ev

    return $game_map.events[@event_id] if @event_id != 0

  end

end

 

In your event, use a Conditional branch, put 'ev.get_vision(RANGE)', without the quotation marks in the text field, where RANGE is the number of tiles they can see.

eg. ev.get_vision(4)
That event can see 4 tiles away.

EDIT: You will need it to be running parallel process to pick it up.
 
Hey thanks for this!

I'll post if there are any problems...

EDIT: Works nicely! I was confused at first because you said put it into the text field..but I put it into the script box for conditional branch and it works fine!
 
There is a small problem.

I'm able to still move some when the script activates...

And also, the range doesn't seem to matter as I can still be seen regardless. Even if the event isn't in the windows view..
 
If you're looking for a Event-Coded view range script, I can give you an example which my game uses.

http://imageshack.us/f/708/viewrangeevent.png

On the second page (requirement Local Switch A on) put whatever you want to happen when the PC gets seen by the event. In this example, the NPC can see up to 4 squares away. You might want the monster to be able to see less, in which case you should lower the 4's (or increase them if you want him to be able to see farther.)

You might want facing to matter, if so you should divide that giant conditional branch into 4 conditional branches, each containing different numbers for view ranges depending on the direction that the enemy is facing.
 
Yes, I thought of something similar. But I want to have as less events possible. So what I did what take adventage of the bug in that script and make the event "face" me when noticed.
 
To stop the player from moving:
Set 1 page with default triggers and parallel process
Another with Self Switch 'A', autorun

On the default page add the text 'ev.get_vision(4)' into the Conditional Branch script box.
Then add the Self Switch 'A' ON underneath

On the Self Switch 'A' page, make sure it's autorun. Autorun stops the player from moving.
Then add your stuff there.

Having it run like this means you can do some pretty awesome stuff.
Like people hiding behind trees, that only chase you after you walk past, etc, not freezing you if you don't want.
 
I'm sorry - I just added the script to my game and I see the bug. Here's the fixed copy!
Code:
#===============================================================================

# SEE RANGE SCRIPT

#===============================================================================

# Put ev.get_vision(RANGE) in a script call or conditional branch.

# eg. ev.get_vision(3)

#-------------------------------------------------------------------------------

 

 

 

 

class Game_Event

  def get_vision(range)

    result = false

    p = $game_player

    case @direction

    when 2

      if p.x == @x and p.y > @y and p.y <= @y+range

        result = true

      end

    when 4

      if p.y == @y and p.x < @x and p.x >= @x-range

        result = true

      end

    when 6

      if p.y == @y and p.x > @x and p.x <= @x+range

        result = true

      end

    when 8

      if p.x == @x and p.y < @y and p.y >= @y-range

        result = true

      end

    end

    return result

  end

end

 

class Interpreter

  def ev

    return $game_map.events[@event_id] if @event_id != 0

  end

end

 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top