Author Topic: Detect if a brick was planted by a Duplicator/Duplorcator  (Read 2848 times)

there's no ::onDuplicator I suppose, is there a way to do this efficiently? I need to block a brick from being duplicated because it screws things up.

To be technical, to do this might involve checking the tool in your hand onPlant then break;.
« Last Edit: October 21, 2012, 01:01:59 AM by Randomness »

Code: [Select]
function servercmdPlantBrick(%client)
{
%brick = %client.player.tempBrick;
if(%brick.duplicationBrick)
{
//Duplorcator support
}
else if(%brick.dupStartBrick)
{
//Duplicator support
}
else
{
//Was not duplicated.
}
}

Prevents all bricks being planted.

Because that's not copy and paste ready code.
Put the code you want in the commented areas, for example you probably want Parent::serverCmdPlantBrick(%client); in the was not duplicated part

My pet peeve: people who don't even look at the code they've been given and are surprised when the code doesn't work, a.k.a. when the code does exactly as it has been written to do

I figured a parent was missing, I just didnt know which one.

Code: [Select]
package drugDupeCheck
{
function fxDTSBrick::onPlant(%brick)
{
if(%brick.duplicationBrick)
{
if(%brick.isDrug)
{
break;
messageClient(%client, '', "\c0Dont ever try to duplicate your drugs - thats cheating.");
messageAll('', '\c3' @ %client.name @ "\c6attempted to cheat by duplicating drugs!");
}
}
else if(%brick.dupStartBrick)
{
if(%brick.isDrug)
{
break;
messageClient(%client, '', "\c0Dont ever try to duplicate your drugs - thats cheating.");
messageAll('', '\c3' @ %client.name @ "\c6attempted to cheat by duplicating drugs!");
}
}
else
{
parent::onPlant(%client);
//Was not duplicated.
}
}
};
activatePackage(drugDupeCheck);

Again, there's no %brick.duplicationBrick. This does not work like it needs to. Can I just fetch the name of the current wielded tool?

Also I apparently dont know how this works.

First, that's an improper use of break;

Second, neither duplicator copies variables (like isDrug) on duplication. If your drug bricks use a special datablock, you can check if %brick.getDatablock().isDrug, but it won't copy isDrug off the actual brick.

Third, you can get the mounted image by calling %player.getMountedImage(0).getName().

First, that's an improper use of break;

Right then, how do you break the planted brick like that if break; isnt proper?

Right then, how do you break the planted brick like that if break; isnt proper?
%brick.delete();

%brick.delete();

Now hold on.
I've used that before and got some major issues, but when I use
schedule(0,%brick,delete);
It worked a ton better.

%brick,delete or %brick.delete? Is there a difference if its part of a schedule process?

%brick,delete or %brick.delete? Is there a difference if its part of a schedule process?

I'm not a master coder, or anything like that, I'm just going off of my past experience.

It's "," by the way, whenever I would use just "%brick.delete();" if the brick was planted on or next to anything besides the ground plane it would crash my server, but when replaced by "schedule(0,%brick,delete);" it would not.

Yeah, deleting an object in the method it's created in can cause pretty big problems. schedule(0, %brick, delete) would ensure that the brick is removed normally.

Additionally, you'll want to rethink your messages. What happens when someone gets a huge pile of drugs and tries to duplicate it over and over again?

Code: [Select]
package drugDupeCheck
{
function fxDTSBrick::onPlant(%brick)
{
if(%brick.duplicationBrick)
{
echo("Duplicator"); // Debug
if(%brick.getDatablock().isDrug)
{
echo("Is a drug."); // Debug
messageClient(%brick.client, '', "\c0Dont ever try to duplicate your drugs - thats cheating.");
messageAll('', '\c3' @ %client.name @ "\c6attempted to cheat by duplicating drugs!");
schedule(0,%brick,delete);
}
}
else if(%brick.dupStartBrick)
{
echo("Duplorcator"); // Debug
if(%brick.getDatablock().isDrug)
{
echo("Is a drug."); // Debug
messageClient(%brick.client, '', "\c0Dont ever try to duplicate your drugs - thats cheating.");
messageAll('', '\c3' @ %client.name @ "\c6attempted to cheat by duplicating drugs!");
schedule(0,%brick,delete);
}
}
else
{
parent::onPlant(%client);
//Was not duplicated.
}
}
};
activatePackage(drugDupeCheck);