用户:
DebugDynamo查看:1 回复:5 评论:1 创建时间:2022-02-10T10:38:08
本次更新修复了同名队伍的存在
以及加上了队伍人数上限的设置
代码:
var team = []
var teampl = 4 //队伍人数上限(可自行调整)
function textdialog(entity, title, content) {
entity.guaji = 0
entity.player.dialog({
type: Box3DialogType.TEXT,
title: title,
content: content,
})
}
function selectdialog(entity, title, content, options) {
entity.guaji = 0
const result = entity.player.dialog({
type: Box3DialogType.SELECT,
title: title,
content: content,
options: options
})
return result
}
function inputdialog(entity, title, content) {
entity.guaji = 0
const result = entity.player.dialog({
type: Box3DialogType.INPUT,
title: title,
content: content,
confirmText: '确定',
placeholder: '请填写回答',
})
return result
}
function find(name) {
a = world.querySelectorAll('player');
for (let i in a) {
if (a[i].player.name == name) return a[i];
}
}
world.onPlayerJoin(({entity})=>{
entity.team = ''
entity.man = ''
})
world.onPlayerLeave(({ entity }) => {
if (entity.man == '队长') {
world.say(`${entity.player.name}解散了${entity.team}队伍`)
world.querySelectorAll('player').forEach((e) => {
if (e.team == entity.team) {
e.man = ''
e.team = ''
}
})
}
})
world.onPress(async ({ entity, button }) => {
if (button == Box3ButtonType.ACTION1) {
const sel = await selectdialog(entity, `控制面板`, `请选择你要操作的按键:`, ['队伍'])
if (sel) {
if (sel.value == '队伍') {
const awa = await selectdialog(entity, `队伍`, `请选择操作`, ['组建队伍', '加入队伍', '管理队伍'])
if (!awa || awa == null) return
if (awa.index == 0) {
if (entity.team !== '') {
entity.player.directMessage('你已有队伍')
return
}
const temename = await inputdialog(entity, `队伍`, `请输入你要创建的队伍名称:`)
if (!temename || temename == null || teamname == '') return
if(team.includes(temename)){textdialog(entity,'提示','此队伍已存在');return}
team.push(temename)
entity.team = temename
entity.man = '队长'
world.say(`${entity.player.name}创建了一个名为${temename}的队伍!`)
}
if (awa.index == 1) {
if (entity.team !== '') {
entity.player.directMessage('你已有队伍')
return
}
var teamname = []
world.querySelectorAll('player').forEach((e) => {
if (e.man == '队长') {
teamname.push(e.team)
}
})
const eawa = await selectdialog(entity, `队伍`, `点击你要加入的队伍`, teamname)
if (!eawa || eawa == null || eawa.value == '') return
var temennnnnn = ''
var temanman = []
world.querySelectorAll('player').forEach((e) => {
if (e.team == eawa.value) {
if (e.man == '队员') {
temanman.push(e.player.name)
}
if (e.man == '队长') {
temennnnnn = e.player.name
}
}
})
const awawawawa = await selectdialog(entity, `队伍`, `
队伍名:${eawa.value}
队长:${temennnnnn}
队员列表:${temanman}
`, ['加入这支队伍'])
if (!awawawawa || awawawawa == null) return
if(temanman.length >= (teampl - 1)){entity.player.directMessage('此队伍人数已达上限');return}
if (find(temennnnnn).destroyed) { entity.player.directMessage('队长已离开地图'); return }
entity.player.directMessage('请等待队长审核!')
const shenhe = await selectdialog(find(temennnnnn), `队伍`, `${entity.player.name}想要加入你的队伍`, ['同意', '拒绝'])
if (!shenhe || shenhe == null) { entity.player.directMessage('你的要求被拒绝了!'); return }
if (entity.destroyed) { entity.player.directMessage('此人已离开地图'); return }
if (shenhe.index == 0) {
world.say(`${entity.player.name}加入了由${temennnnnn}组建的${eawa.value}小队`)
entity.team = eawa.value
entity.man = '队员'
} else {
entity.player.directMessage('你的要求被拒绝了!')
}
} if (awa.index == 2) {
if (entity.team == '') {
entity.player.directMessage('你还没有队伍')
return
}
var o1 = []
if (entity.man == '队长') {
o1 = ['解散队伍', '踢出队员']
}
if (entity.man == '队员') {
o1 = ['退出队伍']
}
var temennnnnn = ''
var temanman = []
var teamname = []
var myteam = entity.team
world.querySelectorAll('player').forEach((e) => {
if (e.team == myteam) {
if (e.man == '队员') {
temanman.push(e.player.name)
}
if (e.man == '队长') {
temennnnnn = e.player.name
}
}
})
const awa1 = await selectdialog(entity, '队伍', `
队伍名:${entity.team}
队长:${temennnnnn}
队员列表:${temanman}
`, o1)
if (!awa1 || awa1 == null) return
if (awa1.value == '解散队伍') {
const diu = await selectdialog(entity, `队伍`, `确认要解散队伍吗`, ['确定', '算了'])
if (!diu || diu == null) return
if (diu.index == 0) {
world.say(`${entity.player.name}解散了${myteam}队伍`)
world.querySelectorAll('player').forEach((e) => {
if (e.team == myteam) {
e.man = ''
e.team = ''
}
})
}
}
if (awa1.value == '踢出队员') {
const duiyuan = await selectdialog(entity, `队伍`, `请选择你要踢出的队员`, temanman)
if (!duiyuan || duiyuan == null || duiyuan.value == '') return
const diu = await selectdialog(entity, `队伍`, `确认要把${duiyuan.value}踢出队伍吗`, ['确定', '算了'])
if (!diu || diu == null) return
if (diu.index == 0) {
world.say(`${entity.player.name}把${duiyuan.value}踢出了${entity.team}队伍`)
find(duiyuan.value).man = ''
find(duiyuan.value).team = ''
}
}
if (awa1.value == '退出队伍') {
const diu = await selectdialog(entity, `队伍`, `确认要退出队伍吗`, ['确定', '算了'])
if (!diu || diu == null) return
if (diu.index == 0) {
world.say(`${entity.player.name}退出了${entity.team}队伍`)
entity.man = ''
entity.team = ''
}
}
}
}
}
}
})