用户:
七叶寂照秘密主promax查看:0 回复:2 评论:0 创建时间:2024-07-26T21:26:23
var admin = ['zz0ggH3u/a4mw+TD']
const sql = storage.getDataStorage('euser0_1')
world.onPlayerJoin(async({entity})=>{
entity.coin=0
entity.exp = 0
entity.other=[]
entity.item=[]
var da = await getdata(entity)
entity.coin=da[0]
entity.exp = da[1]
entity.other=da[2]
entity.item=da[3]
})
world.onPlayerLeave(({entity})=>{
setdata(entity)
})
world.onChat(async ({ entity, message }) => {
if (entity.isPlayer) {
if (admin.includes(entity.player.userKey)) {
if (message[0] == "$") {
if (admin.includes(entity.player.userKey)) {
try {
var code = eval(message.slice(1));
world.say(`~>${code}`)
}
catch (e) {
world.say(e)
}
}
}}}})
async function getdata(entity){
var id = entity.player.userId
while(1){
try{
let data = await sql.get(id)
if(!(data && data.value)){
console.log('正在创建数据')
await sql.set(id,[entity.coin,entity.exp,entity.item,entity.other])
console.log('创建成功:'+JSON.stringify(data.value))
return data.value
}
else{
console.log('数据读取成功'+JSON.stringify(data.value))
return data.value
}
}
catch(e){
console.log(e)
}
}
}
async function setdata(entity){
var id = entity.player.userId
while(1){
try{
let data = await sql.get(id)
if(!(data && data.value)){
console.log('没有创建数据')
await sql.set(id,{'coin':entity.coin,'exp':entity.exp,'item':entity.item,'other':entity.other})
console.log('创建成功:'+JSON.stringify(data.value))
return
}else{
await sql.update(id,(preData) => { return {'coin':entity.coin,'exp':entity.exp,'item':entity.item,'other':entity.other} })
let newdata = await sql.get(id)
var n = newdata.value
console.log('更新成功:'+JSON.stringify(newdata.value))
return
}
}
catch(e){
console.log(e)
}
}
}
async function deldata(entity){//重要的事情说三遍:自己不要作喵!自己不要作喵!自己不要作喵!
var id = entity.player.userId
while(1){
try{
let data = await sql.get(id)
if(!(data && data.value)){
//console.log('没有创建数据')
//entity.player.kick()
return
}else{
await sql.remove(id)
//entity.player.kick()
return
}
}
catch(e){
console.log(e)
}
}
}
使用时更改列表项数,管喵Key即可