Trying to make a guard who chases the player

● ARCHIVED · READ-ONLY
Started by Irather 7 posts View original ↗
  1. Hi!

    I'm trying to make a guard who chases the player. I got the part where the guard is moving to the player (which is really easy to do), but due to no idea how to achieve the player getting caught, I tried scripting it.

    This is my script, but something is wrong with it.:

    (Never tried scripting before)

    if GuardX == (PlayerX - 1) or if GuardX == (PlayerX + 1) or if GuardY == (PlayerY - 1) or if (GuardY == PlayerY +1) then $game_self_switches[[14, 1, 'B']] = trueHere is the full event page:



    What's wrong with my script? Or is there a much easier way to achieve this?
  2. You do not need Scripting to do this.

    Merely go to the Event page for the chase, and in Movement, Set Move Route [whatever event is your guard] to move toward player. Be sure the "Wait for completion" box is unchecked. If you like, set the speed higher before he starts moving to make him go faster.

    You can have something happen if you're caught by having an event for the guard set to "player touch" When used with the guard sprite it will trigger when he touches you.

    . If you plan on using the guard for something else and don't want to worry about it happening every time you touch, set it up with a switch that's triggered by your chase event.

    Edit: Correction; make it "Event Touch" instead of "Player Touch". Sorry about that. .__.
  3. Player touch works when the player moves on the event - for this it's probably better to use "event touch" as that works when the event moves on the player.
  4. Oh, you're correct! Thanks for that! ^.^
  5. I think you meant "event touch", but the problem with this is that when the guard is exactly next to the player, I have to wait another move until the guard catches me. Under this time, the player can easily escape. What I would like to do is that at the exact moment when the guard is next to the player, he will catch him. (Bwah, this sentence was really hard to put together.)
  6. even if you want to do that, you're better use the script option of a conditional branch instead of the script box, it's easier to control the switches that way.


    And don't forget to include a wait in your parallel processes, you don't need to check the positions sixty times per second (which is how often parallel processes are executed without waits)


    Edit: your problem with the script box is probably that some commands get broken if they are spread over two lines, better check in different ifs or branches)
  7. I think Chiaster's solution is the best one unless you are using this as a common mechanic in your game.

    If you insist on going the scripting route, make sure you fix your condition checking.  Aside from line breaks (as Andar mentioned), your check is suffering from incorrect logic.  If the guard is six spots behind you but one to your right, it thinks you've been caught.  Even if you replaced the second 'or' with an 'end', then you'd have the case where a guard right behind you (one space behind, zero to your left or right) would not catch you.

    Here's a good Script command that could replace your entire event content (except for the 1-frame Wait which you should add in)

    a = $game_map.events[event_id]

    b = $game_player

    c = (a.x - b.x).abs

    d = (a.y - b.y).abs

    if ((c <= 1) && (d <= 1))

    $game_self_switches[[14, 1, 'B']] = true

    end