[XP] Super Event Sensor (Event NPC Advanced AI)

Started by Heretic86, November 27, 2013, 08:56:03 pm

Previous topic - Next topic

Helios

April 22, 2016, 06:39:26 pm #20 Last Edit: April 22, 2016, 06:41:29 pm by Helios
That's not the problem here. I know how switches and event page orders work btw, been playing around with RM series since 2008.

The problem here is when you switch page, their move route would reset. This won't be a problem for stationary guards, but moving guards would turn back and try to reach their first waypoint if you put the same move route on that page, or just stand still if you do not, and again go for the first waypoint when you leave their sight because they are on the first page again. The result looks like every guard is trying to avoid you. That's why I want to disable the "Sensor_Config" entirely. Nevermind. I just realized its more about Path Finder than SES. I'll make do with that.

Heretic86

No problem.

Handling Pathfinding with SES was tricky when the script was built because the Pathfind was cleared between page changes.

Aside from that, the whole explanation of Switches and Pages wasnt directed at you specifically.  As this is a public support question, you probably wont be the only one probably with similar questions, so answers like that are intended to help out people who may be reading our conversation in an effort to resolve the same issue.  Some of those other people may or may not have a strong grasp of what Event Pages and Page Conditions are, so it just tries to provide ideas of doing things as simply and easily as possible.  Unfortunately, sometimes that involves using additional scripts to do things that may not have been considered.

If you still need any help, let me know.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Helios

May 01, 2016, 11:09:07 am #22 Last Edit: May 01, 2016, 11:18:20 am by Helios
After some analysis of your script, I figured out how to disable and enable SES on the fly.

Find this line, should be somewhere around line 1505.
return if not @enabled or $game_map.events[@id].starting or not @target

add a switch check:
return if not @enabled or $game_map.events[@id].starting or not @target or $game_switches[123] == true

and turn that switch on to disable SES.

Actually it didn't disable the entire script, it just make the guards stop caring about you (and pretty much everything else).

Then, on the "GUARD TRIGGER BATTLE" page, add something to differ the guards reaction:

if $game_switches[123] == true
"peaceful dialog"
else
"BATTLE"
end

Then edit the move route:
change
@move_type = 2

into
$game_switches[123] ? $game_system.map_interpreter.self_switch("D", false, @id):@move_type = 2
$game_switches[123] ? $game_system.map_interpreter.self_switch("huh", false, @id):@move_type = 2


This will prevent them from chasing you after "peaceful" dialog, especially if you use Multiple Message Windows "Auto-close" function.

Ta-da! You can now put on/off disguise by turning that switch.

Helios

December 23, 2016, 07:46:54 am #23 Last Edit: December 23, 2016, 07:48:09 am by Helios
Hi, it's me again.  :haha:

Recently I have observed another issue: stationary guards won't change direction after returning to post.

This is the movement setting of Page 1:
PathFinder.dyn_request(@id, [13, 47],0,true)    <----  So they would return to their post after giving up the chase.
wait 1 frame
face Left    <---- not working, the guard would return to 13,47 but does not change direction, usually facing the wall at this point, which would make subsequent sneaking attempts hilariously easy. :facepalm:

I think this might be caused by the Lagless Path Finder, but can't nail down the exact reason.

KK20

It has nothing to do with either of the scripts--your eventing is the problem.

When you use the script call the dynamically path find, the event commands don't just stop there and wait until the event reaches its destination. The event will keep running through its commands. Basically, frame 1 you make the path request and call the Wait event. Then, frame 3 I believe (frame 2 would be if Wait was 0.0 sec) it will change the event to face left--which gets lost since the path finding script is currently moving the event.

I don't see anything in the path finder script that allows executing event commands upon reaching its destination, so you're going to have to find another way to event that in. Something like making a parallel process that checks if the event's coordinates are [13,47] then face left.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Helios

December 24, 2016, 12:56:01 am #25 Last Edit: December 24, 2016, 01:30:16 am by Helios
If I change

PathFinder.dyn_request(@id, [13, 47],0,true)

to

PathFinder.dyn_request(@id, [13, 47],1,true)

Then the turning command works. I add another "wait 60 frames" after the turning command to make the result more obvious, and the guard would do like this (after giving up the chase):

walk to the target tile
turn left
wait 60 frames
walk 1 tile away from the target tile
turn left
wait 60 frames

And then the guard would repeat the above. The turning command does work.

