Ir para conteúdo
Entre para seguir isso  
Black Gooden

Super Quiz System 1.0

Recommended Posts

Black Gooden    0
Black Gooden

 

Alterações

1.1 - Criada função GetQuizId para evitar tantas querys a base de dados.

 

Sistema:

Sistema de votações com a oportunidade de ter mais que 1 Opção personalizada.

 

talkactions.xml

   <talkaction words="/quiz" event="script" access="3" value="vote.lua" />
   <talkaction words="/quizinstall" event="script" access="3" value="vote.lua" />
   <talkaction words="!vote" event="script" value="vote.lua" />

vote.lua

---Script: 'Super Quiz System 1.1' By: Gooden
---Based: 'Advanced quiz system com logs!' By: Mock the bear 

--Informations
--/quiz - Start a Quiz - Example: /quiz How Old Are You?,<15,16-20,20-30,30-40,>40
   --This will create a Quiz with the Question: "How Old Are You?" and the Options:
       -- (A) <15
       -- ( 16-20
       -- (C) 20-30
       -- (D) 30-40
       -- (E) >40
--/quiz info - Check The Information of the current Quiz. Alert if no quiz Runing.
--/quiz restart - Restart the Quiz (Clean all the responses sent)
--/quiz close - Close the current Quiz.
--/quiz cancel - Delete the current Quiz
--/quiz commands - Show the commands that exists.
--/quizinstall - Install the Super Quiz System 1.0

local Quiz_Open=0
local Quiz_Finish=1
local Quiz_Cancel=2
local messageDelay = 60
dofile("config.lua")
function sendBroadcast(m)
   local ls = db.getResult("SELECT count(*) as count FROM Quiz where Status="..Quiz_Open..";")
   if ls:getDataInt("count") == 1 then --Verifica se existe Questionario a correr
       doBroadcastMessage(m)
       addEvent(sendBroadcast,messageDelay*1000,m)
   end
end

function GetQuizId()
   local ls = db.getResult("SELECT count(*) as count FROM Quiz where Status="..Quiz_Open..";")        
   if ls:getDataInt("count") == 1 then 
       local ls2 = db.getResult("SELECT id FROM Quiz where Status="..Quiz_Open..";")    
       return ls2:getDataInt("id")
   else
       return 0
   end
end

function onSay(cid, words, param, channel) 
   local ls = db.getResult("SELECT count(*) as count FROM information_schema.tables WHERE table_schema = '"..sqlDatabase.."' AND table_name = 'Quiz';")
   if ls:getDataInt("count") == 0 and words == '/quizinstall' and getPlayerGroupId(cid) >= 3 then
       --Instalação e criação das BD'S
       local QuizTable="CREATE TABLE Quiz (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Question VARCHAR(100),Status INT(1) NOT NULL DEFAULT 0,created TIMESTAMP DEFAULT NOW());"
       local OptionsTable="CREATE TABLE Quiz_options (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Quiz INT NOT NULL,letter Varchar(1),Opt varchar(255));"
       local ResponseTable="CREATE TABLE Quiz_response (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,account INT NOT NULL,Quiz INT NOT NULL,Opt INT NOT NULL);"
       db.executeQuery(QuizTable)
       db.executeQuery(OptionsTable)
       db.executeQuery(ResponseTable)
       doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 installed! Check the commands by typing /quiz commands')        
   else
       if ls:getDataInt("count") == 0 then
           if getPlayerGroupId(cid) >= 3 then
               doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 not installed! To install type /quizinstall')
           end
       else
           local OpenOne = GetQuizId()
           if words == '!vote' then
               if OpenOne ~= 0 then
                   local response=string.upper(string.sub(param, 1, 1))
                   local ls2 = db.getResult("SELECT count(*) as count FROM Quiz_options where quiz="..OpenOne.." and letter='"..response.."';")
                   if ls2:getDataInt("count") == 0 then
                       doPlayerSendTextMessage(cid,25,'Response to the Quiz not found!')                            
                   else
                       local ls3 = db.getResult("SELECT count(*) as count FROM Quiz_response where account="..getPlayerAccountId(cid).." and quiz="..OpenOne..";")
                       if ls3:getDataInt("count") == 0 then        
                           db.executeQuery("INSERT INTO `Quiz_response` (account,Quiz,Opt) VALUES ("..getPlayerAccountId(cid)..","..OpenOne..",(Select id from Quiz_options where quiz="..OpenOne.." and letter='"..response.."')); ")
                           doPlayerSendTextMessage(cid,25,"You have choosen the response "..response.."!!")        
                       else
                           doPlayerSendTextMessage(cid,25,'You already voted!')    
                       end
                   end
               else
                   doPlayerSendTextMessage(cid,25,'No Quiz running at the moment!')
               end
           elseif words == '/quizinstall' and getPlayerGroupId(cid) >= 3 then
                   doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 already installed! Check the commands by typing /quiz commands')                
           elseif words == '/quiz' and getPlayerGroupId(cid) >= 3 then
               if string.sub(param, 1,4) == 'info' and OpenOne ~= 0 then
                   if OpenOne ~= 0 then
                       local ls = db.getResult("SELECT * FROM Quiz where Status="..Quiz_Open..";")            
                       local Question = ls:getDataString("Question")
                       ls:free()

                       local text=Question
                       local db_result = db.getResult("select letter,quiz_options.opt as opt,(select count(*) from quiz_response where quiz_response.opt=quiz_options.id) as Total from quiz_options where quiz="..OpenOne.." order by Total desc;")
                       if (db_result:getID() ~= -1) then
                           repeat
                               text=text..'\n('..db_result:getDataString("letter")..') ' .. db_result:getDataString("opt") .. ' - '..db_result:getDataInt("Total")
                           until not db_result:next()
                       end
                       db_result:free()
                       doPlayerSendTextMessage(cid,25,text)
                   else
                       doPlayerSendTextMessage(cid,25,'No Quiz running!!')
                   end
               elseif string.sub(param, 1,7) == 'install' then    
                   doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 already installed! Check the commands by typing /quiz commands')
               elseif string.sub(param, 1,7) == 'restart' then
                   if OpenOne ~= 0 then
                       db.executeQuery("Delete from quiz_response where quiz="..OpenOne..";")
                       doPlayerSendTextMessage(cid,25,'Quiz Restarted!!')
                   else
                       doPlayerSendTextMessage(cid,25,'No Quiz running!!')
                   end
               elseif string.sub(param, 1,5) == 'close' then
                   if OpenOne ~= 0 then
                       local ls = db.getResult("SELECT * FROM Quiz where Status="..Quiz_Open..";")            
                       local Question = ls:getDataString("Question")
                       ls:free()

                       local text='Quiz Closed. \n\n ' .. Question
                       local db_result = db.getResult("select letter,quiz_options.opt as opt,(select count(*) from quiz_response where quiz_response.opt=quiz_options.id) as Total from quiz_options where quiz="..OpenOne.." order by Total desc;")
                       if (db_result:getID() ~= -1) then
                           repeat
                               text=text..'\n('..db_result:getDataString("letter")..') ' .. db_result:getDataString("opt") .. ' - '..db_result:getDataInt("Total")
                           until not db_result:next()
                       end
                       db_result:free()

                       db.executeQuery("Update Quiz set Status="..Quiz_Finish.." where status="..Quiz_Open..";")
                       doBroadcastMessage("Quiz Finished!")
                       doPlayerSendTextMessage(cid,25,text)
                   else
                       doPlayerSendTextMessage(cid,25,'No Quiz running!!')
                   end
               elseif string.sub(param, 1,6) == 'cancel' then
                   if OpenOne ~= 0 then
                       db.executeQuery("Delete from quiz_response where quiz="..OpenOne..";")
                       db.executeQuery("Delete from quiz where id="..OpenOne..";")
                       doPlayerSendTextMessage(cid,25,'Quiz Deleted!!')
                   else
                       doPlayerSendTextMessage(cid,25,'No Quiz running!!')
                   end
               elseif string.sub(param, 1,8) == 'commands' then
                   doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 Commands!\n/quiz - Start a Quiz - Example: /quiz How Old Are You?,<15,16-20,20-30,30-40,>40\n/quiz info - Check The Information of the current Quiz. Alert if no quiz Runing.\n/quiz restart - Restart the Quiz (Clean all the responses sent)\n/quiz close - Close the current Quiz.\n/quiz cancel - Delete the current Quiz\n/quiz commands - Show the commands that exists.\n/quizinstall - Install the Super Quiz System 1.0')
               else
                   if OpenOne ~= 0 then
                       doPlayerSendTextMessage(cid,25,'There is already a Quiz running!')    
                   else
                       local SP = param:split(",")
                       if #SP>1 then
                           local Question = SP[1]
                           db.executeQuery("INSERT INTO `Quiz` (Question,Status) VALUES ('"..Question.."',"..Quiz_Open..");")

                           OpenOne=GetQuizId()

                           local options = { }
                           local i=0
                           local text='Quiz: '..Question
                           for i = 2,#SP do
                               db.executeQuery("INSERT INTO `Quiz_options` (Quiz,letter,Opt) VALUES ("..OpenOne..",'"..string.char(63+i).."','"..string.trim(SP[i]).."'); ")
                               text=text..'\n('..string.char(63+i)..') - '..string.trim(SP[i])
                           end
                           doPlayerSendTextMessage(cid,25,'Quiz Created!!')            
                           sendBroadcast(text)
                       else
                           doPlayerSendTextMessage(cid,25,'Invalid parameters.')                    
                       end
                   end
               end
           end
       end
   end
   return true
end

function string:split(delimiter)
 local result = { }
 local from  = 1
 local delim_from, delim_to = string.find( self, delimiter, from  )
 while delim_from do
   table.insert( result, string.sub( self, from , delim_from-1 ) )
   from  = delim_to + 1
   delim_from, delim_to = string.find( self, delimiter, from  )
 end
 table.insert( result, string.sub( self, from  ) )
 return result
end

 

Agradecimentos ao Mock pela ideia :P

Editado por Black Ice

Compartilhar este post


Link para o post
Mock    32
Mock

Legal, fico melhor que o meu :P

So que vc posto na seção errada. to movendo.

Compartilhar este post


Link para o post
Rawenga    0
Rawenga

Aparece o nome de quem vota?

Compartilhar este post


Link para o post
Black Gooden    0
Black Gooden

Não aparece... mas fica resgistado... nao é dificil alterar para aparecer. :)

