Author Topic: How would I make a brick activate something if someone clicks on it?  (Read 2381 times)

Code: [Select]
//events
function brickKeyboardData::Activate(%this, %client)
{
%client.onType();
}
doesn't do anything.

Am I doing something wrong?

I also tried adding an "on" before activate.
« Last Edit: January 22, 2015, 05:47:04 AM by Crispy_ »

afaik there is no function that is called on the brick itself when it is activated. You have to do checks manually.


package brickKeyboardPackage
{
   function Player::Activatestuff(%obj)
   {
      Parent::Activatestuff(%obj);
      
      %ray = containerRaycast(%obj.getEyePoint(),vectorAdd(%obj.getEyePoint(),vectorScale(%obj.getEyeVector(),3)),$Typemasks::fxBrickObjectType,%obj);
      if(isObject(%col=firstWord(%ray)))
         if(%col.getDatablock() == brickKeyboardData)
         {
            //Do stuff here
         }

   }
};
activatepackage(brickkeyboardpackage);

ill check it out, great thanks. i'm /kinda/ a beginner but i have determination to do what i want to do

afaik there is no function that is called on the brick itself when it is activated. You have to do checks manually.
What about function fxDTSBrick::OnActivate(%brick, %player, %client, %position, %vector)?

What about function fxDTSBrick::OnActivate(%brick, %player, %client, %position, %vector)?
99% certain that is called if there is an onActivate event on there, otherwise it'll just be ignored.

Just tested. It does get called regardless of events. Should've already figured this because the treasure chest will work even if you take the sound event off it.

It's onPlayerTouch that needs an event, or for the datablock to have enableTouch set to true, for it to be called.

Thank you guys for your help. This is the code that ended up working

Code: [Select]
//Brick data
datablock fxDTSBrickData (brickKeyboardData)
{
brickFile = "Add-Ons/GameMode_CityRPG/shapes/Bricks/1x3FKeyboard.blb";
canCover = true;
category = "CityRPG";
subCategory = "Resources";
uiName = "Keyboard";
isTypable = true;

price = $CityRPG::prices::resources::keyboard;

CityRPGBrickType = 4;
CityRPGBrickAdmin = false;
};

//events
package brickKeyboardPackage
{
function fxDTSBrick::onActivate(%brick, %obj, %client, %pos, %dir)
{
parent::onActivate(%brick, %obj, %client, %pos, %dir);

if(%brick.getDataBlock().isTypable == true)
{
%client.onType();
messageClient(%client, '', "\c3click");
}
}
};
activatepackage(brickKeyboardPackage);

The message was to see if it would work, in case the onType function was broken somehow (which it is, because i typed it in wrong)
« Last Edit: January 22, 2015, 06:50:16 PM by Crispy_ »