void main()
{
    // Get the creature that triggered the OnOpen event.
    object oUser = GetLastOpenedBy();

    // Check if the creature has the CAS_VIPBADGE or the I_CAS_STAFF_KEY.
    if (GetIsObjectValid(GetItemPossessedBy(oUser, "CAS_VIPBADGE")) ||
        GetIsObjectValid(GetItemPossessedBy(oUser, "I_CAS_STAFF_KEY")))
    {
        // Unlock the door.
        SetLocked(OBJECT_SELF, FALSE);

        // Inform the system that the door should be considered open; the action is queued.
        ActionDoCommand(ActionOpenDoor(OBJECT_SELF));

        // Schedule to close and lock the door after 30 seconds.
        DelayCommand(30.0, ActionDoCommand(ActionCloseDoor(OBJECT_SELF)));
        DelayCommand(30.5, SetLocked(OBJECT_SELF, TRUE)); // Small delay added for reliability
    }
    else
    {
        // Send a message to the creature if the necessary item is not found.
        SendMessageToPC(oUser, "VIP BADGE not found, please go purchase one from the prize room.");
        
        // Attempt to lock the door immediately to prevent opening, in case it wasn't locked.
        SetLocked(OBJECT_SELF, TRUE);

        // No need to force the door to close here since we want it to stay closed and locked.
    }
}