The same setting would fail to work if I change RANGE to 0. The guard would get stuck on the "walk to the target tile" part, without running the subsequent commands. I confirmed this by adding a "Play SE" command before "turn left". With RANGE 1, the SE plays every time the guard turns. With RANGE 0, the guard move to the target tile and does not turn, and the SE never plays.

BUT, this only happens when the guard is returning from giving up chasing the player. If the guard begins on a different tile other than the target tile when the map is loaded, and then move towards the target tile, it does turn when reaching it even if RANGE is 0. So I'm not sure which script is causing the problem now.

Heretic86

December 25, 2016, 05:12:28 pm #26 Last Edit: December 25, 2016, 05:31:32 pm by Heretic86
It might be easier to just use a move left or move right command if the guard is only moving one tile.  For example, Pathfind XY 20, 20, Wait 60 frames, Pathfind 50, 50, Wait 60 frames.  Pathfinding too close with a range of 1 would when only moving 1 tile would cause Pathfinding to be skipped.

One of the problems with Move Routes in general is that each Move Command (like Move Left or Move Up) don't have an option to make individual moves skippable.  They also dont handle conditions very well without scripting, but it IS possible.  Hence, why we have Pathfinding scripts.  There are some cases where the use of other tricks without Pathfinding calls is simpler to pull off.

Some of the Tricks I use when making complex Move Routes involve changing the Index to cause a loop to occur as a way of making a Conditional Branch to ensure event positions:

$>Turn Left
$>Wait: 15 Frame(s)
$>Script: @move_route_index -= 2 if @x != 27 or @y != 53
$>Move Left

Using a "@move_route_index -= 1" will ALWAYS cause your game to hang so ALWAYS adjust a Move Route Index by 2 or more.
(NOTE: Pathfinding scripts generate their own Move Routes so Index adjustments are not recommended)

---

One other thing that may be worth while to note is Pathfinding sometimes fails if the Player (or Caterpillar) is standing at the location an event is trying to Pathfind to.  I may have to do some work to allow Character Events like Guards to pathfind correctly even if the Player is at the location an event is trying to pathfind to.  That is usually the reason that a Range of 1 is needed for correct pathfinding.  Current possible untested workaround, Pathfind to a location with a range of 1, Wait a frame, then pathfind again to the same location with a range of 0.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Helios

December 25, 2016, 06:58:37 pm #27 Last Edit: December 25, 2016, 07:02:19 pm by Helios
Thank you for your reply.

I think a demo would explain better so here it is.

https://mega.nz/#!dZE0EAzB!NMBY8O4tEoBPlq-8D-4NytkjsaWK65oeWwS1Qh385Lk

Note the guard on the left (with RANGE 0) walk toward the target tile and face left as commanded.
Now move the Player to the top of the screen. Wait for both guards to investigate then give up and return to their target tile.
The guard on the right (with RANGE 1) would walk up and down, but still face right as commanded.
The guard on the left will get stuck on the target tile without running any subsequent command (like face left). <--  This is the problem.
It only happens if the guard is returning from chasing. If the guard can't chase the player somehow (i.e. by extending both walls to the bottom of the map), or if the guard was undisturbed (like in the beginning), the guard would face left normally.

KK20

December 26, 2016, 04:32:35 pm #28 Last Edit: December 26, 2016, 05:58:09 pm by KK20
There definitely is something screwy. Everything checks out correctly up until the end of Page 2's move route. It jumps back to Page 1 after turning off the "huh" switch, but the @move_route_index variable doesn't start back at 0; rather it continues off to the next value it was before leaving Page 1 (EDIT: due to event sensor @move_route_index = @sensor.last_page_data[0]). Then, after returning to its spot, it jumps to using the move route in Page 3 while still interpreting Page 1, thereby hanging the move route processing (EDIT: caused by calling force_move_route, which stores the @move_route and @move_route_index to @original_* variables (and restores them after the event returns back to their spot)).

To see what I mean, please follow these dubugging steps:

First, add this script to the project: http://forum.chaos-project.com/index.php/topic,7816.0.html
In Game_Character 2, add this to move_type_custom, right under while @move_route_index < @move_route.list.size

      puts [@move_route_index, @move_route.list.size]
      puts "Page #{@event.pages.index(@page) + 1}"

Remove the right guard and playtest.

Throw in some commented scripts in the move routes too--it'll make the problem more obvious.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Helios

So ehhhh... how to fix this? I did what you said and still pretty clueless.

KK20

