:eviltongue:
Hello emudevs.
This script reads the contents of the database into memory.
Randomly selected from 5 minutes to the player
Game player can answer in this period
SQL script
test
Input command ".dt" start the answer
I come from China, so there are some Chinese in the script.
Forgive me for this very poor English:RpS_sad:
Hello emudevs.
This script reads the contents of the database into memory.
Randomly selected from 5 minutes to the player
Game player can answer in this period
Code:
local dt = {}
dt.time = 5 --5 min
dt.data = {}
dt.option = {"a","b","c","d"}
dt.id = 0
function dt.load()
local q = WorldDBQuery("SELECT * FROM ayasecore_questionsystem")
if (q) then
repeat
local temp = {["qu"]=q:GetString(0),["xx"] = {q:GetString(1),q:GetString(2),q:GetString(3),q:GetString(4)},
["ok"]=q:GetString(5),["it"]=q:GetUInt32(6),["it_c"]=q:GetUInt32(7)}
table.insert(dt.data,temp)
until not q:NextRow()
end
end
function dt.re()
dt.id = math.random(1,#dt.data)
local d = dt.data[dt.id]
SendWorldMessage(string.format("|cffff0000[答题系统]|r%s\n [choice] |CFFFF0080a|r:|CFF00FFFF%s|r |CFFFF0080b|r:|CFF00FFFF%s|r |CFFFF0080c|r:|CFF00FFFF%s|r |CFFFF0080d|r:|CFF00FFFF%s|r\n|cFFF08000★★★下一轮答题将在|r|cffff0000(%s分钟)|r|cFFF08000后开始.请留意★★★|r",d.qu,d.xx[1],d.xx[2],d.xx[3],d.xx[4],dt.time))
end
function dt.comm(_,p,c)
if (c == "dt") then
if dt.id == 0 then
p:SendBroadcastMessage("本轮答题结束.下一轮请关注聊天窗口.再接再厉!")
else
dt.show(p)
end
return false
end
end
function dt.show(p)
local d = dt.data[dt.id]
p:GossipClearMenu()
p:GossipMenuAddItem(0,"本轮答题题目:\n"..d.qu.."",1,0)
for i= 1,4 do
p:GossipMenuAddItem(5,"选项\n|CFFFF0080["..dt.option[i].."]|r|cff0000ff"..d.xx[i].."|r",1,i)
end
p:GossipSendMenu(1,p,60001)
end
function dt.sele(_,p,_,_,i)
if (i == 0) then
return dt.show(p)
else
local d = dt.data[dt.id]
if d.ok == dt.option[i] then
SendWorldMessage(string.format("|cffff0000[答题]|r:|cffFFFFFF本轮题目正确答案为 |CFFFF0080%s|r |cffFFFFFF恭喜玩家|cffff0000[%s]|r|cffFFFFFF回答正确.奖励|r %s x |cffff0000%s|r |cffFFFFFF个|r",d.ok,p:GetName(),GetItemLink(d.it),d.it_c))
p:AddItem(d.it,d.it_c)
dt.id = 0
else
p:SendBroadcastMessage(string.format("你回答错误.扣除|r %s x |cffff0000%s|r 个|r\n|cff00cc00你失去了:|r%s|cff00cc00x|r|cff00cc00%s|r|cff00cc00。|r",GetItemLink(d.it),d.it_c,GetItemLink(d.it),d.it_c))
p:RemoveItem(d.it,d.it_c)
end
p:GossipComplete()
end
end
RegisterPlayerEvent(42,dt.comm)
CreateLuaEvent(dt.re,dt.time*60*1000,0)
RegisterPlayerGossipEvent(60001,2,dt.sele)
dt.load()
SQL script
Code:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for ayasecore_questionsystem
-- ----------------------------
DROP TABLE IF EXISTS `ayasecore_questionsystem`;
CREATE TABLE `ayasecore_questionsystem` (
`text` char(255) DEFAULT NULL,
`a` char(255) DEFAULT NULL,
`b` char(255) DEFAULT NULL,
`c` char(255) DEFAULT NULL,
`d` char(255) DEFAULT NULL,
`ok` char(2) DEFAULT NULL,
`rewardId` int(11) DEFAULT '0',
`rewardCount` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
test
Code:
INSERT INTO `ayasecore_questionsystem` (`text`, `a`, `b`, `c`, `d`, `ok`, `rewardId`, `rewardCount`) VALUES ('test question', 'aaa', 'bbbb', 'cccccc', 'dddddd', 'a', '49426', '2')
Input command ".dt" start the answer
I come from China, so there are some Chinese in the script.
Forgive me for this very poor English:RpS_sad:
Last edited: