Game Development Community

Question on - interact with doors - unlock with key?

by J0linar · in Torque 3D Professional · 03/25/2013 (8:16 am) · 4 replies

Hi all
my question is less how to make the door interact but more
how to make it accept keys/ for unlocking
am using T3D mit v2.0

i did came across a couple of door resources
some that use oncollision and most others the interact script
and i did got teh oncollision doors working and the interact ones/ its just the key thing that troubles me

here is the one i used
and where am getting problems with/
*key unlocking does not work
*no messages gettin displayed when i perfom interact
www.garagegames.com/community/resources/view/10200/2#comment-88322

on a side note i did changed the script to work at least the opening/ closing works
whats just missing is the part with key and the displayin of the messages.

now am not expecting a how to guide, just a pointer on how i can make it accept
keys and display a message when the door opens or the player is missing the key

thx for taking the time

#1
03/25/2013 (8:42 am)
I have just recently made a door that opens and closes and can be set to accept keys. It also, once opened, will allow you to open the door and close it without the key anymore. I have a function that checks my inventory for the specific key. And the functions for opening and closing the door check to see if a match of the key needed is what the player has somewhere in their inventory.
I would start off simple and have a function that compares a new dynamic field on your character called key with the dynamic field of the door called key needed. If they are equal then have it initiate the function for opening or closing and initiating the pop gui that you are describing..
#2
03/25/2013 (9:09 am)
thx for the reply DreamPharaoh

would u mind showing a script snippet
of your key function.

I seem to not really be able to wrap my head around that part.
and another thing is that i want to actualy avoid using a real gui for displayin text messages/ just sending a message to the clients display is all i plan with it.

#3
03/25/2013 (11:49 am)
This one is going to really hard for me to explain because it involves so many different things to make it happen in my game. I will list the functions that may help in giving you some idea with notes. I hope it helps.
-------------------------------------
// after my scan function on my character detects a door
// then it will fire this function with the door's ID

function DoorOpenClose(%targetID)
{

//This is the dynamic field of the door
%key = %targetID.key;
// this is placer on my Door gui that holds the information to compare // later
KeyNeeded.text = %key;

//The rest of this information is to load the character's items
// into the door inventory so that the player can choose a key



%NPCPlayerFile = "art/gui/CharacterStatsGui/CharacterInventorySaveFiles/";
DoorsLinker2.text = %NPCPlayerFile;
//This is the name of the File.txt
%Inventory = "ITEMS";
DoorsLinker3.text = %Inventory;
//clear the list box of previous content
// This is the name of the GUIList.gui object
%displayType = "DoorsInventory";
DoorsLinker4.text = %displayType;

// The door gui is finally popped and other commands are linked to its
//buttons such as "use key".
canvas.pushDialog(Doors);


}





#4
03/25/2013 (11:50 am)
function Lockclose(%targetID)
{
// this closes the door placing the door with the collision back into
// place again
%door = %targetID.collisionMimic2;
%pos = %targetID.position;

%Xpos = 0;
%Ypos = 0;
%Zpos = 0;
%xfrm = %pos;
%charX = getWord(%xfrm, 0);
%charY = getWord(%xfrm, 1);
%charZ = getWord(%xfrm, 2);

%Zdis = %charZ + 3;
%Zdis2 = %charZ + 6;
%altPos = %charX @ " " @ %charY @ " " @ %Zdis;
%altPos2 = %charX @ " " @ %charY @ " " @ %Zdis2;
schedule(1000, 0, doorFormerDelay, %door, %pos);
//schedule(1000, "", );


sfxPlay(%targetID.SoundClose);
Canvas.popDialog(Doors);
%targetID.playThread(close);
%targetID.playThread(0, close);
%targetID.DoorLocked = "close";

%data = %targetId.damageFX;
%data2 = %targetId.damageFX2;


%explosion = new Explosion()
{
position = %altPos;
//rotation = "1 0 0 0";
//scale = "1 1 1";
dataBlock = "EntranceEffect";
};


%particles = new ParticleEmitterNode()
{
position = %altPos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "DamageFxNode";
emitter = %data; //"BoulderChipsEmitter";
velocity = "1";
};

%particles1 = new ParticleEmitterNode()
{
position = %pos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "DamageFxNode";
emitter = "TeleportEmitter"; //"BoulderChipsEmitter";
velocity = "1";
};

%particles2 = new ParticleEmitterNode()
{
position = %altPos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "DamageFxNode";
emitter = %data; //"BoulderChipsEmitter";
velocity = "1";
};

%particles3 = new ParticleEmitterNode()
{
position = %altPos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "DamageFxNode";
emitter = %data2; //"BoulderChipsEmitter";
velocity = "1";
};


ServerPlay3D(%targetID.damageSound, %pos);

MissionCleanup.add(%explosion);
MissionCleanup.add(%particles);
MissionCleanup.add(%particles1);
MissionCleanup.add(%particles2);
MissionCleanup.add(%particles3);
%particles.schedule(1000, "delete");
%particles1.schedule(1000, "delete");
%particles2.schedule(1000, "delete");
%particles3.schedule(1000, "delete");
}



function doorFormerDelay(%door, %pos)
{
// this function is only here to allow a delay for when the door appears
// after all the special effects have been completed
%door.position = %pos;


}