Bring up GUI using trigger or 'USE' key.
by Luke Griffin · in Torque 3D Professional · 03/18/2011 (9:33 am) · 16 replies
Hi.
I am trying to figure out a way of having a passcode system next to a door. so you approach the door and press a button next to it using the use key, a GUI is displayed in which you must enter the correct password to open the door, say 1234 as a test. I was wondering how I could do this? I am using the game mechanics kit, so I already have a switch that I can use, with a dynamic field of "onOpened". I would like to use a value here to set which gui I can open as there will be other types of 'usable' gui's such as books to read on tables ect, so I would like to be able to change that in the editor rather then copying and pasting the same functions and making loads of duplicates. It will of course need to have the ability to return a value to the world that could perform a task, such as opening a door. This could be stored as a dynamic field in the button as well if needed. Does anyone have any ideas?, Im really stuck with this and have no real idea where to start.
I am trying to figure out a way of having a passcode system next to a door. so you approach the door and press a button next to it using the use key, a GUI is displayed in which you must enter the correct password to open the door, say 1234 as a test. I was wondering how I could do this? I am using the game mechanics kit, so I already have a switch that I can use, with a dynamic field of "onOpened". I would like to use a value here to set which gui I can open as there will be other types of 'usable' gui's such as books to read on tables ect, so I would like to be able to change that in the editor rather then copying and pasting the same functions and making loads of duplicates. It will of course need to have the ability to return a value to the world that could perform a task, such as opening a door. This could be stored as a dynamic field in the button as well if needed. Does anyone have any ideas?, Im really stuck with this and have no real idea where to start.
#2
scripts/client/config.cs
scripts/client/init.cs
scripts/server/player.cs
Then to get the code to work all you have to do is select a shape or entity in the level editor. create a new dynamic field and change the field to 'menutype'. Then change the value to the name of the .gui file you would like to display. When you are looking at the shape and the 'E' key is pressed that GUI will then be displayed. In theory you should be able to display any .gui that you want to. Im still trying to figure out how I can freeze the player so they can't move while the gui is active, so if any one has any ideas feel free to post.
03/20/2011 (2:29 pm)
OK after a lot of grafting I finally come up with a solution which I thought I would post here in case anyone else wanted to do something similar in the future. As my system is working through a weapon I will just do this example to a key binding to simplify it.scripts/client/config.cs
moveMap.bind(keyboard, "e", useMENUObject);
scripts/client/init.cs
function useMENUObject(%flg)
{
commandToServer('useMENUObj', %flg);
}scripts/server/player.cs
function Player::checkObjectsForMenuType(%this)
{
%eyeVectri = %this.getEyeVector();
%startPos = VectorAdd(%this.getEyePoint(), VectorScale(%eyeVectri, 0.2));
%endPos = VectorAdd(%startPos, VectorScale(%eyeVectri, $Player::useTraceDist));
%this.MenuTypeTarget = ContainerRayCast(%startPos, %endPos, $TypeMasks::ShapeBaseObjectType, %this);
%this.MenuTypeTarget = getWord(%this.MenuTypeTarget, 0);
%menufieldvalue = %this.MenuTypeTarget.getFieldValue("menutype");
return %menufieldvalue;
}
function serverCmduseMENUObj(%client, %buttonState, %additional)
{
%player = %client.player;
// doing a ray cast check on the server to locate dynamic field value
%target = %player.checkObjectsForMenuType();
if(isObject(%target))
{
Canvas.pushDialog(%target);
}
}Then to get the code to work all you have to do is select a shape or entity in the level editor. create a new dynamic field and change the field to 'menutype'. Then change the value to the name of the .gui file you would like to display. When you are looking at the shape and the 'E' key is pressed that GUI will then be displayed. In theory you should be able to display any .gui that you want to. Im still trying to figure out how I can freeze the player so they can't move while the gui is active, so if any one has any ideas feel free to post.
#4
03/20/2011 (2:52 pm)
ahhh thats good, does this one actually render the gui onto the object in question? as that would be a pritty cool effect.
#5
with that working, instant ingame consoles and keypads.
I have things like hand held compasses, you can have radar on a pda,
its a really good resource
03/20/2011 (9:29 pm)
yes it does, but for the life of me I cant get the mouse input working.with that working, instant ingame consoles and keypads.
I have things like hand held compasses, you can have radar on a pda,
its a really good resource
#6
03/21/2011 (2:46 am)
function serverCmduseMENUObj(%client, %buttonState, %additional)
{
%player = %client.player;
// doing a ray cast check on the server to locate dynamic field value
%target = %player.checkObjectsForMenuType();
if(isObject(%target))
{
Canvas.pushDialog(%target);
}
}While this will work in a local game, it's not network-safe. Server command functions are sent by the client to be executed on the server, which is usually a separate machine. And is never responsible for actually rendering GUIs. What you need to do here is sent a command back to the client to tell them they need to push a dialog to the canvas. Have a look for functions starting with clientCmd (and the associated commandToClient function).
#7
@deepscratch: I've noticed there are a few problems when it comes to mouse input. I've tried implementing the code I've found in multiple tutorials to get mouse over button sounds working in menus and it just doesn't seem to work.
03/21/2011 (3:10 am)
@Daniel Buckmaster: Im working on a single player project so its not really a big deal if its running on the server but thanks for letting me know, I hadnt thought about that.@deepscratch: I've noticed there are a few problems when it comes to mouse input. I've tried implementing the code I've found in multiple tutorials to get mouse over button sounds working in menus and it just doesn't seem to work.
#8
I remember cause I turned it off, the sounds got on my nerves,
maybe look how it was done back then?
03/21/2011 (3:14 am)
it was working in tgea 1.8.2I remember cause I turned it off, the sounds got on my nerves,
maybe look how it was done back then?
#9
art/datablocks/audioprofiles.cs
art/gui/defaultgameprofiles.cs
03/21/2011 (4:20 am)
Well this is the method I cant get to work:art/datablocks/audioprofiles.cs
new AudioProfile(AudioButtonOver)
{
filename = "~/data/sound/gui/ButtonOver.wav";
description = "AudioGui";
preload = true;
};
new AudioProfile(AudioButtonDown)
{
filename = "~/data/sound/gui/ButtonHit.wav";
description = "AudioGui";
preload = true;
};art/gui/defaultgameprofiles.cs
GuiButtonProfile.soundButtonOver = "AudioButtonOver"; GuiButtonProfile.soundButtonDown = "AudioButtonDown";
#10
use
03/21/2011 (4:34 am)
this structure is old filename = "~/data/sound/gui/
use
filename = "art/sound/gui/instead.
#11
03/21/2011 (5:04 am)
i've tried that, it also doesnt work.
#12
03/21/2011 (6:07 am)
Also, I am trying to make a kind of "memory" puzzle inside the a gui. So you basicly have say 5 pairs of buttons and when you put your mouse over them they display and image and you have to click on two matching images at a time to solve the puzzle. would this be possible in the gui and how would i go about doing this?
#13
to determine if a control is currently visible. Is there a way to check if the control is not visible?
03/21/2011 (8:27 am)
OK I've made a little head way on this so far but I have a question. In an if statement you can putif (button1.isVisible())
{
}to determine if a control is currently visible. Is there a way to check if the control is not visible?
#15
03/21/2011 (8:40 am)
Oh, and something about the mouseover button sounds: they were enabled in earlier betas but apparently annoyed the Tools team so were disabled. Since then however, there were some changes to the audio system and the loading order of some core/game audio stuff was changed. The method shown above will work to re-enable the button over sounds but you will have to make sure the sound and button over definition is loaded before the core and GUI that makes use of them.
#16
03/21/2011 (9:17 am)
that could explain why I have had trouble with other mouseover events. Any idea how I would need to do this?
Torque 3D Owner Bryan Sawler
muteki corporation