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

What can I do to fetch the name of the wielded tool? Thats much easier to do than to go on this wild goose chase.
It also won't work because they can switch to a gun then hit plant.
Post it again, with the %tempBrick fix.

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

This entire setup is botched because even when duplicated correctly, it returns OP 3 anyway. So thats why duplicationBrick and dupStartBrick do not work.

You're checking whether the temp brick is a drug, which would only apply if you duplicated the drug directly. As for why it's not recognizing that the temp brick is duplicated at all, I'm not sure. Did you fully reload this since you last tested it? Try echoing %tempbrick at the start, then calling ID.dump(); with the ID you get. Scroll up and check the datablock, tagged fields, ect.

Since this obviously isnt the road I want to take, and because only checking the directly duplicated brick isnt going to cut it, allow me to instead ask a different question.

How do you detect the presence of a certain brick within a set of duplicated bricks?


Im thinking the easiest way to do this is to package a function of the Duplicator tools.

...or I could just do this from function FxDtsBrick::getStack(%brick,%player) instead of function FxDtsBrick::onPlant(%brick) which is much easier to do because getStack is strictly Duplorcator.
« Last Edit: October 27, 2012, 11:06:14 PM by Randomness »

Thing is, the way you were trying to do it should work, and if it were me, I'd be trying to figure out the problems with that before deciding it's time to start from square 1. If you want to do that, good luck, because it sounds even more complicated and considering the frequency of mistakes we had to fix here, I'm not interested.

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.
I was telling him the function to use, not giving him code to directly implement. Regardless, the reason you're having an issue is because you're deleting the brick before it's been fully initialized, there are no problems unless you call it inside of a function like onPlant where the brick has been literally just made. So in a way you're right, he should use that, but it's pointless to use that in every scenario when it's only important inside ::onPlant.

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.
Commas delimitate arguments, periods signify a method. Schedule is the function, zero is the first argument, the brick is the second, and delete is the third. So, "%brick,delete();" would cause a syntax error, and "schedule(0.%brick.delete);" would also cause a syntax error.

Wtf guys it's %brick.schedule(0,delete);
Both work equally well. There's absolutely zero reason to use one over the other, it's entirely preference. Actually, schedule() has less overhead, so technically it's more efficient and should be used over ::schedule.

How on earth would that work for anyone? Schedule on its own calls a function, not a method. The object reference in the middle is just an object the schedule is tied to; if it's deleted the schedule cancels.

Also, you never got the client's temp brick. You're testing the brick that was actually planted.
Schedule is laid out like this:
schedule(time, object, method, args, args, ...)

If you replace object with a null value like "" or 0 it will call a global function, if you fill in object with something it will call that function as a method on the object. For example, schedule(1000, findClientByName(Jetz), delete); would wait a second before deleting you.

Just loaded up single player, planted a brick, got its ID, and entered schedule(0, 13315, delete);. The brick was still there. You are wrong.
You did it wrong. You are wrong. That is how schedule works, if you don't believe me go type schedule(); in console and watch Torque tell you that you are wrong.

Code: [Select]
%client = %brick.client;
will fix it right?
Yes, along with %brick.getGroup().client; if you wanted to do that, but do it your way because that way just protects for if a client reconnects.



Code: [Select]
package drugDupeCheck {
function fxDTSBrick::onPlant(%brick)
{
%client = %brick.client;
%tb = %client.player.tempBrick;
if((%tb.duplicationBrick || %tb.dupStartBrick) && %tb.getDatablock().isDrug)
{
messageClient(%client, '', "\c0Do not duplicate your drugs.");
schedule(0, %brick, delete); //forget you Jetz
return;
}
parent::onPlant(%brick);
}
};
activatePackage(drugDupeCheck);
« Last Edit: October 28, 2012, 08:14:32 PM by Trinick »

haha, slick just owned you guys.

Schedule is laid out like this:
schedule(time, object, method, args, args, ...)

If you replace object with a null value like "" or 0 it will call a global function, if you fill in object with something it will call that function as a method on the object. For example, schedule(1000, findClientByName(Jetz), delete); would wait a second before deleting you.
You did it wrong. You are wrong. That is how schedule works, if you don't believe me go type schedule(); in console and watch Torque tell you that you are wrong.
How about you actually test it.
Open the console, type this in:
canvas.schedule(1000, popdialog, consoledlg);
Wait one second. The console closes.
Then try this:
schedule(1000, canvas, popDialog, consoledlg);
Wait one second. forgetall happens.
Now start a server. Define this function:
function colorbrick(%brick){%brick.setcolor(2);}
Plant a brick. Get its ID. Do:
schedule(1000, 0, colorBrick, ID);
Wait one second. Works as expected.
Now do:
schedule(1000, 0, colorBrick, ID); ID.delete();
Wait one second. Console error.
Plant a new brick, get its ID. Do the original schedule again, but with the ID as the second argument.
schedule(1000, ID, colorBrick, ID);
Wait one second. Works fine because it didn't try and call a nonexistent method.
You can also try:
schedule(1000, ID, setColor, 1);
Wait one second. Nothing happens. Because it doesn't call an existing method either, even with no function as an alternative.
Now for the grand finale:
schedule(1000, ID, colorBrick, ID); ID.delete();
Wait one second. No console error.

This is because schedule as a function works as I have described. It does not call methods. It only calls functions. You are wrong.

The nature of that second argument is outlined here.

hey jetz
a method is just whatever's inside the function
so technically

it calls both

hey jetz
a method is just whatever's inside the function
so technically

it calls both
A method is just a word for a function specific to an object or class; something you'd see in ID.dump(); "Function" can refer to either, but in comparison to a method, a function is something you'd find in dumpConsoleFunctions();.

A method is just a word for a function specific to an object or class; something you'd see in ID.dump(); "Function" can refer to either, but in comparison to a method, a function is something you'd find in dumpConsoleFunctions();.
Quote from: http://docs.roxen.com/pike/7.0/tutorial/fundamentals/concepts.xml
Function

Most programming languages allow you to divide your program into smaller parts. These can be called "sub-routines", "procedures", "functions" or "methods".
I'm not joking bro

I'm not joking bro
Good choice of citation. I like how the item directly below the one you quoted supports my point even more.
Method

In object-oriented programming (which is explained more below), functions belong to a certain class, and they work mainly with the data belonging to that class. Such a function, which belongs to a class, is usually called a "method".

it says it can be called that,
as in the term can mean either.

Note the "usually."

it says it can be called that,
as in the term can mean either.

Note the "usually."
A method is a type of function. Functions that are methods can be called methods. The word "method" refers to a function because a method is a type of function.

Honestly though, this has just as much bearing on my argument above as pointing out grammatical errors.