Jump to content

A day-night script for NPC


Recommended Posts

You know how NPC that are present in areas can have schedules? For example, the Nashkel Carnival empties after sundown, the next morning everyone reappears. That's very nice for the atmosphere, but entering NPC into ARE files as actors with all of the settings using Weidu is difficult and limits the number of NPC you can have in an area. Especially if you plan on doing something dynamic with NPC, like spawning them off-screen, quietly removing or replicating them, and so on. Here is a little script that you can insert somewhere in any creature's slot to make it appear and disappear at the right hours:

IF
    TimeOfDay(NIGHT)
    Global("ACTIVE","LOCALS",1)
THEN
    RESPONSE #100
        SetGlobal("ACTIVE","LOCALS",0)
        Deactivate(Myself)
END

IF
    TimeOfDay(DAY)
    Global("ACTIVE","LOCALS",0)
THEN
    RESPONSE #100
        Activate(Myself)
        SetGlobal("ACTIVE","LOCALS",1)
END

Of course, you can be more specific with hours - simply use Time() instead. You can add other conditions, too. For example, do not reappear if the party's reputation is below a certain value. This will make towns desolate around a villainous party.

Link to comment

Note that double caution needs to be exercised when employing Activate()/Deactivate()/IsActive() functionality. During SoD development it led with a significant margin in the number of caused issues, compared to any other scripting function.

In particular, I would add this after those two blocks to ensure no further script action would accidentally trigger while the actor is inactive:

IF
    Global("ACTIVE","LOCALS",0)
THEN
    RESPONSE #100
        NoAction()
END
Link to comment

Those functions were a complete nightmare in IWD-in-BG2 too - IWD handles spawning by Activate()ing already-present NPCs, but trying to duplicate that using BG2 triggers/actions was a huge bugfest. After several iterations I gave up and wrote code to auto-map all the inactive creatures to be spawned by area script instead, and iirc that code made it into IWDEE too.

Link to comment
On 9/6/2019 at 1:02 AM, Ardanis said:

Note that double caution needs to be exercised when employing Activate()/Deactivate()/IsActive() functionality. During SoD development it led with a significant margin in the number of caused issues, compared to any other scripting function.

In particular, I would add this after those two blocks to ensure no further script action would accidentally trigger while the actor is inactive:


IF
    Global("ACTIVE","LOCALS",0)
THEN
    RESPONSE #100
        NoAction()
END

Thank you, I will. What I'm tussling with right now is that deactivated creatures still display visual effects attached to them. I don't know if effects can attach to them while they are deactivated - the whirling things from Confusion, for example, and so on, hopefully not. But if they had them before, those graphics will still hover. This is really only a problem for a specific area, where a lot of these are handed out, and I think I'm going to put a block in the area script so it dispels those for everyone as soon as night comes. I'm open to alternatives, though.

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...