Aller au contenu

Photo

Advice on a Hiding Script


  • Veuillez vous connecter pour répondre
15 réponses à ce sujet

#1
Shaughn78

Shaughn78
  • Members
  • 637 messages
So here is the scenario:

I have six wandering neutral creatures. The player and cohorts have to sneak through the area without being seen or an event will happen.

I am trying to figure out the best way or most effecient way to put this script together. I have looked at several ways, but haven't been overly thrilled with them. I haven't started any scripting yet, trying to find the best format then I will write the script.

Here are some ideas I've kicked around:
-Have each creature have a unique heart beat that will check near objects (PC and party) and run checks.
-Have a master script on an ipoint that uses a loop to find each party member then check is they are close to a creature and run the checks.
-Or have the master script find the creatures then check for the party members. Or is there even a better way.
With these method I will need to account for a character being near multiple creatures and doing a check with each one, or a creature being near multiple characters and doing a check for each one.

Each of the 6 creatures has a unique tag so they can have individual walkpaths. That way the player can time their advance.

#2
kamal_

kamal_
  • Members
  • 5 254 messages
OnPerception

#3
Shaughn78

Shaughn78
  • Members
  • 637 messages
The issue I have with on preception is that it will fire only once per party member, but if the character succeeds that check and they hang around within range of the creature it won't continue to fire and they could just shadow the creature.

#4
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
kamalpoe's right, the on-percep script is the way to go. You can either modify the default or make up your own, depending on how much of the normal AI you want to use.
The game isn't terribly nuanced when it comes to sneaking around though, basically it just does a listen and spot check for every creature within the perception radius every turn. I use triggers to give the PC a hide bonus depending on terrain, but you might try something a bit more complicated, like an area of effect that gives a hide or move silently penalty to creatures near your sentries.
Another trick is to use SetActionMode to turn off stealth mode once the PC has been spotted.

#5
Shaughn78

Shaughn78
  • Members
  • 637 messages
Lagaid, I ran a test and the preception will only work when the character runs into the range. I need something to keep firing, that is why I am looking at heartbeats. I plan on throwing out the AI on these creatures as it is part of a non-combat area i am working on. So i will be creating my own checks for spot, listen, invisibilty and stealth and all that other junk.

With my test I was able to shadow the creature for several minutes with no preception firing.

#6
Shaughn78

Shaughn78
  • Members
  • 637 messages
I guess I am basically looking for performance advice.

-Is it more efficient to run the 6 creature HB and use a loop to find the party members and run checks if they are within X distance.

-Run a loop to id party members then loop through the 6 creatures to see if they are within the distance and run hide checks. Or run the opposite. ID creatures first then run through party members.

Is it bad to have a loop within a loop?

#7
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I think your numbers are small enough that a loop within a loop won't create any lag. Essentially, you're just doing a set of checks, 6 NPCs vs 5 or so PCs, or just 30 checks. Percep checks only induce lag when everyone is perceiving everyone else (i.e. 11x10, or 110 checks in this setup).
6 seconds is a bit long to wait, though, so you might want to set up a pseudo heartbeat to run the check every 1 or 2 seconds.
You could also use triggers to limit when and how the checks are made. A simple way would be to have a big trigger that covers the whole sneaking area, and which toggles a variable when the party enters and exits. As long as the party is in the area, the heartbeat runs the checks. That way, you don't have to constantly recalculate distance.
A more intricate approach would be to litter the area with triggers, each of which does a check on-enter, between the entrant and a particular creature, no heartbeats required.

#8
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
I'd go with HB. On perception works great for a one time type thing when a player comes into the perception range of the creature/npc but that's about it.

If you need a function to see if the npc is facing something in particular you could use something like this in it's HB:


int GetIsFacingTarget(object oSelf, object oTarget, int nViewArc);
int GetIsFacingTarget(object oSelf, object oTarget, int nViewArc)
{
    location lSelf = GetLocation(oSelf);
    location lTarget = GetLocation(oTarget);
    float AngleOffset = VectorToAngle(GetPosition(oTarget) - GetPosition(oSelf)) - GetFacing(oSelf) ;
    return (abs(FloatToInt(AngleOffset)) <  nViewArc/2);
}


Good luck.

#9
dethia

dethia
  • Members
  • 146 messages
PERCEPTION DOES NOT FIRE ONLY ONCE. IT fires a lot of times over and over.

#10
Shaughn78

Shaughn78
  • Members
  • 637 messages
I went with the individual creature heartbeats and it is working fine.

The issue with preception is that I am trying to create the conditions of when an character is preceived and I am ignoring the normal game mechanics that would cause the precieved script to fire.

#11
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

dethia wrote...

PERCEPTION DOES NOT FIRE ONLY ONCE. IT fires a lot of times over and over.


Unless this is a change from NWN1, and to my knowledge it hasn't, what we're saying is that it only fires ONCE while entering the perception range of the creature/npc. The player would have to leave the perception range(no longer be seen or heard by said npc/creature) then reenter the perception range again. It does not repeatedly fire like an HB would. In some cases this is fine. However in many cases this does not work well for what a person needs to happen.

Modifié par GhostOfGod, 16 mars 2011 - 05:25 .


#12
kevL

kevL
  • Members
  • 4 070 messages
um, yer both kinda right

I'm using a custom onPerception script that gives a SendMessageToPC() whenever it fires. It usually fires two or three times on entering LoS (line-of-sight), and again once or twice on leaving. But while remaining distinctly inside (or outside) LoS it won't fire off.

#13
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Hmm...most likely reason it fires 3 times would be to do all perception checks? Seen, Heard and Vanished? My best guess anyway.

#14
kevL

kevL
  • Members
  • 4 070 messages
most likely. i mean, it's odd

usually it fires twice in instant succession (Seen, Heard perhaps), then as PC approaches closer it cliks over yet again, and again. (But sometimes not) It's odd ..

I'm using it to increase TumbleDC - rather, to decrease Tumble Skill. This thread has been giving me ideas on how to make it less kludgy.

#15
Dann-J

Dann-J
  • Members
  • 3 161 messages
I've had a bit of success in forcing a re-perception by making creatures temporarily blind and deaf in their heartbeat script. I have some fish, eels and sharks in an upcoming module that are usually of neutral alignment, but only become hostile when the player enters the water. I initially had trouble getting them to attack from their custom OnPerceived script (which checks the perceived creature's Z height relative to their local 'water level' variable), since often the PC would be within perception range at the edge of the water. They weren't being re-perceived when they entered the water, so there was no hostility.

Making the fishies blind and deaf for one second in their heartbeat script seems to make them re-perceive anything in range when they recover - at least most of the time. I still get the occasional shark that lets you approach it. Putting the creature to sleep for a second works a lot better (they re-perceive every time), but has the downside of causing the sharks to roll onto their backs in a death posture every round.

#16
rjshae

rjshae
  • Members
  • 4 497 messages
You could have the perception script fire off a simple recursive call that checks if that party member is still in range. If true, make another perception check (with a penalty?), then call itself six seconds later on a failure. Otherwise, exit the call.

Possibly this may need to run on the area or an invisible object, rather than the creature, to avoid the action being cleared(?). You might also use local object variables to make the party member lookup efficient. Just thinking out loud here...

Modifié par rjshae, 17 mars 2011 - 10:38 .