Getting creatures to move around when PC's are not around

My eco-system should make creatures constantly move around and interact with world objects even without PC’s in the world, but they only seem to actually start doing it after my PC enters the area where they were created.

When I run “GetObjectByTag” after I launch the module, it indicates that the creatures exist(have been successfully created by the create object script that launches when I load the module), but they only start their behavior after I enter the area (their behavior is mostly indicated on their OnHeartbeat)

How can I make them go even without PC’s in the area?

Try commenting out this line in their OnHeartbeat handler:

    // * if not runnning normal or better Ai then exit for performance reasons
    if (GetAILevel() == AI_LEVEL_VERY_LOW) return;

On a creature with unset AI level or ai level set to -1 (default or invalid), function returns AI_LEVEL_LOW when there is a player character in same area as creature or AI_LEVEL_VERY_LOW when not.

You can also maually set their AI level with SetAILevel().

Note that the same line is also in the default OnPerception handler.

1 Like

Consider the implications, though. Throughout the module, your creatures would be acting the entire time, without anybody around to see it. Making a habit of setting up things like this is a good way to create lag.

Suggestion: Instead, use timestamps and calculate expected changes according to passed time since the last time a PC has been in the area. Creatures’ starting positions can be randomized, giving the illusion of change.

1 Like

Thanks! I’ll give it a shot :slight_smile:

Yes I am worried about lag and performance, I suppose I’ll have to see how big of a deal it is. Right now I’d prefer not to “create the illusion” but have it actually happen to see how bad the lag can get. I know it seems useless if nobody is watching them, but I have some vague future ideas of how to use it and I prefer to go with the worst case scenario before I’ll favor performance over “dynamicability”

1 Like

As a nuance on the core idea here, you can jump the NPCs to random locations when a PC enters the area again. This saves some computation. Few players can tell the difference, I suspect.

Keeping AI level low in unobserved areas is good for performance. It may even be beneficial or convenient to destroy the NPCs and respawn them.

1 Like


If there is a small number of NPCs you really want to move around you can explicitly set them to a higher AI level rather than removing those checks from the base scripts. But respawning or placing randomly on enter are often better for performance.

1 Like

I get that your criticism is valid, but let me tell you what I’m trying to do.

So, the current idea is that I will be able to watch the gameworld change/evolve even with 0 players playing. So, currently I just want to be a viewer of the world I built. Ideally I would have several cameras and could watch several areas at the same time and see how things are changing, like a god with a control panel, but I reckon it’s impossible since 1 account = 1 camera.

But for a lighter version of the concept, let’s I want to run a script where I would be able to track the “action”…for instance, if there are many creatures in the same area, the camera will automatically move there to watch them. That’s just one example. Or maybe I’ll want to track the life of a beetle as it goes around the world, as boring as it may seem to you (though I’m not sure if a possessed creature (or even a DM) can trigger higher AI behavior by their presence?).

You can do whatever you want. It’s your module, I was not being critical, just sharing experience.

But you have expressed concerns about HB performance. You aren’t going to be able to have a world full of high AI creatures running scripts and doing stuff all the time without paying for it. Now, if it’s just for you to watch and see it all move, cool. You probably won’t be too badly effected. That can be fun too. I love the full ambient city module that’s around somewhere, all the NPCs constantly doing their thing, going home at night, coming back to work in the morning etc. But it can be dog slow.

And actually for your purpose you may be better off with the global change as it won’t have bad effects on combat. Maybe your beetles will want to fight some. Just be aware that all those HBs will take their toll eventually.

Well, we agree it’s a matter of quantity. If I have 40 fully active NPC’s and 10 active players, I think it won’t lag out too much. I mean, you have 60 players servers running smooth and I reckon PC’s cost much more lag than NPC’s.
At any rate, I’m not planning go overboard with quantity. I realize there are limitations, but I will probably graze those limitations on occasion before I scale back.

PCs are human-bound, they usually do only as many actions humans can perform, while single NPC, for example with a heavy HB loop (or simply a badly written loop), can quickly become a resource hog. If nobody is there to witness what it does, those CPU ticks could be spend elsewhere (and you have just 1). But you should definitely go overboard if that’s what gives you the joy. The game is for people, not the other way around. Start optimizing when slowdowns become a nuisance.