User Tag List

Results 1 to 3 of 3

Thread: [lua]Question System

  1. #1
    Enthusiast
    Join Date
    Dec 2013
    Location
    China
    Posts
    33
    XP
    2,410
    Level
    13
    Thanks
    18
    Thanked 18 Times in 5 Posts

    [lua]Question System


    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')
    QQ截图20151108031108.pngQQ截图20151108031121.pngQQ截图20151108031153.jpg

    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
    Last edited by Ayase; 11-07-2015 at 07:23 PM.
    Achievements:
    Member 1 year registered Level X

  2. The Following 4 Users Say Thank You to Ayase For This Useful Post:


  3. #2
    Retired Staff <span style='color: #FF4500'><span class='glow_000000'>Jafferwaffer</span></span>'s Avatar
    Join Date
    Nov 2013
    Location
    UK
    Posts
    224
    XP
    352,560
    Level
    120
    Thanks
    106
    Thanked 40 Times in 27 Posts
    Thanks for the release!
    Achievements:
    Member 1 year registered Shopper Level XL Level C
    Awards:
    Member of Staff Support LOL Pot Head

  4. #3
    Lurking Member
    Join Date
    Aug 2016
    Posts
    2
    XP
    6
    Level
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Very powerful, come on!@ayase

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •