Triggering a GUI on the client
by Edward Gardner · 12/13/2001 (11:28 pm) · 0 comments
First off, I drew from this thread www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=1420 and copied the trigger.cs into my fps/server/scripts directory.
Then, open trigger.cs and add the following to the end of the file:
And this:
Make sure you exec trigger.cs in fps/server/scripts/game.cs
This adds the trigger type "stationTrigger" to the map editor and sets the stage for messaging the client to invoke the GUI.
In the fps/client/scrips folder, create a file called TriggerClient.cs, the contents of which should be:
Add the exec statement for this .cs to the client/init.cs
Finally, you need a GUI with buttons that execute a commandtoserver to spawn your vehicles. Here's mine:
Of course, you need to exec this GUI on the client, and you will want to change it to match your vehicles, or player armors, or what have you.
That's it. Open up your mission in the editor, select the creator window, and add a trigger object, give it a clever name and select the stationTrigger type.
Note, in Torque 1.1, you will need to manually edit the poly definition as per the thread above in notepad after you save it. This seems to be fixed in the new editor.
Again, thanks a million to Spock, Snowman and Kalldrexx on IRC for helping me thru this!
Then, open trigger.cs and add the following to the end of the file:
/// -Trigger- //////////////////////////////////////////////////////////////////
//Function -- onLeaveTrigger (%data, %obj, %colObj)
// %data = Trigger Data Block
// %obj = Trigger Object
// %colObj = Object that collided with the trigger
//Decription -- Called when trigger has been untriggered
////////////////////////////////////////////////////////////////////////////////
function stationTrigger::onEnterTrigger(%data, %obj, %colObj) {
%client = %colObj.client;
if (%client) {
commandToClient(%client, 'triggerClientGui');
} else {
echo ("Not a client");
}
}
function stationTrigger::onLeaveTrigger(%data, %obj, %colObj)
{
//Game.onLeaveTrigger(%client.name, %data, %client);
return;
}
/// -Trigger- //////////////////////////////////////////////////////////////////
//Function -- onTickTrigger(%data, %obj)
// %data = Trigger Data Block
// %obj = Trigger Object
//Decription -- Called every tick if triggered
////////////////////////////////////////////////////////////////////////////////
function stationTrigger::onTickTrigger(%data, %obj, %colObj)
{
//Game.onLeaveTrigger(%client.name, %data, %client);
return;
}And this:
datablock TriggerData(stationTrigger)
{
tickPeriodMS = 30;
};to the datablock definitions at the top of the file.Make sure you exec trigger.cs in fps/server/scripts/game.cs
This adds the trigger type "stationTrigger" to the map editor and sets the stage for messaging the client to invoke the GUI.
In the fps/client/scrips folder, create a file called TriggerClient.cs, the contents of which should be:
function clientCmdtriggerClientGui()
{
canvas.setContent(vehiclestation);
}Add the exec statement for this .cs to the client/init.cs
Finally, you need a GUI with buttons that execute a commandtoserver to spawn your vehicles. Here's mine:
//--- OBJECT WRITE BEGIN ---
new GuiControl(VehicleStation) {
profile = "GuiContentProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "640 480";
minExtent = "8 8";
visible = "1";
helpTag = "0";
new GuiWindowCtrl() {
profile = "GuiWindowProfile";
horizSizing = "center";
vertSizing = "center";
position = "0 0";
extent = "640 480";
minExtent = "8 8";
visible = "1";
helpTag = "0";
maxLength = "255";
resizeWidth = "1";
resizeHeight = "1";
canMove = "1";
canClose = "1";
canMinimize = "1";
canMaximize = "1";
minSize = "50 50";
new GuiButtonCtrl(Pyro) {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "247 69";
extent = "140 30";
minExtent = "8 8";
visible = "1";
command = "commandtoserver (\'addflyer\'); canvas.setContent(\"playgui\");";
helpTag = "0";
text = "Pyro";
};
new GuiButtonCtrl(backbutton) {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "459 412";
extent = "140 30";
minExtent = "8 8";
visible = "1";
command = "canvas.setContent(\"playgui\");";
helpTag = "0";
text = "Back";
};
new GuiButtonCtrl(ulysses) {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "246 113";
extent = "140 30";
minExtent = "8 8";
visible = "1";
command = "commandtoserver (\'addintercept\'); canvas.setContent(\"playgui\");";
helpTag = "0";
text = "Ulysses";
};
new GuiButtonCtrl(savannah) {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "246 165";
extent = "140 30";
minExtent = "8 8";
visible = "1";
command = "commandtoserver (\'addsav\'); canvas.setContent(\"playgui\");";
helpTag = "0";
text = "Savannah Master";
};
};
};
//--- OBJECT WRITE END ---Of course, you need to exec this GUI on the client, and you will want to change it to match your vehicles, or player armors, or what have you.
That's it. Open up your mission in the editor, select the creator window, and add a trigger object, give it a clever name and select the stationTrigger type.
Note, in Torque 1.1, you will need to manually edit the poly definition as per the thread above in notepad after you save it. This seems to be fixed in the new editor.
Again, thanks a million to Spock, Snowman and Kalldrexx on IRC for helping me thru this!
About the author
