Larian Studios
Posted By: TheSpartanShow BoxTrigger closes door - 14/10/17 04:08 AM
I am trying to figure out how to implement a script that closes a door if no one (player or npc) is in the box trigger. So when player or npc walks off of the BoxTrigger the door will close.

This will be my first script so if you could help me as to how to setup the script that would be helpful as well. Thanks!
Posted By: Tinkerer Re: BoxTrigger closes door - 14/10/17 02:25 PM
I have documented the Osiris calls related to registering triggers and getting events from entering/leaving them: https://docs.larian.game/Osiris/API/TriggerRegisterForCharacter (you can find related calls starting from that page).

Since you want to track all characters' presence in that trigger, it's best to use an event trigger as mentioned in the Notes on that page. You can then use the following Osiris code:

Code
QRY
QRY_DoorIsOpenOrOpening((ITEMGUID)_Door)
AND
DoorIsOpening(_Door, 1)
THEN
DB_NOOP(1);

QRY
QRY_DoorIsOpenOrOpening((ITEMGUID)_Door)
AND
ItemIsOpen(_Door, 1)
THEN
DB_NOOP(1);

IF
// anyone leaves the trigger
CharacterLeftTrigger(_, TRIGGERGUID_S_YourBoxTrigger_UUID)
AND
// no one is left in the trigger
NOT DB_InRegion(_, TRIGGERGUID_S_YourBoxTrigger_UUID)
AND
// the door is currently open or opening
QRY_DoorIsOpenOrOpening(ITEMGUID_S_YourDoor_UUID)
THEN
ItemClose(ITEMGUID_S_YourDoor_UUID);

For details on how to structure your Osiris code, please see https://docs.larian.game/Osiris_Design_Patterns#Program_Initialisation

Edit: For a more concrete start on setting up your story scripting, see Windemere's https://docs.larian.game/Tutorial_-_Implementing_a_Basic_Quest
© Larian Studios forums