#Ban Items
1 messages · Page 1 of 1 (latest)
Do you want to do something to them if they have it, or just clear the item? If yoh just want to clear the item, you can use tick.json to constantly run a /clear command. You can also use a scoreboard timer if you only want it to happen every few seconds. Here's some info on both of those ideas:
https://wiki.bedrock.dev/commands/mcfunctions.html#tick-json
I mean the whole thing im trying to acheive is just to ban maps from players - its just a survival server, however maps can be made and or found in villages and these maps show player locations on so ideally i wanted just to remove them for that reason.. however i gathered the only way was to tick through the inventory of players check for the item and them just remove it... however after reading iv learnt that i should avoid using ticks as it will slow down the server but i can't think of what action to execute this on players to make it run smoother
- to claify not treasure maps, just the player maps which shows player icons on.
I suppose you can also modify use an animation that's constantly playing that clears the player of maps every 5 seconds or so if you'd rather do that. It requires modifying player.json though and so poses compatability issues. The format of the animation would be like ```json
{
"format_version": "1.16.100",
"animations": {
"animation.player.kill_map": {
"loop": true,
"animation_length": 5.0,
"timeline": {
"0.0": [
"/clear @s filled_map"
]
}
}
}
}
And then you'd add this to player.json under the `description`: ```json
"animations": {
"kill_map": "animation.player.kill_map"
},
"scripts": {
"animate": [
"kill_map"
]
}```
True that’s not a bad idea - however as for server performance … don’t get me wrong the server is just between friends so maybe 8-10 of us at a time. In terms of performance would this impact it doing somthing every 5 seconds ?
I was leaning more to execute something maybe if they was to open a chest of craft bench - this way it limits it to not running all the time…
Again I’m not sure if there’s a function that can check that.. unless I have to go the long winded method of checking which blocks are interacted with and again if this is then checking for every block that’s interacted with would that affect server performance
I don't think that should have a performance issue, it might take some testing though. The problem with running it when they interact with a block is that you can't clear a chests inventory on interaction without running 27 replaceitem commands, and running too many commands at once from a script can cause lag.
And in general, commands only cause lag if you're doing hundreds per tick
Use functions
Using hasitem
@pearl helm
So I looked at using hasItem, but does this only work when the item is interacted with ? I’ll have to have a read up in the morning, problem is a map isn’t used I though, as the user can just scroll to on the hotbar and look down on the map@kinda thing
So the player technically isn’t using the item from what I gathered when I tested
So u want it if they hold the item in clears it?
So yeah ideally if they was to either pickup a map or hold one yeah it would just clear it from their inventory
But remembering that treasures maps also class as maps.. this maps can stay in the inventory’s only the player maps which show player locations on
Needs to be removed
So u want to keep the map that shows players locations
So u want to keep locator map
Sorry that’s my bad, locator maps with player locations on to be banned
All other maps are fine
Yeah that’s fine - but what would be the most efficient way of running this in my .js file. As using a ticker system is bad practise for server performance
Uhh
Not sur
E
If ure not looking for lag execute at @a[hasitem={item=minecraft:locator_map}] run clear @a minecraft:locator_map
Bc it only goes off it someone has one
That’s fine, but that’s an ingame command thou right ? Am more looking for somthing I can put into a behaviour back that runs all the time
Its possible with script
import {world,system,ItemStack} from '@minecraft/server'
system.runInterval(()=>{
let banitems = [
"barrier",
"deny",
"allow",
"bedrock",
"command_block"
]
for(let player of world.getAllPlayers()){
for(let n = 0; n<=35;n++){
let inv = player.getComponent("inventory").container
let id = inv.getItem(n)?.typeId?.split("minecraft:")[1]
if(banitems.includes(id)){
inv.setItem(n, new ItemStack("minecraft:air"))
player.sendMessage("§cYou are not allowed to have that item")
}
}
}
})