[XP] AVOIVING THE GUARDS
Posts
Pages:
1
This is one of the oldest challanges in RPGs. Walk into a dungeon or prison, avoiding the guards seeing you. If they do, then it's "I see you" and start over. Is there a way to do this using events? I can't find anything in the conditional branches that even allow for such things.
...well, someone will tell you much better than I can (sorry, started this post and realized it was a bit more complex than I thought).
You need to find the direction that the guard is facing, the distance between the guard and the player, and whether or not any obstacles are in the way. The last issue is likely the hardest to solve.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
I will say that using scripts it is much simpler. As in, it's only one line of event commands, with no variables, because the script already did all the work for you.
You need a script called "View Range Module", written by Near Fantastica. Instead of sending you around the internet hunting for it, I'll just paste it here:
Add that script to your game by opening the scripts screen, then inserting a new page of scripts somewhere above Main, and pasting that script code into the empty page.
You can then make the sentry event a parallel process. Give it a conditional branch, with the condition being the script line:
5 is the number of tiles away the hero can be. Change the 5 to some other number if you want. This will make anything in the conditional branch only happen when the event is facing the hero and less than 5 tiles away.
If you want the guards to only see the hero if they're looking directly at him - as in, if he's diagonal from the guard, they can't see him - use this line instead:
If you want walls to block vision, you're going to need to find a pathfinding script and do something a lot more complex, or else just make all the walls thick enough that the guards' sight range doesn't go through them.
You need a script called "View Range Module", written by Near Fantastica. Instead of sending you around the internet hunting for it, I'll just paste it here:
#============================================================================== # ■ View Range Module #============================================================================== # Near Fantastica # Version 4 # 29.11.05 #============================================================================== #-------------------------------------------------------------------------- # * SDK Log Script #-------------------------------------------------------------------------- #SDK.log("View Range", "Near Fantastica", 4, "29.11.05") #-------------------------------------------------------------------------- # * Begin SDK Enable Test #-------------------------------------------------------------------------- #if SDK.state("View Range") == true module VR #---------------------------------------------------------------------------- def VR.in_range?(element, object, range) if range == 0 return (element.x == object.x and element.y == object.y) end x = (element.x - object.x) * (element.x - object.x) y = (element.y - object.y) * (element.y - object.y) r = x + y if r <= (range * range) return true else return false end end #---------------------------------------------------------------------------- def VR.range(element, object) x = (element.x - object.x) * (element.x - object.x) y = (element.y - object.y) * (element.y - object.y) r = x + y r = Math.sqrt(r) return r.to_i end #---------------------------------------------------------------------------- def VR.facing?(element, object, direct = false) if direct case element.direction when 2 # DOWN return true if (object.y > element.y) and (object.x == element.x) when 4 # LEFT return true if (object.x < element.x) and (object.y == element.y) when 6 # RIGHT return true if (object.x > element.x) and (object.y == element.y) when 8 # UP return true if (object.y < element.y) and (object.x == element.x) end else case element.direction when 2 # DOWN return true if (object.y > element.y) when 4 # LEFT return true if (object.x < element.x) when 6 # RIGHT return true if (object.x > element.x) when 8 # UP return true if (object.y < element.y) end end return false end end #============================================================================== class Interpreter #---------------------------------------------------------------------------- def event(id = nil) id = @event_id unless id return $game_map.events[id] end end #-------------------------------------------------------------------------- # * End SDK Enable Test #-------------------------------------------------------------------------- #end
Add that script to your game by opening the scripts screen, then inserting a new page of scripts somewhere above Main, and pasting that script code into the empty page.
You can then make the sentry event a parallel process. Give it a conditional branch, with the condition being the script line:
VR.in_range?($game_player, $game_map.events[@event_id], 5) and VR.facing?($game_map.events[@event_id], $game_player)
5 is the number of tiles away the hero can be. Change the 5 to some other number if you want. This will make anything in the conditional branch only happen when the event is facing the hero and less than 5 tiles away.
If you want the guards to only see the hero if they're looking directly at him - as in, if he's diagonal from the guard, they can't see him - use this line instead:
VR.in_range?($game_player, $game_map.events[@event_id], 5) and VR.facing?($game_map.events[@event_id], $game_player, true)
If you want walls to block vision, you're going to need to find a pathfinding script and do something a lot more complex, or else just make all the walls thick enough that the guards' sight range doesn't go through them.
I currently have it evented for my Halloween entry and I can tell you it's a pain in the ass. LockeZ's script will be much, much easier and probably less buggy.
Pages:
1