HELP!!

[RU] artursanzakov
Joined 30/11/2020
Posts 118
10:36 AM 04/12/2022
how to do it, when you click on something, you have an object


BrickGod
Joined 06/09/2019
Posts 3,547
10:45 AM 04/12/2022
It's called interaction


[INC] kringlePringles
Joined 25/06/2019
Posts 111
11:39 AM 04/12/2022
You mean when you click a brick, you'll get that specific tool? You should be more clearer... but then again, you must be new to scripting...


[RU] artursanzakov
Joined 30/11/2020
Posts 118
05:55 PM 04/12/2022
YESSSSSSSSSSSSSSSS


[INC] kringlePringles
Joined 25/06/2019
Posts 111
01:50 AM 05/12/2022
So a small disclaimer: I did not test the code. Yes, it is very faulty of me for assuming that THIS will work without testing it. From this point onwards, I’m going with my intuition. If you need to know more on how to make scripts for playable sets, check these links out:

- [the official node-hill documentation] https://brickhill.gitlab.io/open-source/node-hill/modules.html
- [Brick Hill Developer Community Resources] https://github.com/Brick-Hill-Developers/Community-Resources

Unfortunately, I had to split this into multiple posts. Hurrah, post farming...

=== Step 0 ===

First thing's first is to add a brick into your set that has a name. You pretty much just do that in your brick hill workshop (either the official or with Brick Builder). Let's call our currently hypothetical brick "swishy giver". Make sure to REMEMBER the brick’s name correctly, unless you are expecting it to not work correctly.


[INC] kringlePringles
Joined 25/06/2019
Posts 111
01:51 AM 05/12/2022
=== step 1 ===

Next we go to our code editor and define our tool:

//create a new tool called “sword” and assign it to the variable [toolSword].
//this allows us to reference the tool within the script it was written in.
let toolSword = new Tool(“sword”);
toolSword.model = 2930; //set the model

//once it is activated (i.e. player clicks while tool is equipped)
toolSword.on(“activated”, (p) => {
//create an array of ALL players that is not the attacking player via filtering via player name and netId
let notP = Game.world.players.filter(notP => notP.name !== p.name && notP.netId !== p.netId);

//if attacking player is within distance, deduct the not-player’s health
if (Game.pointDistance3D(p, notP) <= 50) notP.setHealth(notP.health – 10);
})

Now that we created our tool, we get onto making a brick that GRANTS it.


[INC] kringlePringles
Joined 25/06/2019
Posts 111
01:53 AM 05/12/2022
There are two ways we are taking this: One of which is if we are making only one brick that gives an item. In this case, we want “swishy giver” to give a sword.

//first we find the brick named “swishy giver” and assign it to the variable [swordGiver]
let swordGiver = Game.world.bricks.find(brick => brick.name === “swishy giver”);

//let it be clickable and set distance (not in studs) to 100
swordGiver.setClickable(true, 100)

//DO NOT turn off collision for bricks, that prevents us from ever clicking the brick

//then, once it is clicked, we defined [p] for player and [s] for secure (which checks if player is within clicking distance)
swordGiver.clicked((p, s){

//if it is not secured OR if player already has the sword inside their inventory
if (!s || !p.inventory.includes(p.inventory.find(t => t.name === toolSword.name && t.id === toolSword.id))) return //do nothing >
p.addTool(toolSword); //otherwise add the sword tool to their inventory
}


[INC] kringlePringles
Joined 25/06/2019
Posts 111
01:54 AM 05/12/2022
So we are able to create a brick that gives players a sword, but what if you want multiple bricks to do give the exact same tool? This is the second method, where we filter for all the bricks with the name “swishy giver”.

Assuming you have read this entire list of posts and added multiple bricks with the exact name “swishy giver”, we will replace the find() function with filter(), as we have used earlier for the players:

//first we create an array that filter for any bricks named “swishy giver” and assign it to the variable [swordGiver]
let swordGiver = Game.world.bricks.filer(brick => brick.name === “swishy giver”);


[INC] kringlePringles
Joined 25/06/2019
Posts 111
01:55 AM 05/12/2022
//we use a forEach() function to run through every brick inside the array and make them clickable
swordGiver.forEach(brick => {
brick.setClickable(true, 100)

//then, once it is clicked, we defined [p] for player and [s] for secure (which checks if player is within clicking distance)
brick.clicked((p, s){

//if it is not secured OR if player already has the sword inside their inventory
if (!s || !p.inventory.includes(p.inventory.find(t => t.name === toolSword.name && t.id === toolSword.id))) return //do nothing >
p.addTool(toolSword); //otherwise add the sword tool to their inventory
}
})

Hopefully, with all of this, you should be able to have a working tool-giver. Just do not forget to place the code in the user_scripts folder.


[INC] kringlePringles
Joined 25/06/2019
Posts 111
02:01 AM 05/12/2022
No, I do not want to use pastebin. I'm too lazy and/or found it unhelpful with the fact that the looming possibility that any pastes I make may become removed within 6 months in the future of pastebin.

Very scary stuff.

I just realized I should have used the discord attachments. 🤦‍♂️


[RU] artursanzakov
Joined 30/11/2020
Posts 118
03:10 PM 06/12/2022
конечно интересно,но не понятно

1 2