@datiswous
It's a dirty hack, to be honest, as it was just a proof of concept. Basically there are two things going on.
1. An infinite loop, that takes care of clearing the inventory if the player is not looking at a door.
2. An alternative version of the frob action script on the door that takes care of finding the correct key in the players inventory and switching to the lockpick, if the correct key is not in the players possesion.
As stated in the video this setup works with one lockpick. But due to the minigame in TDM having several picks is nonsense either way and only present as it was like that in the original games.
These are the scripts (this stuff is actually still lying around on my harddrive ) :
1. Inventory clearance (switching away from the lockpicks (this is to disguise them in the inventory, as the player doesn't have to use them actively)
void test()
{
while(1)
{
if ($player1.getImmobilization("")!=2048 && $player1.getCurInvItemEntity().getName()=="lockpick")
{
$player1.getNextInvItem();
}
sys.waitFrame();
}
}
Immobilizations are set by the game if the player is doing something specific, normally to somewhat restrict his moving capabilities (e.g. making him slower). From player.h
// Player control immobilization categories.
enum {
EIM_ALL = -1,
EIM_UPDATE = BIT( 0), // For internal use only. True if immobilization needs to be recalculated.
EIM_VIEW_ANGLE = BIT( 1), // Looking around
EIM_MOVEMENT = BIT( 2), // Forwards/backwards, strafing and swimming.
EIM_CROUCH = BIT( 3), // Crouching.
EIM_CROUCH_HOLD = BIT( 4), // Prevent changes to crouching state. (NYI)
EIM_JUMP = BIT( 5), // Jumping.
EIM_MANTLE = BIT( 6), // Mantling (excluding jumping)
EIM_CLIMB = BIT( 7), // Climbing ladders, ropes and mantling.
EIM_FROB = BIT( 8), // Frobbing.
EIM_FROB_HILIGHT = BIT( 9), // Frobbing AND frob hilighting (not sure if needed or if EIM_FROB can disable hilight also)
EIM_FROB_COMPLEX = BIT(10), // Frobbing of "complex" items (not a door, lever, button, etc)
EIM_ATTACK = BIT(11), // Using weapons
EIM_ATTACK_RANGED = BIT(12), // Using ranged weapons (bows)
EIM_WEAPON_SELECT = BIT(13), // Selecting weapons.
EIM_ITEM_USE = BIT(14), // Using items
EIM_ITEM_SELECT = BIT(15), // Selecting items.
EIM_ITEM_DROP = BIT(16), // Dropping inventory items.
EIM_LEAN = BIT(17), // Leaning
};
Dunno if the numbering has changed or the logic is a bit different, but immobilization 2048 refers to one of the frobs (but it is two to the power of eleven, so I am a bit confused here, one would have to test if it is still valid).
The frob_action_script on the door (you have to set that via the respective spawnarg):
void advancedDoorFrob(entity door)
{
if (door.IsLocked())
{
$player1.setCurInvCategory("#str_02392");
$player1.setCurInvItem(door.getKey("used_by"));
sys.waitFrame();
entity key=$player1.getCurInvItemEntity();
if(key==$null_entity)
{
$player1.setCurInvCategory("#str_02389");
$player1.setCurInvItem("lockpick");
}
else
{
door.ToggleLock();
}
}
else
{
door.ToggleOpen();
}
}
The code basically switches the inventory item to the key used by the door currently frobbed. If such a key isn't present in the players inventory, no item will be selected (aka null_entity) and we switch to the lockpick. Otherwise the door will be unlocked. This only happens if the door is still locked, though, otherwise it just gets opened/closed.
In all honesty, I would prefer a different implementation nowadays, but this gives you an impression of how this can be set up.