Author Topic: onPlant gets called regardless of certain planting errors.  (Read 1265 times)

So, as of v21, when I plant the brick in the air, it will still call the onPlant function even though the brick itself did not plant. This causes some bad errors to happen.
Here's my onPlant code if necessary:
Code: [Select]
function fxDTSBrickData::OnPlant( %this, %obj )
{
parent::onPlant( %this, %obj );

if( %this.isOre || %this.isTree )
{
%obj.resources = %this.resources;
%obj.health = %this.maxHealth;
}

%client = %obj.getGroup().client;

if( isObject( %obj ) )
{
if( %this.adminOnly )
{
if( %client.isAdmin )
{
return;
}
else
{
commandToClient( %client, 'centerPrint', "\c6You are not permitted to plant this brick.", 2 );
%obj.schedule(0, "delete");
return;
}
}

if( %client.buildMode )
{
return;
}

%player = %client.player;

%found = false;
for( %i = 0; %i < %player.getDataBlock().maxTools; %i++ )
{
if( %player.tool[ %i ].getName() $= "gmsHammerItem" )
{
%found = true;
}
}

if( !%found )
{
commandToClient( %client, 'centerPrint', "\c6You must have a building hammer to build!", 2 );
%obj.schedule(0, "delete");
return;
}

%req = MCeil( ( %this.brickSizeX * %this.brickSizeY * %this.brickSizeZ ) * (60/100) );

if( %req > 1024 )
{
commandToClient( %client, 'centerPrint', "\c6This brick cannot be planted.", 2 );
%obj.schedule(0, "delete");
return;
}
if( %client.resources["wood"] < %req )
{
commandToClient( %client, 'centerPrint', "\c6You need\c3" SPC %req SPC "\c6wood to plant this brick.", 2 );
%obj.schedule(0, "delete");
}
else
{
commandToClient( %client, 'centerPrint', "\c6You planted a brick for\c3" SPC %req SPC "\c6wood.", 2 );
%client.resources["wood"] -= %req;
%client.strandedBottomPrint();
%obj.cost = %req;
}
}
}

Any idea how to resolve this problem?

Code: [Select]
function fxDTSBrickData::OnPlant( %this, %obj )
{
parent::onPlant( %this, %obj );
if(%obj.isPlanted)
{
//logic here
}
}

Alright, now my onPlant completely refuses to work even though I didn't change anything.
I heard lots of people say that onPlant function can just break randomly...

I heard lots of people say that onPlant function can just break randomly...

this is only true for miniGameCanDamage

this is only true for miniGameCanDamage
In any case, the entire function broke and I can't seem to fix it.
I even copy-pasted the WORKING code from here and it didn't help at all.
Any idea on what to do..?

I know i'm off topic but... What's with the avatars......

I know i'm off topic but... What's with the avatars......

What are you talking about?!

I know i'm off topic but... What's with the avatars......
What's up with them?

I know i'm off topic but... What's with the avatars......

Huh?

What's up with them?
Certain community members have been infected with the mlp epidemic


Bump.
Guys, are there any solutions to the onPlant function not being called AT ALL?
It started happening recently. I tried to run it in different gamemodes and places, and it does nothing at all.

Bump.
Guys, are there any solutions to the onPlant function not being called AT ALL?
It started happening recently. I tried to run it in different gamemodes and places, and it does nothing at all.
Run trace() and tell us what happens.

Hmm...  I know cashmod2 does the same sort of thing you're trying to do.  But I haven't used it in a while so I don't know if it even still works.  Ill test it out when I get home, but in the meantime, maybe you could look at that.

Or maybe I'll just paste the plant code from it here and save you the trouble.
Code: [Select]
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
if(!%e)
{
%c = getbrickgroupfromobject(%brick).client;
if(isObject(%c) && isObject(%c.player) && isObject(%c.player.tempbrick))
{
%vol = %c.player.tempbrick.getVolume();
%cost = $Cash::BrickCostPerVolume / 10;
%amt = mFloatLength(%c.cashObj.cash,2);
if(%amt < %cost * %vol)
{
commandtoclient(%c,'centerprint',"\c6You need" SPC CashStr(%cost * %vol,"") SPC "\c6to plant this brick.",2);
%brick.schedule(0,"delete");
} else {
%c.cashObj.mod("Cash",0 - (%cost * %vol));
}
}
}
}

plant returns a value for errors

plant probably calls onPlant inside of it regardless

you may want to package plant instead and do something like

%r = parent::Plant(%this);

and then

if(%r !$= 0)
   return %r;



similar to above