Author Topic: fxDTSBrick::onPlant(%this, %obj) done goofed? [RESOLVED]  (Read 906 times)

Code: [Select]
function fxDTSBrick::OnPlant( %this, %obj )
{
echo("attempting to plant");

%client = %obj.getGroup().client;
// %db = %obj.getDataBlock();

if( isObject( %obj ) )
{
echo("brick exists!");
%req = %this.brickSizeX * %this.brickSizeY * %this.brickSizeZ;

if( %client.Plastic < %req )
{
echo("Not enough plastic!");
commandToClient( %client, 'centerPrint', "\c6You need\c3" SPC %req SPC "\c6plastic to plant this brick.", 2 );
return;
}
else
{
echo("Enough plastic!");
commandToClient( %client, 'centerPrint', "\c6You planted a brick for\c3" SPC %req SPC "\c6plastic.", 2 );
%client.Plastic -= %req;
parent::onPlant( %this, %obj );
}
}
}

This won't work.
At all.
Not even echo is called.
Yes, this is packaged.

I have no idea why this does not work, seeing as in CityRPG, this bitch works just fine.

Honestly, I need to get this function work on plant, at least, even if there are errors.
« Last Edit: February 28, 2013, 08:23:22 AM by Crystalwarrior »

fxDTSBrick::onPlant has the arguments %this
fxDTSBrickData::onPlant has the arguments %this, %obj

Choose one, don't mix them.
I recommend the latter.

Also, not calling the parent in this function will not prevent the brick from being planted.
This is a callback, it runs after the brick was planted.

Yeah, port, I did try both variants: the first one and the second one.
I ended up mixing up the two though.
But the problem is, NONE of the variants worked at all.
It just won't run the function.

adjkaffdaj what do

You're thinking of %obj as the brick, while %this is actually the brick. Use function fxDTSBrick::OnPlant(%this) for your first line and change all instances of %obj to %this

If his echo isn't even appearing though, that would mean he either packaged it wrong or didn't activate the package.

If his echo isn't even appearing though, that would mean he either packaged it wrong or didn't activate the package.
Or he also could have a script with a syntax error, leading him thinking that the script works; and the piece of script doesn't.

change the namespace to fxDTSBrickData and see if that works (don't change anything else)

if not possibly consider packaging serverCmdPlantBrick instead.

the client's temporary brick is %client.player.tempBrick if you decide to go with the latter

This piece is 100% correct, both are called when planting a brick, and loading a save.

Code: [Select]
package blah
{
function fxDTSBrick::onPlant(%this)
{
parent::onPlant(%this);
//Your code before or after the parent.
}

function fxDTSBrick::onLoadPlant(%this)
{
parent::onLoadPlant(%this);
//Your code before or after the parent.
}
};
ActivatePackage(blah);
« Last Edit: February 28, 2013, 04:12:05 AM by Honorabl3 »

Just for reference, the above code goes in a package.

Oh, forgot to mention. Editted, thanks.

I guess the problem lies in the packaging/files, then.
You see, I am making this a gamemode, and I put common.cs in "scripts" folder inside the gamemode folder.
The script executes properly, and even the package works fine, but only the onPlant function won't do stuff.

EDIT: ...what the forget. Suddenly onPlant works flawlessy today.
ogm wtf badspot pls fix ok
« Last Edit: February 28, 2013, 05:46:43 AM by Crystalwarrior »

Ok stop

You're trying to blame others for it not working, while there's a 99.9% chance it's completely your own fault

Ok stop

You're trying to blame others for it not working, while there's a 99.9% chance it's completely your own fault

Well, if it really was my fault, I guess it has to do with setmodpaths(getmodpaths()); exec("addonstuffhere"); not working as good as I'd like it to.
Or it had to do with missing datablocks.cs file that I tried to execute from server.cs :V