Compartilhar este post


Link para o post
eskerII    0
eskerII

tag da talkactions.xml ??

Compartilhar este post


Link para o post
Hauntedy    0
Hauntedy
tag da talkactions.xml ??

 

Sim isso eh uma talkaction portanto eh facil de se advinhar aonde fica a tag

 

 

 

 

@topic

Ficou muito bom.... esse eh um dos sistemas que eu gosto muito. Fica quenem o CS quando pedem pros players escolherem a proxima faze :yes:

Compartilhar este post


Link para o post
SoDD    0
SoDD

onde vai os arquivos da pasta MODS ?

Compartilhar este post


Link para o post
eskerII    0
eskerII

[Error - LuaScriptInterface::loadFile] data/talkactions/scripts/vote.lua:154: '

' expected near 'g'

Compartilhar este post


Link para o post
FKaupert    0
FKaupert

gratz black :D

script fico mt bom...

Compartilhar este post


Link para o post
alanvito    0
alanvito

[27/08/2010 17:50:07] [Error - LuaScriptInterface::loadFile] data/talkactions/scripts/vote.lua:154: ')' expected near 'g'

[27/08/2010 17:50:07] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/vote.lua)

[27/08/2010 17:50:07] data/talkactions/scripts/vote.lua:154: ')' expected near 'g'

[27/08/2010 17:50:07] [Error - LuaScriptInterface::loadFile] data/talkactions/scripts/vote.lua:154: ')' expected near 'g'

[27/08/2010 17:50:07] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/vote.lua)

[27/08/2010 17:50:08] data/talkactions/scripts/vote.lua:154: ')' expected near 'g'

[27/08/2010 17:50:08] [Error - LuaScriptInterface::loadFile] data/talkactions/scripts/vote.lua:154: ')' expected near 'g'

[27/08/2010 17:50:08] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/vote.lua)

[27/08/2010 17:50:08] data/talkactions/scripts/vote.lua:154: ')' expected near 'g'

 

Coloca isso aqui que eu acho que resolve:

---Script: 'Super Quiz System 1.1' By: Gooden

---Based: 'Advanced quiz system com logs!' By: Mock the bear

 

--Informations

--/quiz - Start a Quiz - Example: /quiz How Old Are You?,<15,16-20,20-30,30-40,>40

--This will create a Quiz with the Question: "How Old Are You?" and the Options:

-- (A) <15

-- (B) 16-20

-- © 20-30

-- (D) 30-40

-- (E) >40

--/quiz info - Check The Information of the current Quiz. Alert if no quiz Runing.

--/quiz restart - Restart the Quiz (Clean all the responses sent)

--/quiz close - Close the current Quiz.

--/quiz cancel - Delete the current Quiz

