Page 1 of 1

Animals Random Walking and Persistent Storage

Posted: Thu Aug 19, 2010 12:56 am
by Brayon
I was asked to help a friend of mine build a mod for personal playing. And I'm stuck trying to do a couple of things.

First, how do you make animals which are static to an area, not encounter spawns, randomly walk? Not looking for way-points, just have them walk around a bit.

Second, without using a ton of DB systems, as this is coding for dummies, how can you make persistent storage using the default Bioware DBs?

Thanks folks. :-)

Re: Animals Random Walking and Persistent Storage

Posted: Thu Aug 19, 2010 1:54 am
by Gorgon
I really wouldn't bother with the Bioware db stuff. NWNX is quite easy to install and setup, and it has its own sqlite db built in. I think it comes with a test mod as well that has example chests to see how things work.
http://www.nwnx.org/index.php?id=doc_nwnx#IV

I was surprised how simple it was to install and setup the first time, though I do suggest moving to something like MySQL if you get more serious about it on Windows (even that was simple to switch to following the instructions for both). The documentation on the nwnx site has instructions for both.

Re: Animals Random Walking and Persistent Storage

Posted: Thu Aug 19, 2010 7:31 am
by Moredo
You're looking for the ActionRandomWalk(); script. ;)

Re: Animals Random Walking and Persistent Storage

Posted: Thu Aug 19, 2010 4:26 pm
by Buddha
Brayon wrote:First, how do you make animals which are static to an area, not encounter spawns, randomly walk? Not looking for way-points, just have them walk around a bit.
Right-click them in the toolset and go to their properties. Add the variable X2_L_SPAWN_USE_AMBIENT as an int variable with a value of 1 to give them ambient NPC animations. Not sure how this will work on animals, but it should work fine and make them wander around. If they wander too far, try setting the variable NW_ANIM_FLAG_IS_MOBILE_CLOSE_RANGE with a value of 1 in addition to the first variable. You may want to read up on that second one. Something in my brain is tickling that you need to put down some sort of HOME waypoint to make it work. A quick Google search should tell.

Re: Animals Random Walking and Persistent Storage

Posted: Thu Aug 19, 2010 4:30 pm
by terror2001
You don't want just ActionRandomWalk in a heartbeat script. You want them to randomly walk around when they are not in combat or in a conversation, but only if PC's are in the area, so they're not chewing up system resources with pathfinding, so that takes a little more code.

Code: Select all

int CheckForPlayersInArea( object oCreature ) {
    object oPC = GetNearestCreature( CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oCreature );
    if( !GetIsObjectValid(oPC) )
        return 0;
    return 1;
}

int CreatureBusy( object oCreature ) {
    return GetIsInCombat(oCreature) || IsInConversation(oCreature);
}

void main()
{
    if( !CheckForPlayersInArea(OBJECT_SELF) || CreatureBusy(OBJECT_SELF) )
        return;

    ActionRandomWalk();
}

Re: Animals Random Walking and Persistent Storage

Posted: Thu Aug 19, 2010 5:44 pm
by Brayon
Thank you folks. :-)

Re: Animals Random Walking and Persistent Storage

Posted: Fri Aug 20, 2010 5:39 am
by Horred the Plague
All the stock tricks, along with the variable names, are listed in x2_inc_switches script. Yes, RandomWalk() works well with animals, I know of several using it on a certain server when not evaluating if a person perceived is a druid/ranger. It's usually called from their on perception script; if an animal doesn't see or hear an intruder, they random walk. You should even be able to see it in stock nw_c2_default2 script I believe (Bioware's stock on perception script). You can even use the perception script itself to host a shutoff for the random walk, with a procedure quite similar to Terror2001's above.