Open inventory of a lock box

Is there a way to open the inventory of a placeable that has inventory? I tried to do a script but couldn’t find a function to do that. Is that impossible? Or do you have to use XML coding to do this perhaps?

I began my simple script like this:

void main()
{

object oLockbox = GetObjectByTag("lockboxl");

SetLocked(oLockbox,FALSE);


}

But I would really have liked if the game could open up the inventory of the box. The scene is like this: The party approaches the box, the player clicks on it, it starts a dialogue, and in the last node I would want to run a script that opens the inventory of the box.

you could try this (perhaps in a delayed call on the last node) →

void open(object oPC, object oPlaceable)
{
    AssignCommand(oPC, DoPlaceableObjectAction(oPlaceable, PLACEABLE_ACTION_USE));
}

void main()
{
    object oLockbox = GetObjectByTag("lockboxl");

    SetLocked(oLockbox,FALSE);

    object oPC = GetPCSpeaker();
    DelayCommand(0.1f, open(oPC, oLockbox));
}

[edit] define oPC before passing it into the delayed command

3 Likes

Aha! So that’s the way to do it? Interesting. It seems logical. Sometimes you just have to figure out what you need to write in certain scripts, and it’s not always that clear.

Thank you as always, @kevL_s ! I’ll check this tomorrow night. Now it’s time for me to go sleep.

1 Like

@kevL_s

Interesting … I need to check that function out. Looks useful.

@andgalf

In my own module, I have done it this way … Ensure the PC is able to reach the placeable for this to work. In my own script, I have the PC jump to the placeable prior the interaction function. The function does work though.

void GetStuff(object oPC, object oPlaceable);
void GetStuff(object oPC, object oPlaceable)
{			
	AssignCommand(oPC, ClearAllActions(TRUE));	
	AssignCommand(oPC, ActionInteractObject(oPlaceable));
}

void main()
{
	object oPC = GetPCSpeaker();
	
	// INTERACT PLACEABLE
	object oPlaceable = GetObjectByTag("lockboxl");
	
	// THEN OPEN STORAGE WITH THE PC
	DelayCommand(0.2, GetStuff(oPC, oPlaceable));	
}
1 Like

So I have tried @kevL_s script now but it doesn’t quite work and I really don’t know why. It’s odd.
It seems to want to work if that makes any sense.

So, let me try and explain the situation further.

The lock box I have is locked. On the OnLeftClick I have a script now that looks like this:

// gp_talk_object.nss
/*
	This script allows you to speak to an object.
	Set a conversation, set Usable to True, and attach this script to the OnUsed event.
*/
// FAB 2/7
// ChazM 2/17/05
// BMA-OEI 9/17/05 file description

void OpenTheBox (object oPC, object oPlaceable)
{
    AssignCommand(oPC, DoPlaceableObjectAction(oPlaceable, PLACEABLE_ACTION_USE));
}


void main()
{

	object oLockbox = GetObjectByTag("lockboxl");
	object oPC = GetFirstPC();

	if(!GetLocalInt(OBJECT_SELF,"DoOnceOnly"))
	{

	SetLocalInt(OBJECT_SELF,"DoOnceOnly",1);
	
    ActionStartConversation(oPC);
	}
	
	else
	{
	
	DelayCommand(0.1f, OpenTheBox(oPC, oLockbox));
	
	}
}

This makes the dialog run. Then at the last node of the conversation (I do this particular conversation in NWN1 style (maybe that has something to do with it not quite working?)) I have the script here:

void OpenTheBox (object oPC, object oPlaceable)
{
    AssignCommand(oPC, DoPlaceableObjectAction(oPlaceable, PLACEABLE_ACTION_USE));
}

void main()
{
    object oLockbox = GetObjectByTag("lockboxl");
	object oPC = GetFirstPC();

    SetLocked(oLockbox,FALSE);

    DelayCommand(0.1f, OpenTheBox(oPC, oLockbox));
}

What I see happens ingame, is that the PCs action queue shows the symbol “Use”, but then nothing happens. I have no idea why.

I guess I’ll do some more testing, otherwise I might try Lance’s script.

EDIT: Alright, I tried some things and did some baking and now suddenly it works. Really weird. Don’t know what was the issue before.

1 Like

Probably the baking allowed the PC to come closer to the placeable, thus enabling the action to occur.

1 Like

Yep, I think so too. It was obvious the game was trying to get the action to occur but it was stuck in limbo (is that the right expression here?). I also noticed that the PC, when I got it to work, walked closer to the placeable when the action worked.

I have now reworked the whole scene so it’s much smoother. I teleport all the companions, through a script that I’ve used before in this module at the first node of the conversation (one made by kevL_s and travus that I really dig, that has all the companions place themselves dynamically at different angles around the object when talking) - that I had to modify since it was no longer a creature talking - and I’ve taken a few precautions to different scenarios and (can’t find the word in english, I’m way too tired at the moment) … well, anyway…

1 Like

This is why I say for my own version …

Normally, this means ensuring the walk path to the object is easily accessible, and like I also did, ensure the PC to do the interacting is jumped closer to the object just prior to the call …

So it sounds like the two functions act in a similar way. I had hoped the other function that KevL suggested may have been able to bypass any distance between the objects much like the old (deprecated?) OpenInventory function used to do. I believe that function used to open an inventory directly without the need to interact with an object on-screen.

Your feedback suggests that the two functions suggested for you work in a similar fashion, both requiring the PC to move and interact with the object when the function is called.

i.e. ActionInteractObject works similar to DoPlaceableObjectAction

Although the latter allows some other parameters, which may be useful moving forward.

@Lance_Botelle - Yes, I believe you’re right.

I could probably have used either of your scripts and had the same result, I think.

2 Likes