Author Topic: Brick activate?  (Read 725 times)

Hi, i was wonder how to make a brick call a function when activated.

Code: [Select]
package blah
{
function fxDtsBrick::onActivate(%this,%player,%client)
{
parent::onActivate(%this,%player,%client);

//do your stuff
}
};
activatePackage(blah);


I tried
Code: [Select]
function fxDtsBrick::onActivate(%this,%player,%client)
{
parent::onActivate(%this,%player,%client);

messageclient(%client, '','\c3Test: Success!');
}
And it sends the message when any brick is clicked not just the one brick I want.

EDIT: It works now! :D
Code: [Select]
package testBrickActivate
{
function fxDTSBrick::onActivate(%obj, %player, %client, %pos, $vec)
{
%data = %obj.getDataBlock();

if(%data.getid() == TestBrickData.getId())
{
messageclient(%client, '','\c3Test: Success!');

Parent::OnActivate(%obj, %player, %client, %pos, %vec);
}
}
};
activatePackage(testBrickActivate);
« Last Edit: October 26, 2011, 01:37:36 PM by jes00 »

Code: [Select]
package testBrickActivate
{
function fxDTSBrick::onActivate(%obj, %player, %client, %pos, %vec)
{
if(%obj.getDataBlock() $= "TestBrickData")
{
messageclient(%client, '','\c3Test: Success!');
Parent::OnActivate(%obj, %player, %client, %pos, %vec);
}
}
};
activatePackage(testBrickActivate);

By the way, jes, you broke the %vec at the start as "$vec," which would be bad in some cases. You also should make sure not to keep it like that, where it never activates unless it's that type of brick.

You also should make sure not to keep it like that, where it never activates unless it's that type of brick.
Code: [Select]
Parent::OnActivate(%obj, %player, %client, %pos, %vec);

If you didn't notice, that is within the If check. That means it will only happen if it is that brick. Bad idea in most cases.

If you didn't notice, that is within the If check. That means it will only happen if it is that brick. Bad idea in most cases.
Oops, thanks.