Author Topic: [SOLVED] brick::onActivate Does Nothing  (Read 1109 times)

Are you sure %client is actually a client?
In there you should add:
echo(%client.getClassName());

Also, %brick.getDatablock(); should be %brick.getDataBlock().getName();
Thanks, this worked.

And a thank you to everyone to posted ITT.  The final code is;

Code: [Select]
datablock fxDTSBrickData (smallFoodBrick)
{
brickFile = "./smallfood.blb";
category = "Special";
subCategory = "DayZ";
uiName = "1 Food";
iconName = "";
};

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

if(%brick.getDatablock().getName() $= "smallFoodBrick")
{
%client.food++;
commandtoclient(%client,'centerPrint',"You found food.");
}
}
};
activatePackage(FoodBricks);

You may want to turn %brick.getDatablock().getName() into a variable instead of calling those functions every time if you plan to add mediumFoodBrick and largeFoodBrick
Code: [Select]
datablock fxDTSBrickData (smallFoodBrick)
{
brickFile = "./smallfood.blb";
category = "Special";
subCategory = "DayZ";
uiName = "1 Food";
iconName = "";
};

package FoodBricks
{
function fxDTSBrick::onActivate(%brick, %obj, %client, %pos, %dir)
{
parent::onActivate(%brick, %obj, %client, %pos, %dir);
%data = %brick.getDatablock().getName();
if(%data $= "smallFoodBrick")
{
%client.food++;
commandtoclient(%client,'centerPrint',"You found food.");
}
}
};
activatePackage(FoodBricks);

You may want to turn %brick.getDatablock().getName() into a variable instead of calling those functions every time if you plan to add mediumFoodBrick and largeFoodBrick
Code: [Select]
datablock fxDTSBrickData (smallFoodBrick)
{
brickFile = "./smallfood.blb";
category = "Special";
subCategory = "DayZ";
uiName = "1 Food";
iconName = "";
};

package FoodBricks
{
function fxDTSBrick::onActivate(%brick, %obj, %client, %pos, %dir)
{
parent::onActivate(%brick, %obj, %client, %pos, %dir);
%data = %brick.getDatablock().getName();
if(%data $= "smallFoodBrick")
{
%client.food++;
commandtoclient(%client,'centerPrint',"You found food.");
}
}
};
activatePackage(FoodBricks);

It's basically the same thing since it's only called once plus, it's not like you're storing it to a global variable, so you are creating that new local variable every time. But it's good practice anyway.

It's basically the same thing since it's only called once plus, it's not like you're storing it to a global variable, so you are creating that new local variable every time. But it's good practice anyway.
It's better to store it as a variable instead of calling %brick.getDatablock().getName() 5 times if you want to check if it is another datablock.

It's better to store it as a variable instead of calling %brick.getDatablock().getName() 5 times if you want to check if it is another datablock.

Yeah, you're right, but he only had it called once so it was okay how he had it.