Scripting Help

Author Topic: Scripting Help  (Read 1770 times)

Hello. Currently I am working on an addon that lets only admins build.
Here is my code:
Code: [Select]
package BuildingBlocker
{
function gameConnection::OnClientEnterGame(%this,%obj,%a,%b,%c,%d,%e)
{
%this.buildallow = 0;
Parent::OnClientEnterGame(%this,%obj,%a,%b,%c,%d,%e);
}
function fxDTSbrick::Plant(%brick, %client, %obj)
{
%e = Parent::Plant(%brick);
if(!%e)
{
%c = getBrickGroupFromObject(%brick).client;
if(isObject(%c) && isObject(%c.player) && isObject(%c.player.tempbrick))
{
if(%c.isAdmin)
{
Parent::Plant(%brick);
}
else if(%c.buildallow == 1)
{
Parent::Plant(%brick);
}
else
{
commandToClient(%c,'centerprint',"\c7Building is not enabled for players.",2);
%brick.schedule(0,"delete");
%c.player.tempbrick.delete();
}
}
}
}
};

activatePackage("BuildingBlocker");

It removes the ghost brick once they plant the brick, but they are still able to plant their bricks.
I am wondering how to make it so it instantly removes the ghost brick once it is placed.

Return 6 instead of deleting the brick and it'll prevent the brick from being planted. You'll also want to return the parent when you parent the function.

You may use serverCmdPlantBrick(%client) and use the parent if they are an admin.

Sorry, I wasn't descriptive enough.
In my code I already had it to make sure they weren't able to plant bricks.
What I am looking for is the function or how to make it so they are unable to place their ghost bricks.
Thanks in advance, Medieval.

All I need to know is the function of placing a ghost brick.
I already have the one for planting bricks.

does it show up in a trace?
i do remember the ghost brick is part of their brickgroup, in case there's no function to prevent it directly

You should still make the changes I recommended. There's currently a console error when a non-admin plants a brick.

I'd either use BrickDeployProjectile::onCollision or fxDTSBrick::onAdd and check if isPlanted is false.

One last thing before I am done, I have finished this and ghost bricks do not place anymore.
But even as admin I cannot place them.
I am wondering what I have to put in the code to keep the ghost brick as admin or with permission.
Code: [Select]
function fxDTSBrick::onAdd(%brick, %client, %obj)
{
%c = getBrickGroupFromObject(%brick).client;
if(isObject(%c) && isObject(%c.player) && isObject(%c.player.tempbrick))
{
if(%c.isAdmin)
{
// Here
return;
}
else if(%c.buildallow == 1)
{
// Here
return;
}
else
{
commandToClient(%c,'centerprint',"\c7Building is not enabled for players.",2);
%brick.schedule(0,"delete");
%c.player.tempbrick.delete();
}
}
}

(In the // Here part)

parent the normal function where you want to be able to build normally

Thank you!
I have finished the addon.
Lots of love!

Using onAdd can create problems if a lot of bricks are being planted at the same time, id rather just use the brick tool check since it’s just an admin plant check