Jump to content

[1.12.2] give a player a scripted block w/script inside


Maxwelllondon

Recommended Posts

I have a scripted block designed to summon an item above it if a player scoreboard is >100, then remove 100 from scoreboard.

function tick(event) {
var player = event.block.world.getAllPlayers()[0].displayName;
var cash = event.block.world.getScoreboard().getObjective('Cash').getScore(player).getValue();
if (cash >= 100){
event.block.executeCommand ('/summon Item ~ ~1 ~ {Item:{id:"minecraft:iron_ingot",Count:1b}}');
event.block.executeCommand ('/scoreboard players remove @p Cash 100')
}}

 

Now I would like to give this block to the player, so he can place it where he likes in order to summon the item where he need it.

How can I do?

I thought i should give the scripted block w/script thru /give command, but I don't know how.

Thanks for any suggestion.

 

EDIT: the script is written in Javascript.

EDIT2: I managed to /give the block with script as NBTtag, but when placed down there's no script inside it.

Edited by Maxwelllondon
Link to comment
Share on other sites

Why are you using the scoreboard and commands when you could write the stuff properly? Also, what language are you writing in and how did you start writing in it. (i.e. How are you using what seems JavaScript)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

Why are you using the scoreboard and commands when you could write the stuff properly? Also, what language are you writing in and how did you start writing in it. (i.e. How are you using what seems JavaScript)

First of all, this is one of my first scripts, so I didn't even know it could be writed better than this. It works, then for me it's fine.

But, if you have any suggestion for a better code I'm happy to read you.

Second, I couldn't find any APIs that remove points. I found setValue only.

And yes, I'm writing with JavaScript.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.