Author Topic: Brick To Script  (Read 1932 times)

Hi all!
How would I go about making a brick fire off a function in the server scrips? For example, if you click a brick it will deduct their in game coins and give them an item?

I've looked at the Castle Crashers game mode because the /setdiff command fires a brick relay

Code: [Select]
_setDiffEasy.firerelay();
I'm trying to make the brick call the function, so like
Code: [Select]
function _buyItem.onActivate()Would this work?

Thank you!

I took your approaches as well before but I realized it wasn't practicall. The best way is to package

fxDTSBrick::onActivate(%this,%client)

And check if the brick is the one you want. You can do this with a different brick datablock (if( %this.getDatablock().uiName $= "ATM")) or by brick name (if(%this.getName() $= "_ATM"))


fxDTSBrick is ANY kind of brick. I believe you can package specific brick datablocks but I am unsure (as in use atmBrickDatablock::onActivate)


Not really. He wants a code segment to be executed when something happens, not register an event.

But if OP wanted to register an event but communicated it incorrectly, well, the link is right there in your post.

I took your approaches as well before but I realized it wasn't practicall. The best way is to package

fxDTSBrick::onActivate(%this,%client)

And check if the brick is the one you want. You can do this with a different brick datablock (if( %this.getDatablock().uiName $= "ATM")) or by brick name (if(%this.getName() $= "_ATM"))


fxDTSBrick is ANY kind of brick. I believe you can package specific brick datablocks but I am unsure (as in use atmBrickDatablock::onActivate)

Thank you, this is exactly what I'm looking for, I knew about the fxDTSBrick part of things, I was unsure on how to check the brick name etc, but thank you!

Brick names have an underscore in the beginning. Use strreplace to remove it or add _ when comparing the names to a string.

The best way is to package

fxDTSBrick::onActivate(%this,%client)

No, it's not. Now you added a completely useless extra function call to every brick being activated.

Are you sure? I'm certain that RPCore uses that.

It would make sense if you have loads of bricks that you want to handle, but OP is asking for just one.

For example,

function _buyItem::onActivate(this, %player, %client, %pos, %vec)
{
    //do stuff

    parent::onActivate(%this, %player, %client, %pos, %vec);
}

would be called for the named brick he uses.
« Last Edit: March 11, 2016, 11:12:33 AM by Zeblote »

Did not know that. Good to know.


Also quick edit, it's

FxDTSBrick::onactivate(%brick,%player,%loc,%rot)

Not fxDTSBrick::onActivate(%brick,%client)

Thanks for your responses! thanks for the fix too, Zeblote.

Really appreciate it

Note, if you go down the named brick route: It will work for anyone who sets that name to a brick.

Note, if you go down the named brick route: It will work for anyone who sets that name to a brick.

I am aware, I'm making a gamemode for my little brother so when it'll be a mini-game with no building involved

I can't seem to get this to work, here's the code I'm using. The console log says that the file is being executed and the brick I place, I call 'buyItem' (without the quotes)

What am I doing wrong?

Code: [Select]
if(isPackage(BrickControl)) {
deactivatePackage(BrickControl);
}

package BrickControl {
function _buyItem::onActivate(%this, %player, %client, %pos, %vec)
{
messageClient(%client, '', "\c6This is a test.");

parent::onActivate(%this, %player, %client, %pos, %vec);
}
};
activatePackage(BrickControl);

There's no %client in the arguments. You need to use %player.client