--/quiz commands - Show the commands that exists.

--/quizinstall - Install the Super Quiz System 1.0

 

local Quiz_Open=0

local Quiz_Finish=1

local Quiz_Cancel=2

local messageDelay = 60

dofile("config.lua")

function sendBroadcast(m)

local ls = db.getResult("SELECT count(*) as count FROM Quiz where Status="..Quiz_Open..";")

if ls:getDataInt("count") == 1 then --Verifica se existe Questionario a correr

doBroadcastMessage(m)

addEvent(sendBroadcast,messageDelay*1000,m)

end

end

 

function GetQuizId()

local ls = db.getResult("SELECT count(*) as count FROM Quiz where Status="..Quiz_Open..";")

if ls:getDataInt("count") == 1 then

local ls2 = db.getResult("SELECT id FROM Quiz where Status="..Quiz_Open..";")

return ls2:getDataInt("id")

else

return 0

end

end

 

function onSay(cid, words, param, channel)

local ls = db.getResult("SELECT count(*) as count FROM information_schema.tables WHERE table_schema = '"..sqlDatabase.."' AND table_name = 'Quiz';")

if ls:getDataInt("count") == 0 and words == '/quizinstall' and getPlayerGroupId(cid) >= 3 then

--Instalação e criação das BD'S

local QuizTable="CREATE TABLE Quiz (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Question VARCHAR(100),Status INT(1) NOT NULL DEFAULT 0,created TIMESTAMP DEFAULT NOW());"

local OptionsTable="CREATE TABLE Quiz_options (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Quiz INT NOT NULL,letter Varchar(1),Opt varchar(255));"

local ResponseTable="CREATE TABLE Quiz_response (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,account INT NOT NULL,Quiz INT NOT NULL,Opt INT NOT NULL);"

db.executeQuery(QuizTable)

db.executeQuery(OptionsTable)

db.executeQuery(ResponseTable)

doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 installed! Check the commands by typing /quiz commands')

else

if ls:getDataInt("count") == 0 then

if getPlayerGroupId(cid) >= 3 then

doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 not installed! To install type /quizinstall')

end

else

local OpenOne = GetQuizId()

if words == '!vote' then

if OpenOne ~= 0 then

local response=string.upper(string.sub(param, 1, 1))

local ls2 = db.getResult("SELECT count(*) as count FROM Quiz_options where quiz="..OpenOne.." and letter='"..response.."';")

if ls2:getDataInt("count") == 0 then

doPlayerSendTextMessage(cid,25,'Response to the Quiz not found!')

else

local ls3 = db.getResult("SELECT count(*) as count FROM Quiz_response where account="..getPlayerAccountId(cid).." and quiz="..OpenOne..";")

if ls3:getDataInt("count") == 0 then

db.executeQuery("INSERT INTO `Quiz_response` (account,Quiz,Opt) VALUES ("..getPlayerAccountId(cid)..","..OpenOne..",(Sele ct id from Quiz_options where quiz="..OpenOne.." and letter='"..response.."')); ")

doPlayerSendTextMessage(cid,25,"You have choosen the response "..response.."!!")

else

doPlayerSendTextMessage(cid,25,'You already voted!')

end

end

else

doPlayerSendTextMessage(cid,25,'No Quiz running at the moment!')

end

elseif words == '/quizinstall' and getPlayerGroupId(cid) >= 3 then

doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 already installed! Check the commands by typing /quiz commands')

elseif words == '/quiz' and getPlayerGroupId(cid) >= 3 then

if string.sub(param, 1,4) == 'info' and OpenOne ~= 0 then

if OpenOne ~= 0 then

local ls = db.getResult("SELECT * FROM Quiz where Status="..Quiz_Open..";")

local Question = ls:getDataString("Question")

ls:free()

 

local text=Question

local db_result = db.getResult("select letter,quiz_options.opt as opt,(select count(*) from quiz_response where quiz_response.opt=quiz_options.id) as Total from quiz_options where quiz="..OpenOne.." order by Total desc;")

if (db_result:getID() ~= -1) then

repeat

text=text..'\n('..db_result:getDataString("letter" )..') ' .. db_result:getDataString("opt") .. ' - '..db_result:getDataInt("Total")

until not db_result:next()

end

db_result:free()

doPlayerSendTextMessage(cid,25,text)

else

doPlayerSendTextMessage(cid,25,'No Quiz running!!')

end

elseif string.sub(param, 1,7) == 'install' then

doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 already installed! Check the commands by typing /quiz commands')

elseif string.sub(param, 1,7) == 'restart' then

if OpenOne ~= 0 then

db.executeQuery("Delete from quiz_response where quiz="..OpenOne..";")

doPlayerSendTextMessage(cid,25,'Quiz Restarted!!')

else

doPlayerSendTextMessage(cid,25,'No Quiz running!!')

end

elseif string.sub(param, 1,5) == 'close' then

if OpenOne ~= 0 then

local ls = db.getResult("SELECT * FROM Quiz where Status="..Quiz_Open..";")

local Question = ls:getDataString("Question")

ls:free()

 

local text='Quiz Closed. \n\n ' .. Question

local db_result = db.getResult("select letter,quiz_options.opt as opt,(select count(*) from quiz_response where quiz_response.opt=quiz_options.id) as Total from quiz_options where quiz="..OpenOne.." order by Total desc;")

if (db_result:getID() ~= -1) then

repeat

text=text..'\n('..db_result:getDataString("letter" )..') ' .. db_result:getDataString("opt") .. ' - '..db_result:getDataInt("Total")

until not db_result:next()

end

db_result:free()

 

db.executeQuery("Update Quiz set Status="..Quiz_Finish.." where status="..Quiz_Open..";")

doBroadcastMessage("Quiz Finished!")

doPlayerSendTextMessage(cid,25,text)

else

doPlayerSendTextMessage(cid,25,'No Quiz running!!')

end

elseif string.sub(param, 1,6) == 'cancel' then

if OpenOne ~= 0 then

db.executeQuery("Delete from quiz_response where quiz="..OpenOne..";")

db.executeQuery("Delete from quiz where id="..OpenOne..";")

doPlayerSendTextMessage(cid,25,'Quiz Deleted!!')

else

doPlayerSendTextMessage(cid,25,'No Quiz running!!')

end

elseif string.sub(param, 1,8) == 'commands' then

doPlayerSendTextMessage(cid,25,'Super Quiz System 1.0 Commands!\n/quiz - Start a Quiz - Example: /quiz How Old Are You?,<15,16-20,20-30,30-40,>40\n/quiz info - Check The Information of the current Quiz. Alert if no quiz Runing.\n/quiz restart - Restart the Quiz (Clean all the responses sent)\n/quiz close - Close the current Quiz.\n/quiz cancel - Delete the current Quiz\n/quiz commands - Show the commands that exists.\n/quizinstall - Install the Super Quiz System 1.0')

else

if OpenOne ~= 0 then

doPlayerSendTextMessage(cid,25,'There is already a Quiz running!')

else

local SP = param:split(",")

if #SP>1 then

local Question = SP[1]

db.executeQuery("INSERT INTO `Quiz` (Question,Status) VALUES ('"..Question.."',"..Quiz_Open..");")

 

OpenOne=GetQuizId()

 

local options = { }

local i=0

local text='Quiz: '..Question

for i = 2,#SP do

db.executeQuery("INSERT INTO `Quiz_options` (Quiz,letter,Opt) VALUES ("..OpenOne..",'"..string.char(63+i).."','"..string.trim(SP).."'); ")

text=text..'\n('..string.char(63+i)..') - '..string.trim(SP)

end

doPlayerSendTextMessage(cid,25,'Quiz Created!!')

sendBroadcast(text)

else

doPlayerSendTextMessage(cid,25,'Invalid parameters.')

end

end

end

end

end

end

return true

end

 

function string:split(delimiter)

local result = { }

local from = 1

local delim_from, delim_to = string.find( self, delimiter, from )

while delim_from do

table.insert( result, string.sub( self, from , delim_from-1 ) )

from = delim_to + 1

delim_from, delim_to = string.find( self, delimiter, from )

end

table.insert( result, string.sub( self, from ) )

return result

end

 

 

o erro está no espaco no "string.char", ta assim no topico "strin g.char" pelo menos eu acho, quando eu tirei o espaco melhorou ^^

 

espero estar certo :D

Editado por alanvito
Achei a solução ^^

Compartilhar este post


Link para o post
alanvito    0
alanvito

Otimo Script ^^

Compartilhar este post


Link para o post
Dargosh    0
Dargosh

[Error - LuaScriptInterface::loadFile] data/talkactions/scripts/vote.lua:154: '

 

oque aconteceu?

Compartilhar este post


Link para o post
ahbom    0
ahbom

nun entendi !

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×