Author Topic: On player touch brick though coding. (or in zone, whichever)  (Read 838 times)

I need to make it so when a player enters a bricks zone, or touches the brick, whichever is easier, something happens:
Code: [Select]

datablock fxDTSBrickData(DDRPSmith : brick8x8FData)
{
category = "DDRP";
subCategory = "Job Plates";
uiName = "Smithing";
};

datablock TriggerData(DDRPTrigger)
{
tickPeriodMS = 200;
};

function zoneTrigger::onEnterTrigger(%this,%trigger,%obj)
{
echo("Hi!");
}

deactivatepackage(smithplant);
package smithplant
{
function fxdtsbrick::onplant(%brick)
{
if(%brick.getDatablock().getID() == DDRPSmith.getID())
{
Parent::onplant(%brick);
echo("Adding trigger.");

%zoneXa = getWord(%brick.getWorldBox(), 0) - 1/10;
%zoneYa = getWord(%brick.getWorldBox(), 1) - 1/10;
%zoneZa = getWord(%brick.getWorldBox(), 2) - 1/10;


%polySuffA = 0;
%zoneShape = "0.0 0.0 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 1.0";
%pz = new PhysicalZone()
{
  position = %zoneXa SPC %zoneYa SPC %zoneZa;
  velocityMod = "1";
  gravityMod = "1";
  extraDrag = "0";
  isWater = "0";
  waterViscosity = "40";
  waterDensity = "1";
  waterColor = "0.200000 0.600000 0.600000 0.300000";
  appliedForce = 1;
  polyhedron = %zoneShape;

};
missionCleanup.add(%pz);


//Create a new trigger
%tr = new trigger()
{
  position = %zoneXa SPC %zoneYa SPC %zoneZa;
  polyhedron = %zoneShape;
  dataBlock = DDRPTrigger;
};
missionCleanup.add(%tr);

%pz.setScale("5 5 5");
%tr.setScale("5 5 5");

%brick.IsZoneBrick = 1;
%brick.physicalZone = %pz;


%brick.trigger = %tr;
%brick.trigger.Active = 1;
%tr.istriggerBricktrigger = 1;
%tr.triggerBrick = %brick;
}
}
};
activatepackage(smithplant);
I have also tried things with adding an onActivate->self->fireRelay when a brick is planted to put one event in it, so the onPlayerTouch function is called for that brick, but I can't seem to get events put into a brick though script.

And no, this can not be done though events.
And it dosn't work as of yet.

I would say the initContainerBoxSearch, or however its spelled.

DDRPTrigger::blablabla

From Brick_Checkpoint:
Code: [Select]
function brickCheckpointData::onPlayerTouch(%data, %obj, %player)
{
   %client = %player.client;
   if(!isObject(%client))
      return;

   if(%client.checkPointBrick != %obj)
   {
      %client.checkPointBrick = %obj;
      %client.checkPointBrickPos = %obj.getPosition();
      commandToClient(%client, 'BottomPrint', "\c4Checkpoint reached! \c7- Say /clearCheckpoint to go back to the beginning", 3);

      Parent::onPlayerTouch(%data, %obj, %player);
   }
}

From Brick_Checkpoint:
Code: [Select]
function brickCheckpointData::onPlayerTouch(%data, %obj, %player)
{
   %client = %player.client;
   if(!isObject(%client))
      return;

   if(%client.checkPointBrick != %obj)
   {
      %client.checkPointBrick = %obj;
      %client.checkPointBrickPos = %obj.getPosition();
      commandToClient(%client, 'BottomPrint', "\c4Checkpoint reached! \c7- Say /clearCheckpoint to go back to the beginning", 3);

      Parent::onPlayerTouch(%data, %obj, %player);
   }
}

Don't forget it needs this to call that method:

Code: [Select]
function brickCheckpointData::onPlant(%data, %obj)
{
   %obj.enableTouch = true;

   %enabled     = 1;
   %delay       = 0;
   %inputEvent  = "OnPlayerTouch";
   %target      = "Self";
   %outputEvent = "PlaySound";
   %par1        = Beep_Popup_Sound.getId();
   %obj.addEvent(%enabled, %delay, %inputEvent, %target, %outputEvent, %par1);
}

The "enableTouch" is necessary but I don't think the other event is. It might end up cancelling the enable-touch if you then change the events on it without adding an onPlayerTouch one, though.