Inn Rooms and Keys

For toolset tutorials as well as question and answers.
Locked
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Inn Rooms and Keys

Post by Teric neDhalir »

Is there a copy of the system for handling keys for inn rooms anywhere or could some kind soul package it up for me?
Many thanks,
Teric
Zelknolf
Chosen of Forumamus, God of Forums
Posts: 6139
Joined: Tue Jul 05, 2005 7:04 pm

Re: Inn Rooms and Keys

Post by Zelknolf »

There isn't a singular system; is there a particular inn that you call an ideal/ model that you'd like to emulate?
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Inn Rooms and Keys

Post by Teric neDhalir »

Zelknolf wrote:There isn't a singular system; is there a particular inn that you call an ideal/ model that you'd like to emulate?
I've been looking at the Blade and Stars on BG.
Zelknolf
Chosen of Forumamus, God of Forums
Posts: 6139
Joined: Tue Jul 05, 2005 7:04 pm

Re: Inn Rooms and Keys

Post by Zelknolf »

So... keys open individual doors and triggers behind doors open the doors?

You can start on tooling the inn-- the area can take whatever shape is handy; the only thing you need is doors which are accessed by unique keys which are set to automatically lock themselves.

You'll also want to place triggers around, careful that they're on the -inside- of the door, with this on the OnEnter event

Code: Select all

void main()
{
    object oPC = GetEnteringObject();
    if(!GetIsPC(oPC)) return; // we don't want cats opening doors.
    object oDoor = GetNearestObject(OBJECT_TYPE_DOOR);
    if(GetIsObjectValid(oDoor))
    {
        vector vPos = GetPosition(oPC);
        WriteTimeStampedLogEntry(GetName(oPC) + " has called auto unlock in area " + GetName(GetArea(oPC)) + " at location (" + FloatToInt(vPos.x) + ", " + FloatToInt(vPos.y) + ")");
        SetLocked(oDoor, FALSE);
    }
}
and then in the area's OnExit

Code: Select all

string sPrefix = ""; // This should be replaced with the first part of the tags on all of your keys
string sStore = ""; // This should be replaced with the tag of the merchant who sells the keys
object oPC = GetExitingObject(oPC);
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
{
    if(GetBaseItemType(oItem) == BASE_ITEM_KEY)
    {
        if(GetStringLeft(GetTag(oItem), GetStringLength(sPrefix)) == sPrefix)
        {
            object oStore = GetObjectByTag(oStore);
            if(!GetStoreContainsKey(oStore, oItem))
            {
                CopyItem(oItem, oStore, TRUE);
            }
            DestroyObject(oItem);
        }
    }
    oItem = GetNextItemInInventory(oPC);
}
And then this function needs to be available in that script

Code: Select all

int GetStoreContainsKey(object oStore, object oItem)
{
    object oInv = GetFirstItemInInventory(oStore);
    while(GetIsObjectValid(oInv))
    {
        if(GetTag(oInv) == GetTag(oItem))
            return 1;
        oInv = GetNextItemInInventory(oStore);
    }
    return 0;
}
Of course, this is also something that I just kinda wrote up-- obviously not exactly what BG is using, though should check for the logging on the unlock trigger (because nwn2server will totally run anything if the client asks nicely-- which is why I say that custom GUIs should be off, to make it harder to ask) and make sure you don't create duplicate keys inside of shops if you grab theirs.
Locked