Author Topic: How do you make something happen when you touch a brick?  (Read 869 times)

I know how to do it via eventing, rather easy, but I need to know how to do it via code.

You can either set %brick.enableTouch to true and then either package fxDTSBrick::onPlayerTouch(%obj, %player) or just use yourDataBlock::onPlayerTouch(%data, %obj, %player). Or you can create a trigger around the brick.

The default checkpoint brick as well as the teledoor are good examples of this.


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);
}

function brickCheckpointData::onLoadPlant(%data, %obj)
{
   Parent::onLoadPlant(%data, %obj);
   %obj.enableTouch = true;
}

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);
   }
}


?
« Last Edit: March 28, 2014, 04:08:45 PM by Advanced Bot »

?
Well specifically the onPlayerTouch segment. Dunno why half that thing's functionality is hardcoded to the brick while the other isn't.