--2048小游戏
--作者韩永旗
--bug,建议
--核心运算,来自负负
--待完善
--UI2048,UI主页
local ui={"7104543079461138338","7104543079461138338_",}
--p={{p,name,iconid,maxnum,maxscore,nowscore},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
--上下左右,重开,关闭,
--界面1-16,最大数,当前分数,最高分数,
--排行榜,关闭,排行榜 1-7.1
local id={2,3,4,5,7,6,175,174,}
--[[ "2*n+8,2*n+9",42,43,45,47,
51,
"6*n+47",
95,96,97,98,99,
]]local p0=42
--音效
local mid={10948,10946,10949,10947,10379}
local num={}
local lbrt={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
13,9,5,1,14,10,6,2,15,11,7,3,16,12,8,4,4,
3,2,1,8,7,6,5,12,11,10,9,16,15,14,13,1,5,
9,13,2,6,10,14,3,7,11,15,4,8,12,16,}
local P={}
local P0={}
local list=0
local maxnum=0
local maxscore=0
local ret={}
--[[
local P2048={1000,247312290,331488399,1562836700}
local P={[1000]={{"迷你队长",1000,"role_4",10,10000,6666},{10,9,8,7,6,5,4,3,2,1,0,0,0,0,0,0}},
[331488399]={{"XD迷你村长",331488399,"skin_79",11,35864,35864},{11,10,8,6,5,6,7,5,3,5,4,2,1,2,3,1}},
[247312290]={{"韩永旗",247312290,"role_1",10,18678,18678},{2,3,1,2,2,4,3,1,5,7,6,4,8,10,9,7}},
[1562836700]={{"无敌的小雯",1562836700,"role_2",9,9152,9152},{2,3,1,2,2,4,3,1,5,7,6,4,8,8,9,7}},
}
]]
--原件颜色 原件位置,x,y,大小
local A={ {"0xFFEFD7",40,10,120,2},
{"0xFFE57F",40,10,120,4},
{"0xFFFF00",40,10,120,8},
{"0xFF6E40",20,20,100,16},
{"0xF57F17",20,20,100,32},
{"0xFF1744",20,20,100,64},
{"0xD500F9",10,25,80,128},
{"0x3D5AFE",10,25,80,256},
{"0x00E5FF",10,25,80,512},
{"0x76FF03",10,35,60,1024},
{"0xE77B17",10,35,60,2048},
{"0xE040FB",10,35,60,4096},
{"0xF50057",10,35,60,8192},
{"0x64DD17",10,45,45,16384},
{"0xF57F17",10,45,45,32768},
{"0x3D5AFE",10,45,45,65536},
}
--当前方向、是否正在进行、是否结束
local drct,ising,isend,has=0,0,0,0
local i,j,k=0,0,0
local score=0
--表格数据转字符串
local function setad(p) local t="" for k,v in ipairs(P[p]) do for k0,v0 in ipairs(v) do t=t..v0.." " end end return t end--上传玩家数据
local function setstr(p)
local v2=p
local actionattr=4--变量类型:数值
local msg="字符串"--变量名
local val=setad(p)--要设置的值
local v1=class.TriggerVarLibVar2.new(110850001).Data
VarLib2:setPlayerVarByName(v2,actionattr,msg,val)
Trigger.CloudSever:setDataListAnyValue(v1, v2, val)
end-- 字符串转表格数值
local function strad1(str) for j=1,#str do if string.sub(str,j,j) ==" " then if tonumber(string.sub(str,1,j-1))~=nil then return tonumber(string.sub(str,1,j-1)),string.sub(str,j+1,#str) else return string.sub(str,1,j-1),string.sub(str,j+1,#str) end end end end
local function strad2(p,v0)
local A0&#61;{{},{}} for i&#61;0,25 do if i<6 then if #v0>0 then A0[1][#A0[1]&#43;1],v0&#61;strad1(v0) end else if #v0>0 then A0[2][#A0[2]&#43;1],v0&#61;strad1(v0) end end end
P[p]&#61;A0
end
--获取玩家数据
local callback &#61; function (ret,k,v) if ret &#61;&#61; true then strad2(k,v) else end end
local function getstr(p) local v1&#61;class.TriggerVarLibVar2.new(110850001).Data local v2&#61;p local ret &#61; CloudSever:getDataListByKey(v1,v2,callback) if ret &#61;&#61; ErrorCode.OK then else end end--获取指定分数的值
local function CloudSevergetv(score)
local callbackscore &#61; function (ret,k,v,ix)
if ret &#61;&#61; true then
print(&#39;返回数据成功 键&#61; &#39;..k..&#39; 值&#61;&#39;..v)
else
print(&#39;返回数据失败&#39;)
end
end
local v1&#61;class.TriggerVarLibVar2.new(110840001).Data
local v2&#61;score
local ret &#61; CloudSever:getDataListByKey(v1,v2,callbackscore) --获取key1的分数
if ret &#61;&#61; ErrorCode.OK then
print(&#39;请求排行榜数据成功&#39;)
else
print("请求排行榜数据失败")
end
end
--获取指定排名的值
local callbackgetix &#61; function (ret,k,v,ix)
if ret &#61;&#61; true then
print(&#39;返回数据成功 键&#61; &#39;..k..&#39; 值&#61;&#39;..v..&#39; 排名&#61;&#39;..ix )
getstr(k)
P0[k]&#61;{P[k][1][3],P[k][1][2],P[k][1][1],P[k][1][4],P[k][1][5],P[k][1][6],ix}
else
print(&#39;返回数据失败&#39;)
end
end
local function CloudSevergetix(k0)
local v1&#61;class.TriggerVarLibVar2.new(110840001).Data
local v2&#61;k0
local ret &#61; CloudSever:getOrderDataIndexValue(v1,v2,callbackgetix) -- 请求第1名的数据
if ret &#61;&#61; ErrorCode.OK then
print(&#39;请求排行榜数据成功&#39;)
else
print("请求排行榜数据失败")
end
end
--获取指定玩家的值
local function CloudSevergetk(p)
local callbackk &#61; function (ret,k,v,ix) -- 返回结果不一定有排名
if ret &#61;&#61; true then
if ix then
print(&#39;返回数据成功 键&#61; &#39;..k..&#39; 值&#61;&#39;..v..&#39; 排名&#61;&#39;..ix )
else
print(&#39;返回数据成功 键&#61; &#39;..k..&#39; 值&#61;&#39;..v)
end
else
print(&#39;返回数据失败&#39;)
end
end
local v1&#61;class.TriggerVarLibVar2.new(110840001).Data
local v2&#61;p
local ret &#61; CloudSever:getOrderDataByKey(v1,v2,callbackk)
if ret &#61;&#61; ErrorCode.OK then
print(&#39;请求排行榜数据成功&#39;)
else
print("请求排行榜数据失败")
end
end
--获取 所有玩家数据
local function getallstr(p)
local v1&#61;class.TriggerVarLibVar2.new(110840001).Data
local ret,values &#61; CloudSever:getlistCache(v1)
if ret &#61;&#61; ErrorCode.OK then
print(&#39;获取数据成功&#39;)
local P0&#61;{}
for k0&#61;#values,1 do
CloudSevergetix(k0)
end
else
print(&#39;获取数据失败&#39;)
end
end--设置玩家最高记录数值
if maxscore setstr(p)
local function maxscorenum(p)
local v2&#61;p
local actionattr&#61;3--变量类型&#xff1a;数值
local msg&#61;"数值"--变量名
local val&#61;P[p][1][5]--要设置的值
--设置私有数值“数值01”的值为50
local v1&#61;class.TriggerVarLibVar2.new(110840001).Data
local v2&#61;p
VarLib2:setPlayerVarByName(v2,actionattr,msg,val)
Trigger.CloudSever:setDataListAnyValue(v1, v2, val)
end
--界面
local function add0(p,i)
if num[i]&#61;&#61;0 then
Trigger.UI:hideElement(p, ui[1],ui[2]..(2*i&#43;8))
else
Trigger.UI:showElement(p, ui[1],ui[2]..(2*i&#43;8))
Trigger.UI:setColor(p, ui[1],ui[2]..(2*i&#43;8),A[num[i]][1])
Trigger.UI:setText(p, ui[1],ui[2]..(2*i&#43;9),A[num[i]][5])
Trigger.UI:setPosition(p, ui[1],ui[2]..(2*i&#43;9),A[num[i]][2],A[num[i]][3])
Trigger.UI:setFontSize(p, ui[1],ui[2]..(2*i&#43;9),A[num[i]][4])
end
end
--当前分数
local function add1(p)
local maxnum&#61;nil
for k,v in ipairs(num) do
if maxnum&#61;&#61;nil then maxnum&#61;v
elseif maxnumend
end
local maxscore&#61;score
if maxnum
Trigger.UI:setColor(p, ui[1],ui[2]..42,A[maxnum][1])
Trigger.UI:setText(p, ui[1],ui[2]..43,A[maxnum][5])
Trigger.UI:setPosition(p, ui[1],ui[2]..43,A[maxnum][2],A[maxnum][3])
Trigger.UI:setFontSize(p, ui[1],ui[2]..43,A[maxnum][4])
Trigger.UI:setText(p, ui[1],ui[2]..45,maxscore)
Trigger.UI:setText(p, ui[1],ui[2]..47,P[p][1][5])
end
--排行榜
local function add2(p)
getallstr(p)
print("排行榜")
Trigger.UI:showElement(p, ui[1],ui[2]..51)
if #P0&#61;&#61;0 then getallstr(p) end
print("排行榜")
table.sort(P0 ,function(a, b) if a[4] > b[4] then return a[4] > b[4] elseif a[4] &#61;&#61; b[4] then return a[5]>b[5] end end)
print("P0排名")
print(P0)for i,v in ipairs(P0) do
if i<&#61;10 then
if i>#P0 then Trigger.UI:hideElement(p, ui[1],ui[2]..(10*i&#43;p0))
else
Trigger.UI:showElement(p, ui[1],ui[2]..(10*i&#43;p0))
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;1),i)
Trigger.UI:setTexture(p, ui[1],ui[2]..(10*i&#43;p0&#43;2), P0[i][1])
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;3),P0[i][2])
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;4),P0[i][3])
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;5),A[P0[i][4]][5])
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;6),P0[i][5])
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;7),P0[i][6])
Trigger.UI:setText(p, ui[1],ui[2]..(10*i&#43;p0&#43;8),P0[i][7])
end
end
if v[3]&#61;&#61;p then
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;1),i)
Trigger.UI:setTexture(p, ui[1],ui[2]..(10*11&#43;p0&#43;2), v[1])
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;3),v[2])
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;4),v[3])
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;5),A[v[4]][5])
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;6),v[5])
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;7),v[6])
Trigger.UI:setText(p, ui[1],ui[2]..(10*11&#43;p0&#43;8),v[7])
end
end
endlocal function Check(p)
for i&#61;1,16 do
if num[i]&#61;&#61;11 then
isend&#61;99999
end
end
if isend&#61;&#61;99999 then Game:msgBox("恭喜&#xff01;2048&#xff01;") has&#61;2
Player:playMusic(p,mid[5],100,1,false)
Chat:sendSystemMsg("恭喜&#xff01;玩家"..P[p][1][2].."2048&#xff01;")
end
end
--刷新
local function Re(p)
for i&#61;1,16 do
add0(p,i)
end
setstr(p)
if has&#61;&#61;1 then
Check(p)
end
end
--随机生成1个2/4
local function Add(p)
math.randomseed(os.time())
local z&#61;0
for i&#61;1,16 do
if num[i]&#61;&#61;0 then
z&#61;z&#43;1
end
end
if z>0 then
local r&#61;math.random(1,z)
for j&#61;1,16 do
if num[j]&#61;&#61;0 then
r&#61;r-1
end
if r&#61;&#61;0 then
math.randomseed(os.time())
num[j]&#61;math.random(1,10)
if num[j]<3 then
num[j]&#61;2
score&#61;score&#43;4
else
num[j]&#61;1
score&#61;score&#43;2
end
r&#61;-1
end
end
end
Re(p)
end
--四个数字的合并
local function Fin(num1,num2,num3,num4)
local numr&#61;{0,0,0,0,}
local m&#61;1
if num1~&#61;0 then
numr[m]&#61;num1
m&#61;m&#43;1
elseif (num2~&#61;0)or(num3~&#61;0)or(num4~&#61;0) then
isend&#61;1
end
if num2~&#61;0 then
numr[m]&#61;num2
m&#61;m&#43;1
elseif (num3~&#61;0)or(num4~&#61;0) then
isend&#61;1
end
if num3~&#61;0 then
numr[m]&#61;num3
m&#61;m&#43;1
elseif (num4~&#61;0) then
isend&#61;1
end
if num4~&#61;0 then
numr[m]&#61;num4
m&#61;m&#43;1
end
if (numr[1]&#61;&#61;numr[2])and(numr[1]~&#61;0)and(numr[1]~&#61;11) then
numr[1]&#61;numr[1]&#43;1
score&#61;score&#43;math.pow(2,numr[1])
isend&#61;1
if (numr[3]&#61;&#61;numr[4])and(numr[3]~&#61;0)and(numr[3]~&#61;11) then
numr[2]&#61;numr[3]&#43;1
score&#61;score&#43;math.pow(2,numr[2])
isend&#61;1
numr[3]&#61;0
numr[4]&#61;0
return numr
else
numr[2]&#61;numr[3]
numr[3]&#61;numr[4]
numr[4]&#61;0
return numr
end
elseif (numr[2]&#61;&#61;numr[3])and(numr[2]~&#61;0)and(numr[2]~&#61;11) then
numr[2]&#61;numr[2]&#43;1
score&#61;score&#43;math.pow(2,numr[2])
isend&#61;1
numr[3]&#61;numr[4]
numr[4]&#61;0
return numr
elseif (numr[3]&#61;&#61;numr[4])and(numr[3]~&#61;0)and(numr[3]~&#61;11) then
numr[3]&#61;numr[3]&#43;1
score&#61;score&#43;math.pow(2,numr[3])
isend&#61;1
numr[4]&#61;0
return numr
else
return numr
end
end
--滑动
local function Move(p,drct)
isend&#61;0
score&#61;P[p][1][6]
if has&#61;&#61;0 then
isend&#61;1
has&#61;1
end
for i&#61;1,4 do
local wn&#61;(drct-1)*16&#43;i*4
local nw&#61;Fin(num[lbrt[wn-3]],num[lbrt[wn-2]],num[lbrt[wn-1]],num[lbrt[wn]])
for j&#61;1,4 do
num[lbrt[wn&#43;j-4]]&#61;nw[j]
end
end
if isend&#61;&#61;0 then
Player:playMusic(p,mid[3],100,1,false)
else Player:playMusic(p,mid[2],100,1,false) Add(p)
end
P[p][1][6]&#61;score add1(p)
end
--初始化
local function setnum(p) P[p][1][6],P[p][2]&#61;0,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
num,score&#61;P[p][2],P[p][1][6] Add(p) P[p][1][6]&#61;score add1(p)
endlocal function cunid(p)
local vartype&#61;7--变量组类型&#xff0c;3是数值
local libname&#61;"玩家组"--组名
local value&#61;p--值
local playerid&#61;0--私有变量组所属玩家id&#xff0c;0代表全局变量组
--添加value到vartype类型的变量组的最后一位
Valuegroup:insertInGroupByName(vartype, libname, value, playerid)
endlocal function funcevent(event)
local p,uid,uiid&#61;event.eventobjid,event.CustomUI,event.btnelenemt
if uid&#61;&#61;ui[1] then num&#61;P[p][2]
if uiid&#61;&#61;ui[2]..2 then Move(p,4)
elseif uiid&#61;&#61;ui[2]..3 then Move(p,2)
elseif uiid&#61;&#61;ui[2]..4 then Move(p,1)
elseif uiid&#61;&#61;ui[2]..5 then Move(p,3)
elseif uiid&#61;&#61;ui[2]..7 then Player:playMusic(p,mid[1],100,1,false) Chat:sendSystemMsg("2048已重新开始",p) setnum(p)
elseif uiid&#61;&#61;ui[2]..6 then Trigger.UI:hideElement(p, ui[1],ui[2]..1) Trigger.UI:showElement(p, ui[1],ui[2]..179)
elseif uiid&#61;&#61;ui[2]..174 then Trigger.UI:hideElement(p, ui[1],ui[2]..51)
elseif uiid&#61;&#61;ui[2]..175 then add2(p)
elseif uiid&#61;&#61;ui[2]..179 then Trigger.UI:hideElement(p, ui[1],ui[2]..179) Trigger.UI:showElement(p, ui[1],ui[2]..1)
end
end
end
--点击按钮
ScriptSupportEvent:registerEvent([&#61;[UI.Button.Click]&#61;],funcevent)
local function EnterGame(param)
local p&#61;param.eventobjid
local result,name&#61;Player:getNickname(p)
local result,iconid &#61; Customui:getRoleIcon(p)
--[[
local objid&#61;p
local actionattr&#61;4--变量类型&#xff1a;数值
local msg&#61;"字符串"--变量名
local result,value &#61; VarLib2:getPlayerVarByName(objid,actionattr,msg)
local v1&#61;class.TriggerVarLibVar2.new(110850001).Data
local v2&#61;p
local v3&#61;value
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)
]]
local v1 &#61; class.TriggerVarLibVar2.new(110850001).Data
local v2 &#61; p
local v3 &#61; class.TriggerVarLibVar2.new(210100001, v2).PrivateData
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)
threadpool:wait(2)
if v3&#61;&#61;nil or #v3<50 then
Player:notifyGameInfo2Self(p,"欢迎玩家"..name.."来到2048游戏房间")
P[p]&#61;{{p,name,iconid,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
setstr(p)
else
Player:notifyGameInfo2Self(p,"欢迎玩家"..name.."再次来到2048游戏房间")
local v1&#61;class.TriggerVarLibVar2.new(110850001).Data
local v2&#61;p
local v3&#61;class.TriggerVarLibVar2.new(210100001, v2).PrivateData
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)
end
cunid(p)
maxscorenum(p)
P[p][1][3]&#61;iconid
threadpool:wait(2)
Player:openUIView(p,ui[1])
Trigger.UI:hideElement(p, ui[1],ui[2]..179)
num,score&#61;P[p][2],P[p][1][6]
for i&#61;1,16 do add0(p,i)end add1(p) add2(p)
end
--玩家进入游戏
ScriptSupportEvent:registerEvent_NoError([&#61;[Game.AnyPlayer.EnterGame]&#61;], EnterGame)local function LeaveGame(param)
local p&#61;param.eventobjid
setstr(p)
maxscorenum(p)
end
--玩家离开游戏
ScriptSupportEvent:registerEvent_NoError([&#61;[Game.AnyPlayer.LeaveGame]&#61;], LeaveGame)
--[[
class.TriggerVarLibVar2.new(210100001, CurEventParam.TriggerByPlayer).PrivateData &#61; v2
local v1 &#61; class.TriggerVarLibVar2.new(110850001).Data
local v2 &#61; p
local v3 &#61; class.TriggerVarLibVar2.new(210100001, p).PrivateData
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)local v1 &#61; class.TriggerVarLibVar2.new(110840001).Data
local v2 &#61; p
local v3 &#61; class.TriggerVarLibVar2.new(210050001, p).PrivateData
Trigger.CloudSever:setDataListValue(v1, v2, v3)
class.TriggerVarLibVar2.new(210050001, CurEventParam.TriggerByPlayer).PrivateData &#61; v2
class.TriggerVarLibVar2.new(210050001, CurEventParam.TriggerByPlayer).PrivateData &#61; v2local actionattr&#61;3--变量类型&#xff1a;数值
local msg&#61;"数值01"--变量名
local val&#61;50--要设置的值
VarLib2:setGlobalVarByName(actionattr,msg,val)
function clickblock(event)
local actionattr&#61;3--变量类型&#xff1a;数值
local msg&#61;"数值01"--变量名
local result,value &#61; VarLib2:getGlobalVarByName(actionattr,msg)
--在聊天框显示数值
Chat:sendSystemMsg("数值“数值01”的值为"..value)
local objid&#61;event.eventobjid--点击方块的玩家迷你号&#xff08;私有变量所属对象&#xff09;local objid&#61;event.eventobjid
local actionattr&#61;3--变量类型&#xff1a;数值
local msg&#61;"字符串01"--变量名
local val&#61;50--要设置的值
VarLib2:setPlayerVarByName(objid,actionattr,msg,val)
local objid&#61;event.eventobjid--点击方块的玩家迷你号&#xff08;私有变量所属对象&#xff09;local objid&#61;p
local actionattr&#61;3--变量类型&#xff1a;数值
local msg&#61;"字符串01"--变量名
local result,value &#61; VarLib2:getPlayerVarByName(objid,actionattr,msg)
local objid&#61;247312290
local actionattr&#61;7--变量类型&#xff1a;数值
local msg&#61;"玩家组01"--变量名
local val&#61;p--要设置的值
VarLib2:setPlayerVarByName(objid,actionattr,msg,val)(
local objid&#61;247312290
local actionattr&#61;7--变量类型&#xff1a;数值
local msg&#61;"玩家组01"--变量名
local result,value &#61; VarLib2:getPlayerVarByName(objid,actionattr,msg)
local objid&#61;p
local actionattr&#61;4--变量类型&#xff1a;数值
local msg&#61;"字符串"--变量名
local result,value &#61; VarLib2:getPlayerVarByName(objid,actionattr,msg)
print("get",value)
strad2(p,value)
print(P)
local vartype&#61;3--变量组类型&#xff0c;3是数值
local libname&#61;"数值"--组名
local sortType&#61;1--排序方式&#xff1a;0升序 1降序
local playerid&#61;0--私有变量组所属玩家id&#xff0c;0代表全局变量组
--对组中的值排序
Valuegroup:sortGroupByName(vartype, libname, sortType, playerid)
local vartype&#61;3--要获取的变量组类型&#xff0c;3是数值
local libname&#61;"数值"--要获取的组名
local playerid&#61;0--私有变量组所属玩家id&#xff0c;0代表全局变量组
--获取类型为vartype的变量组中所有变量的值
local result,ret&#61;Valuegroup:getAllGroupItem(vartype, libname, playerid)
print(ret)--在日志输出
local vartype&#61;3--变量组类型&#xff0c;3是数值
local libname&#61;"数值"--组名
local value&#61;10--值
local playerid&#61;0--私有变量组所属玩家id&#xff0c;0代表全局变量组
--删除类型为vartype的变量组中值为value的值&#xff0c;删除后值为nil
Valuegroup:removeValueByName(vartype, libname, value, playerid)
local vartype&#61;3--变量组类型&#xff0c;3是数值
local libname&#61;"数值"--组名
local value&#61;10--值
local playerid&#61;0--私有变量组所属玩家id&#xff0c;0代表全局变量组
--添加value到vartype类型的变量组的最后一位
Valuegroup:insertInGroupByName(vartype, libname, value, playerid)
]]
--[[
数值 用法描述
POSITION 1 位置
AREAINS 2 区域
NUMBER 3 数值
STRING 4 字符串
BOOLEAN 5 布尔值
PLAYER 6 玩家
PLAYERGROUT 7 玩家组
BLOCKTYPE 8 方块类型
ITEMTYPE 9 道具类型
CREATURE 10 生物
ACTORID 11 actor类型
CREATUREGROUP 12 生物组
TIMER 13 计时器
EFFECTTYPE 14 特效类型
SITEGROUP 15 位置组
AREAGROUP 16 区域组
NUMBERGROUP 17 数值组
STRINGGROUP 18 字符串组
BOOLEANGROUP 19 布尔值组
BLOCKTYPEGROUP 20 方块类型组
ITEMTYPEGROUP 21 道具类型组
CREATURETYPEGROUP 22 生物类型组
TIMERGROUP 23 计时器组
EFFECTTYPEGROUP 24 特效类型组
--获取排行榜名次
local v1 &#61; class.TriggerVarLibVar2.new(110850001).Data
local v2 &#61; p
local v3 &#61; class.TriggerVarLibVar2.new(210100001, v2).PrivateData
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)
-- 云服务器
local CS2048&#61;{class.TriggerVarLibVar2.new(110840001).Data,
class.TriggerVarLibVar2.new(110850001).Data,
}
--表格数据转字符串
local function setad(p) local t&#61;"" for k,v in ipairs(P[p]) do for k0,v0 in ipairs(v) do t&#61;t..v0.." " end end return t end--上传玩家数据
local function setstr(p)
local v1&#61;CS2048[2]
local v2&#61;p
local v3&#61;setad(p)
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)
end-- 字符串转表格数值
local function strad1(str) for j&#61;1,#str do if string.sub(str,j,j) &#61;&#61;" " then if tonumber(string.sub(str,1,j-1))~&#61;nil then return tonumber(string.sub(str,1,j-1)),string.sub(str,j&#43;1,#str) else return string.sub(str,1,j-1),string.sub(str,j&#43;1,#str) end end end end
local function strad2(k,v)
local A0&#61;{{},{}} local v0&#61;v for i&#61;0,25 do if i<6 then if #v0>0 then A0[1][#A0[1]&#43;1],v0&#61;strad1(v0) end else if #v0>0 then A0[2][#A0[2]&#43;1],v0&#61;strad1(v0) end end end
for i&#61;4,6 do if P[k][1][i]end --获取玩家数据
local callback &#61; function (ret,k,v) if ret &#61;&#61; true then strad2(k,v) else end end
local function getstr(p) local v1&#61;CS2048[2] local v2&#61;p local ret &#61; CloudSever:getDataListByKey(v1,v2,callback) if ret &#61;&#61; ErrorCode.OK then else end end--获取所有数据110850001或排行榜110840001数据
local v1 &#61; class.TriggerVarLibVar2.new(110850002).Data
local ret,values &#61; CloudSever:getlistCache(v1)
if ret &#61;&#61; ErrorCode.OK then
print(&#39;获取数据成功&#39;)
print(values)
else
print(&#39;获取数据失败&#39;)
end
--删除排行榜的值
local function add19(p,maxnum)
local v1&#61;CS2048[1][maxnum-1]
local v2&#61;p
local ret &#61; CloudSever:removeOrderDataByKey(v1,v2)
if ret &#61;&#61; ErrorCode.OK then
print(&#39;删除排行榜数据成功&#39;)
else
print("删除排行榜数据失败")
end
end
--获取所有数据110850001或排行榜110840001数据
local function getlist(p)
local v1&#61;CS2048[1][1]
local ret,values &#61; CloudSever:getlistCache(v1)
if ret &#61;&#61; ErrorCode.OK then
-- print(values)
local list&#61;0
for k,v in ipairs(values) do
list&#61;list&#43;1
if v[k]&#61;&#61;p then
local v3&#61;#values-list&#43;1
local v2&#61;p
-- print(v3)
class.TriggerVarLibVar2.new(210050002, v2).PrivateData&#61;v3
return v3
end
end
else
end
end
local callback3 &#61; function (ret,k,v,ix) -- 返回结果不一定有排名
if ret &#61;&#61; true then
if ix then
print(&#39;返回数据成功 键&#61; &#39;..k..&#39; 值&#61;&#39;..v..&#39; 排名&#61;&#39;..ix )
print(list)
else
print(&#39;返回数据成功 键&#61; &#39;..k..&#39; 值&#61;&#39;..v)
end
else
print(&#39;返回数据失败&#39;)
end
end
local function getlistcs(p)
local list&#61;getlist()
local v1&#61;CS2048[1]
local v2&#61;p
local ret &#61; CloudSever:getOrderDataByKey(v1,v2,callback3)
if ret &#61;&#61; ErrorCode.OK then
print(&#39;请求排行榜数据成功&#39;)
else
print("请求排行榜数据失败")
end
-- print("排行")
-- print(list)
end--删除排行榜的值
local function removecs(p)
local v1&#61;CS2048[1]
local v2&#61;p
local ret &#61; CloudSever:removeOrderDataByKey(v1,v2)
if ret &#61;&#61; ErrorCode.OK then
else
end
end
--设定排行榜分数值
local function setcs(p)
local v1&#61;class.TriggerVarLibVar2.new(110840001).Data
local v2&#61;p
local v3&#61;P[p][1][5]
Trigger.CloudSever:setDataListAnyValue(v1, v2, v3)-- class.TriggerVarLibVar2.new(210050001, v2).PrivateData&#61;v3
if ret &#61;&#61; ErrorCode.OK then
getlistcs(p)
else
end
end
]]