#Custom commands not working?
1 messages · Page 1 of 1 (latest)
are you on stable or beta?
because this is the old syntax
@worn bay you'll need to use this instead: world.beforeEvents.chatSend.subscribe
btw, are you trying to do a slot selection system for each inventory slot?
One message removed from a suspended account.
One message removed from a suspended account.
I have a really good one https://github.com/GlitchyTurtle/Avatar-Addon/tree/v1.20.1
hmm, can I see your manifest?
One message removed from a suspended account.
ah, it's outdated
One message removed from a suspended account.
One message removed from a suspended account.
use this ```json
"capabilities": [
"script_eval"
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.3.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.1.0-beta"
}
]
Actually, here, just edit the other stuff to your liking: ```json
{
"format_version": 2,
"header": {
"name": "§6Avatar §3Addon §8[1.20.1] [BP]§r",
"description": "Adds the bending seen in avatar the last airbender to minecraft! All credit to GlitchTurtle32!",
"uuid": "13fbd8d8-7ff3-492d-9b92-94ff4a1855c2",
"version": [
3,
1,
0
],
"min_engine_version": [
1,
20,
0
]
},
"modules": [
{
"type": "script",
"language": "javascript",
"uuid": "b7055392-4154-4aa8-813f-afa6291f1056",
"entry": "scripts/index.js",
"version": [
0,
1,
0
]
}
],
"capabilities": [
"script_eval"
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.3.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.1.0-beta"
}
]
}
again, how many chat commands are you going to create? Cause it might be a good idea to implement a handler for those
instead of just a really long switch statment
One message removed from a suspended account.
also, for tick event, you're gonna need to do ```js
system.run(function runnable() {
system.run(runnable);
tickEvent();
});
One message removed from a suspended account.
it's definitely a manifest thing
give me a minute
i'll fix the code
just found the issue
chatsend is a before event, so it's readonly
to run commands from that, you'll need a system.run
One message removed from a suspended account.
I'm fixing the code rn
I'll send it back working
import { world, system } from '@minecraft/server';
// Events
world.beforeEvents.chatSend.subscribe(eventData => chatSend(eventData));
// Tick event
system.run(function runnable() {
system.run(runnable);
tickEvent();
});
// ----- in a different file probably
function tickEvent() {
for (const player of world.getPlayers()) {
let slot = player.selectedSlot;
setScore(player, "hotbar", slot);
}
};
// ----- in a different file probably
const commands = {
help: helpCommand,
}
function chatSend(eventData) {
const player = eventData.sender;
const message = eventData.message;
if (!message.startsWith("!")) return;
const args = message.slice(1).split(/ +/);
const commandName = args.shift().toLowerCase();
system.run(() => {
if (!(commandName in commands)) return player.sendMessage("That's not a commmand you can use!")
commands[commandName](player, args);
message.cancel = true;
});
};
// ----- in a different file probably
function helpCommand(player, args) {
console.warn(args);
}
// ----- in a different file probably
/**
* Set the score of a player or other entity
* @param {Entity|string} target The entity or dummy player to change the score of.
* @param {string} objective The objective to change the score on.
* @param {number} amount The amount to change the score by.
* @param {boolean} add If the score should stack on top of the previous value set.
* @returns {number} The new score that was set, or NaN if no objective or initial entity score was found or set.
*/
export function setScore(target, objective, amount, add = false) {
try {
const scoreObj = world.scoreboard.getObjective(objective);
const score = (add ? scoreObj.getScore(target.scoreboardIdentity) : 0) + amount;
target.scoreboardIdentity.setScore(scoreObj, score);
return score;
} catch (error) {
return undefined;
};
};
there's a very basic command handler and args system
in this example, the help command gets an array of the arguments, like if the user typed !help flame passive it would give the help command ['flame', 'passive'] which should make it much eaiser to sort through
@worn bay
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
how so? Like other commands?
One message removed from a suspended account.
For passives, if it’s list of text, I’d use a dictionary data structure
I can’t help right now, but I’ll send an example in a couple minutes
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
That’s what I’ll show in a sec
updated code ```js
import { world, system } from '@minecraft/server';
// Events
world.beforeEvents.chatSend.subscribe(eventData => chatSend(eventData));
// Tick event
system.run(function runnable() {
system.run(runnable);
tickEvent();
});
// ----- in a different file probably
function tickEvent() {
for (const player of world.getPlayers()) {
let slot = player.selectedSlot;
setScore(player, "hotbar", slot);
}
};
// ----- in a different file probably
const commands = {
help: helpCommand,
}
function chatSend(eventData) {
const player = eventData.sender;
const message = eventData.message;
if (!message.startsWith("!")) return;
eventData.cancel = true;
const args = message.slice(1).split(/ +/);
const commandName = args.shift().toLowerCase();
system.run(() => {
if (!(commandName in commands)) return player.sendMessage("That's not a commmand you can use!")
commands[commandName](player, args);
});
};
// ----- in a different file probably
const help = {
flame: {
passive: "test text goes here",
heavy: "other stuff idk"
}
}
function helpCommand(player, args) {
console.warn(args);
player.sendMessage(help[args[0]][args[1]]);
}
notice the ```js
const help = {
flame: {
passive: "test text goes here",
heavy: "other stuff idk"
}
}
it navigates the tree based on your args
like if you put !help flame heavy, it would send "other stuff idk"
if you ever need help with gametest, feel free to send me a DM
One message removed from a suspended account.
Sure, you’ll have to change how you call it though. If you’re using just tellraw though, it’s much better this way
If you want to insert player name or score, you can do that super easily with the current way
One message removed from a suspended account.
So run command then?
Switch sendMessage for runCommand and suddenly the descriptions are commands
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
got this to add some permissions ``````
what is this?
ah nice