December 27, 2016, 11:49:11 pm #30 Last Edit: December 28, 2016, 05:58:49 pm by KK20
It's pretty much up for Heretic to decide. Clearly, there's an incompatibility going on here.

@Heretic: If you can make it so that the @original_move_route(_index) variables only get applied to the @move_route(_index) variables if the event is currently on the same page, this would probably fix it. Either that or just reset @original_move_route(_index) every time the page changes, perhaps?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Heretic86

I may have to look at this weekend.  A bit busy right now.

Are there any other scripts that affect pages or move routes that I didnt make?
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

KK20

Only other thing is the extra self switches but I am pretty sure that is not the problem.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Heretic86

It shouldnt be.

Just woke up, sort of thinking about this when Ive had time for a few days.  I think what has happened is if a space is occupied by an event when pathfinding by the player, the pathfind may fail.  Not sure.  Have a ton of code re-reading to look thru to see what is going on.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

KK20

Just repeat what I did in my test above. I only had one event on the map. I already told you the cause, you just need to find a reasonable solution to it.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Heretic86

I havent started work on a fix for this yet.  :(

Two known issues.  First is some trouble with Pathfinding.

#1 - If the spot a guard / npc pathfinds to is occupied by the player, pathfinding typically fails.  I may need to use Modular Passable to make a fix for that, but I am hesitant because I dont want to force dependancies.  Basically, a pathfinding event should not consider the Players position during a pathfind calculation (or caterpillar).

#2 - Move Route Indeces - Im thinking a possible solution to this would be to use a Hash and set the Page as a Hash Key to retain the Move Route Index across page changes.  Move Routes are already per page.  The Index resets properly, but when there are too many page changes, I think the wrong Index may be in use.

Before I start working on this, does this sound like an acceptable resolution to the problem?

Im sorry for the delay, been working a lot lately, and holidays, havent had much down time...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Helios

January 01, 2017, 06:15:37 pm #36 Last Edit: April 18, 2017, 08:58:01 pm by Helios
No problem, take your time. I'm not in any hurry. :)

Just make sure you try the DEMO I posted above when you are ready to work on this. No need to take guesses here.

The first is not the case - pathfinding is successful, problem occurs after the successful pathfinding.

Not sure about the second - although there are 8 pages in the guard event, only the first 3 are actually activated, and the guard did use the first page's move route so I think page/index switching is also successful, or at least partially.


=================================================

Eh, it's been 3 months... any news?

Denver

Hello, Heretic86! First of all, thank you very much for your Super Event Sensor script, it is just perfect for my project! Now forgive me if I am being dumb, but I just cannot figure out how to make the event go back to its starting position when the target is out of range. My event has 3 pages:

- Page 1 has a custom move route (it is not stationary) and the sensor comment (Sensor_Config;range=4).
- Page 2, which is triggered by self-switch A, has the approach route and the battle processing on event touch.
- Page 3 is triggered by self-switch B but it is just an empty page for when the enemy is defeated.

When the player is out of range, the event does not go back to its starting position but instead stays exactly where it lost track of the player. I am not using a path finding script so far. Do I need to use one? Would you please help me? Thanks in advance!

KK20

June 07, 2017, 11:05:51 am #38 Last Edit: June 07, 2017, 09:15:08 pm by KK20
You mention the event moves towards the player. Where and how are you making the event move back to its starting location?
I get the question now...

Yes, you should use a path-finding script since it's not built-in to RMXP's default move event commands.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Heretic86

Quote from: Denver on June 07, 2017, 10:06:15 am
Hello, Heretic86! First of all, thank you very much for your Super Event Sensor script, it is just perfect for my project! Now forgive me if I am being dumb, but I just cannot figure out how to make the event go back to its starting position when the target is out of range. My event has 3 pages:

- Page 1 has a custom move route (it is not stationary) and the sensor comment (Sensor_Config;range=4).
- Page 2, which is triggered by self-switch A, has the approach route and the battle processing on event touch.
- Page 3 is triggered by self-switch B but it is just an empty page for when the enemy is defeated.

When the player is out of range, the event does not go back to its starting position but instead stays exactly where it lost track of the player. I am not using a path finding script so far. Do I need to use one? Would you please help me? Thanks in advance!


I would actually recommend using a pathfinding script.  There are two to choose from in the Collection so you should have both.

On Page 1, instead of using standard movement commands, instead, have your event pathfind its patrol route.  That will allow your character go back to where they were before they saw the player.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)