Author Topic: Making a bricktype respond to onActivate in script.  (Read 792 times)

So I've created a brick type, OilSource with it's code below:

Code: [Select]
datablock fxDtsBrickData(brick8x8Data)
{
category = "Bricks";
subcategory = "Oil Mod";

uiName = "Oil Source";

specialBrickType = "";

adminOnly = 1;
};

And I want to make it so when you click it (activate) it will automatically, lets say, make a message appear on your screen. (center message) I didn't really want to do this with simply adding events in though, I wanted to do it more like the employment/banking bricks in the RP mod. And yes, I tried to look though the code but when I did nothing I tried to use there worked. For example:

Code: [Select]
datablock fxDtsBrickData(PipeDat : brick2x4Data)
{
category = "Bricks";
subcategory = "Oil Mod";

uiName = "Pipeline";

specialBrickType = "";

adminOnly = 0;
};

function PipeDat::Activate(%datablock, %client)
{
messageClient(%client, '', "\c3Employment Office");
messageClient(%client, '', "\c31. \c6Job list");
messageClient(%client, '', "\c32. \c6Specify job");
messageClient(%client, '', "\c33. \c6Get job");
return true;
}

Doesn't do anything when I click a "Pipe" brick.

I'm no scripter, but wouldn't it be 'onActivate'?

I may be wrong but I'm pretty sure you'd have to package fxDtsBrick::onActivate. An alternate method would be to add the events you want to the brick when it's planted.

I may also be wrong but you may have to add a OnActivate event to the brick in order for an OnActivate override to work, that is, I don't think it's called if you click a brick that doesn't have onactivate involved with it.


I may also be wrong but you may have to add a OnActivate event to the brick in order for an OnActivate override to work, that is, I don't think it's called if you click a brick that doesn't have onactivate involved with it.


Last time I checked it worked without needing an event. But that was several versions ago.

Okay I suppose I'll just make it automatically put events in like the JVC content. But is there anyway to lock events for a particular brick upon planting? (brick type) Also, is there anyway to access all bricks with one variable?


That may break the default brick type.

Yeah I fixed that it's now "OilSource : brick8x8Data".
Also I tried this code I found in another thread but although it activates the package and dosn't bring up any syntax errors it doesn't do anything at all:

Code: [Select]
package azjact
{

function fxDtsBrick::onPlant(%brick)
{
Parent::onPlant(%brick);
//if(%brick.getDatablock() != PipeDat)
// return;
%oldWrenchBrick = %brick.client.wrenchBrick;
%brick.client.wrenchBrick = %brick;

%onPlayerTouchIndex = inputEvent_GetInputEventIdx("onPlayerTouch");
%addHealthIndex = outputEvent_GetOutputEventIdx("Player","addHealth");
%playerIndex = inputEvent_GetTargetIndex("fxDTSBrick",%onPlayerTouchIndex,"Player");

%damageAmount = 10; //causes 10 damage
serverCmdAddEvent(%brick.client,1,%onPlayerTouchIndex,0,%playerIndex,-1,%addHealthIndex,-%damageAmount);

%brick.client.wrenchBrick = %oldWrenchBrick;
}

};


activatePackage(azjact);



It's supposed to make every brick planted have the event 'onPlayerTouch->Player->AddHealth(-10)' or something like that, but it does nothing.

Last time I checked it worked without needing an event. But that was several versions ago.
fxDTSBrick::onActivate is still called regardless of having events.
fxDTSBrick::onPlayerTouch needs events to be called, though.

fxDTSBrick::onActivate is still called regardless of having events.
fxDTSBrick::onPlayerTouch needs events to be called, though.

So it is onActivate, and the on is needed, but that still leaves a lot of questions.

So it is onActivate, and the on is needed, but that still leaves a lot of questions.
Such as?