Game Development Community

Trouble creating a trigger by script and getting callbacks

by Guigouille · in Torque 3D Beginner · 02/27/2013 (12:06 pm) · 4 replies

Hi,

I'm new at Torque3D and I can't figure how to solve my problem.
I create a trigger using the script but I don't have any callback.

Here is the script I use to create my trigger :

new Trigger()
{
datablock = "DefaultTrigger";
polyhedron = "-0.5 -0.5 0 1 0 0 0 1 0 0 0 1";
position = %position;
scale = %scale;
};

No callback is fired on this trigger, if I create a trigger using the editor using the same datablock, callbacks are correctly fired.

Help would be highly appreciated ^^

About the author

Recent Threads


#1
02/27/2013 (1:24 pm)
Are you sure that %position and %scale are assigned values? If they are not then you aren't getting a callback because the trigger isn't where you think it is.

I have used the following function to dynamically create a building with an attached spawn point and trigger:
// create a building as indicated by the %type at the point we clicked.  Right
// now this only creates a "Barracks" building.
function serverCmdcreateBuilding(%client, %pos, %start, %ray, %type)
{
    // find end of search vector
    %ray = VectorScale(%ray, 2000);
    %end = VectorAdd(%start, %ray);

    %searchMasks = $TypeMasks::TerrainObjectType;

    // search!
    %scanTarg = ContainerRayCast( %start, %end, %searchMasks);

    // If the terrain object was found in the scan
    if( %scanTarg )
    {
        %obj = getWord(%scanTarg, 0);

        %pos = getWords(%scanTarg, 1, 3);

        // spawn a new object at the intersection point
        %obj = new TSStatic()
        {
            position = %pos;
            shapeName = "art/shapes/building/orcburrow.dts";
            class = "barracks";
            collisionType = "Visible Mesh";
            scale = "0.5 0.5 0.5";
        };
        %obj.team = %client.getId();

        // Add the new object to the MissionCleanup group
        MissionCleanup.add(%obj);
        
        // Set up a spawn point for new troops to arrive at.
        %teamSpawnGroup = "Team"@%client.team@"SpawnGroup";
        if (!isObject(%teamSpawnGroup))
        {
            new SimGroup(%teamSpawnGroup)
            {
                canSave = "1";
                canSaveDynamicFields = "1";
                    enabled = "1";
            };

            MissionGroup.add(%teamSpawnGroup);
        }
        
        %spawnName = "team"@%client.team@"Spawn" @ %obj.getId();
        %datablock = (%type !$= "" ? %type : $Game::DefaultPlayerDataBlock);
        %point = new SpawnSphere(%spawnName)
        {
            radius = "1";
            dataBlock      = "SpawnSphereMarker";
            spawnClass     = $Game::DefaultPlayerClass;
            spawnDatablock = %datablock;
        };
        %point.position = VectorAdd(%obj.getPosition(), "0 6 2");
        %obj.spawnPoint = %point;
        %teamSpawnGroup.add(%point);
        MissionCleanup.add(%point);

        %triggerName = "team"@%client.team@"Trigger" @ %obj.getId();
        %box = %obj.getWorldBox();
        %rot = %obj.rotation;
        %pos = %obj.getPosition();
        %scalex = (getWord(%box, 3) - getWord(%box, 0)) * 1.2;
        %scaley = (getWord(%box, 4) - getWord(%box, 1)) * 1.2;
        %scalez = (getWord(%box, 5) - getWord(%box, 2)) * 10.0;
        %scale = %scalex SPC %scaley SPC %scalez;
        %trigger = new Trigger(%triggerName)
        {
            polyhedron = "-0.5 0.5 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 1.0";
            dataBlock = "BarracksTrigger";
        	rotation = %rot;
        	position = %pos;
        	scale = %scale;
        };
        %trigger.owner = %obj;
        MissionCleanup.add(%trigger);
    }
}
The end of this function is where you want to look, specifically.

Hope it helps!
#2
02/27/2013 (2:11 pm)
%position and %scale are assigned values.
And the trigger I create appears in the editor (or maybe I shouldn't trust the editor ? :p)

I still can't figure what I did wrong and why I don't have any callback.

Maybe the file where I create my trigger ? I made it in a custom script file.

Thank you for helping btw ^^
#3
02/27/2013 (4:24 pm)
The code I posted was added to scripts/server/commands.cs, but if the trigger is being created then the script is being executed so the file it is in shouldn't matter.

Try using my polyhedron for your trigger and see if that helps. Sometimes Torque is ticklish with 1 vs. 1.0....
#4
02/28/2013 (6:25 am)
I just tried it aaaaaaaaaaaaaand it worked !

Thank you Richard for helping me ^^