Author Topic: Trigger Gui  (Read 652 times)

How would you make it so that when you stand inside of a trigger it opens a GUI on the clients side?

Code: (Server-Sided) [Select]
package Server
{
    function TheFunction(%TheClient)
    {
        commandToClient(%TheClient, 'TheCommand');
    }
};
activatePackage("Server");

Code: (Client-Sided) [Select]
new GuiControl(TheGUI) { };

function clientcmdTheCommand()
{
    Canvas.pushDialog(TheGUI);
}


Everything prefaced with a "The" should be replaced with what you actually have/want. IE "clientcmdTheCommand" becomes "clientcmdTrig_OpenGUI".

Code: (Trigger Code) [Select]
// The Trigger Datablock
datablock TriggerData(GUITrigger)
{
tickPeriodMS = 500;  //How often the trigger updates to check if someone has entered/left the trigger (Time in milliseconds)
};

// Function called to create the trigger on a brick
// Usage: createTrigger(%brick, "TRIGGERDATABLOCKNAME");
function createTrigger(%this, %triggerDataBlock)
{
%t = new Trigger()
{
datablock = %triggerDataBlock;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};

missionCleanup.add(%t);

%trigX = %this.getDatablock().brickSizeX;
%trigY = %this.getDatablock().brickSizeY;
%trigZ = %this.getDatablock().brickSizeZ;

if(mFloor(getWord(%this.rotation, 3)) == 90)
%boxDiff = (%trigY / 2) SPC (%trigX / 2) SPC %trigZ;
else
%boxDiff = (%trigX / 2) SPC (%trigY / 2) SPC %trigZ;

%t.setScale(%boxDiff);
%posA = %this.getWorldBoxCenter();
%posB = %t.getWorldBoxCenter();
%posDiff = vectorSub(%posA, %posB);
%posDiff = vectorAdd(%posDiff, "0 0 0.1");
%t.setTransform(%posDiff);

%this.trigger = %t;
%t.brick = %this;

return %t;
}

// This function is called when a player leaves a Trigger of the name, GUITrigger
function GUITrigger::onLeaveTrigger(%this, %trigger, %obj)
{
// Do Stuff
}

// This function is called when a player enters a Trigger of the name, GUITrigger
function GUITrigger::onEnterTrigger(%this, %trigger, %obj)
{
// Do Stuff
}


Replace "TRIGGERDATABLOCKNAME" with "GUITrigger" (the trigger stated above) or the name of whatever trigger datablock you create.
« Last Edit: October 26, 2013, 08:00:31 PM by Vaux »