#Change teams in finishUsing item?

44 messages · Page 1 of 1 (latest)

strong cargo
#

Im trying to make an item that allows a person to change their team from A to B and from B to A. This however i cannot figure out how to do with the finishUsing function inside item registry setup. Anyone able to help me out as the wiki doesnt show any information regarding console functions, things you could do inside finishUsing function or anything related to teams.

Current code looks as following

StartupEvents.registry('item', event => {
    event.create('orb_of_altering_reality')
        .maxStackSize(1)
        .glow(true)
        .tooltip('$7The ability to swap teams lies within the orb')
        .tooltip('$7can you really betray your fellow comrades though?')
        .useAnimation('block')
        .useDuration(itemstack => 60)
        .use((level, player, hand) => true)
        .finishUsing((itemstack, level, entity) => {
            const effects = entity.potionEffects
            effects.add('minecraft:haste', 120 * 20)
            itemstack.shrink(1)
            return itemstack
        })
})
lethal berryBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

strong cargo
#

would anyone know?

tacit shard
#

well ok

#

i tried few things

#

the promblem is if there are no people in party, this party will be erased

#

also i cant force-remove party's owner via command

#

and there is no config for changing something

#

soo, i think u cant

#

@strong cargo

strong cargo
#

wdym by party?

#

teams can exist without anyone being in them

tacit shard
tacit shard
strong cargo
#

yeah?

tacit shard
#

how?

strong cargo
#

if u just do /team add (teamname), it create a team with nobody in it... then if u do /team join (team) (username/entities) the person/entity will be added to the team, if u did /team leave (username/entity) the person/entity will leave said team but the team wont be deleted/gone

tacit shard
#

OHH, there is /team command?!?

strong cargo
#

thats why i was wondering if theres a way to do maybe through console a possibility of if entity.team == "teamA", console.command /team join teamB entity but i lack the kubejs knowledge

tacit shard
#

i used /ftbteams

strong cargo
#

could you maybe check with vanilla teams if ur able to get something?

#

cus im currently stuck

tacit shard
#

i did it

#
StartupEvents.registry('item', event => {
    event.create('orb_of_altering_reality')
        .maxStackSize(1)
        .glow(true)
        .tooltip('$7The ability to swap teams lies within the orb')
        .tooltip('$7can you really betray your fellow comrades though?')
        .useAnimation('block')
        .useDuration(itemstack => 60)
        .use((level, player, hand) => true)
        .finishUsing((itemstack, level, entity) => {
            const effects = entity.potionEffects
            effects.add('minecraft:haste', 120 * 20)
            let teamA = "team_1"
            let teamB = "team_2"
            if (entity.team.name == teamA)
                level.runCommandSilent("team join " + teamB + " " + entity.getName().getString())
            else if (entity.team.name == teamB)
                level.runCommandSilent("team join " + teamA + " " + entity.getName().getString())

            itemstack.shrink(1)
            return itemstack
        })
})
#

just redefine teamA and teamB with your team name

#

@strong cargo

strong cargo
#

ah thanks, ill see if this would work

#

yup that worked, ty

main robinBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You should create a new post for unrelated issues.

strong cargo
#

actually it doesnt work 100% yet

tacit shard
#

?

strong cargo
#

i just tried it in a survival setting where i dont have op/access to the commands, resulting in this error

tacit shard
#

shit

#

try this

StartupEvents.registry('item', event => {
    event.create('orb_of_altering_reality')
        .maxStackSize(1)
        .glow(true)
        .tooltip('$7The ability to swap teams lies within the orb')
        .tooltip('$7can you really betray your fellow comrades though?')
        .useAnimation('block')
        .useDuration(itemstack => 60)
        .use((level, player, hand) => true)
        .finishUsing((itemstack, level, entity) => {
            const effects = entity.potionEffects
            effects.add('minecraft:haste', 120 * 20)
            let teamA = "team_1"
            let teamB = "team_2"
            if (entity.team.name == teamA)
                level.server.runCommandSilent("team join " + teamB + " " + entity.getName().getString())
            else if (entity.team.name == teamB)
                level.server.runCommandSilent("team join " + teamA + " " + entity.getName().getString())

            itemstack.shrink(1)
            return itemstack
        })
})
#

@strong cargo

strong cargo
#

crashed the singleplayer world, giving this error
dev.latvian.mods.rhino.EcmaError: TypeError: Cannot call method "runCommandSilent" of null (startup_scripts:main.js#20)

main robinBOT
#

Paste version of disconnect-2025-11-04_17.17.46-client.txt from @strong cargo

tacit shard
#

oh finally got it to working

#
StartupEvents.registry('item', event => {
    event.create('orb_of_altering_reality')
        .maxStackSize(1)
        .glow(true)
        .tooltip('$7The ability to swap teams lies within the orb')
        .tooltip('$7can you really betray your fellow comrades though?')
        .useAnimation('block')
        .useDuration(itemstack => 60)
        .use((level, player, hand) => true)
        .finishUsing((itemstack, level, entity) => {
            const effects = entity.potionEffects
            effects.add('minecraft:haste', 120 * 20)
            let teamA = "team_1"
            let teamB = "team_2"
            if (entity.player && entity.getServer())
                if (entity.team.name == teamA)
                    entity.getServer().runCommandSilent("team join " + teamB + " " + entity.getName().getString())
                else if (entity.team.name == teamB)
                    entity.getServer().runCommandSilent("team join " + teamA + " " + entity.getName().getString())

            itemstack.shrink(1)
            return itemstack
        })
})
#

@strong cargo

strong cargo
#

yes that seemed to work perfectly

#

ty