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

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

function smallFoodBrick::onActivate(%cl)
{
%cl.food += 1;
%cl.centerPrint("You found food!");
}

Supposed to give the player 1 food and display it on his/her screen, but when clicked on the brick does absolutely nothing!
« Last Edit: June 27, 2012, 11:58:04 PM by brickybob »

Well, %cl is never defined...

Well, %cl is never defined...
Whoops!  I copy-pasted this from the gist I gave to Nullable, I changed it to %cl since then.

Op fixed.

Whoops!  I copy-pasted this from the gist I gave to Nullable, I changed it to %cl since then.

Op fixed.

Well, %cl would be referring to the brick, not any actual client.

Code: [Select]
smallFoodBrick::onActivate(%brick)
{
    %client = %brick.client;
    %client.food++;
    %client.cenerPrint("You found food!");
}

Why is %client defined as the brick's owner?

The major issue is that there's supposed to be multiple args for onActivate.

IIRC, the second argument to onActivate is the player, and the third might be the client. If it's not, just get the client from the player.

Code: [Select]
function smallFoodBrick::onActivate(%data,%brick,%player)
{
    %player.client.food++;
    commandtoclient(%player.client,'centerPrint',"You found food");
}

Code: [Select]
smallFoodBrick::onActivate(%brick)
{
    %client = %brick.client;
    %client.food++;
    %client.cenerPrint("You found food!");
}
onActivate is an fxDtsBrickData class function, therefore you need the datablock (smallFoodBrick) the brick, and the activator.
In this code you provided, %client would be the brick's owner, not the activator. Also, field "client" on a brick is only applied when the player manually plant's it, if the server loads bricks and the client doesn't connect it will give you invalid objects. %brick.getGroup().client works when the brick is loaded and not manually planted. Also, that is not in function form.

Code: [Select]
function smallFoodBrick::onActivate(%data,%brick,%player)
{
    %player.client.food++;
    commandtoclient(%player.client,'centerPrint',"You found food");
}

onActivate is an fxDtsBrickData class function, therefore you need the datablock (smallFoodBrick) the brick, and the activator.
In this code you provided, %client would be the brick's owner, not the activator. Also, field "client" on a brick is only applied when the player manually plant's it, if the server loads bricks and the client doesn't connect it will give you invalid objects. %brick.getGroup().client works when the brick is loaded and not manually planted. Also, that is not in function form.
Wow what the hell was I doing. This is a lesson kids, don't code while distracted

onActivate is an fxDtsBrickData class function, therefore you need the datablock (smallFoodBrick) the brick
First parameter is a brick, not the datablock.

First parameter is a brick, not the datablock.
Which is why it's an fxdtsbrick function and not an fxdtsbrickdata function.

It's (fxdtsbrick, activating object, activating client)

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

if(%brick.getDatablock() $= "smallFoodBrick")
{
%client.food++;
commandtoclient(%client,'centerPrint',"You found food.");
}
}
};
activatePackage(FoodBricks);
My bad, I thought onPlant was an fxDtsBrick and fxDtsBrickData function just like onPlant.

Code: [Select]
[quote author=Plexious link=topic=198516.msg5426598#msg5426598 date=1340849745]
-snip-
activatePackage(FoodBricks);
My bad, I thought onPlant was an fxDtsBrick and fxDtsBrickData function just like onPlant.
[/quote]
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() $= "smallFoodBrick")
{
%client.food++;
commandtoclient(%client,'centerPrint',"You found food.");
}
}
};
activatePackage(FoodBricks);
For some reason, it still does not work.

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

Also, %brick.getDatablock(); should be %brick.getDataBlock().getName();
« Last Edit: June 27, 2012, 11:46:40 PM by elm »