PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: Tarot on 03 July, 2005, 13:46:09

Title: who can convert for me Phrase-O-Rama to lua5
Post by: Tarot on 03 July, 2005, 13:46:09
-- Phrase-O-Rama Script
-- By Chaggydawg
-- Version 0.3b
--
-- Much like a trivia script, be first to answer the hidden phrase
-- before it is revealed. Unlike most trivia script, this one does
-- does NOT bogg the hub down, nor does it consume more than 1Mb of
-- memory. You can add your own phrase lists as text fil
-- This is a fantastice script and my hubbers play it often
--
-- Modded by Mutor 9-22-04
-- Changes:
--
--   + Added Display of available phrase lists
--   + Added option for right click menu
--   + Loads/saves active list to file when hub/scripts restart
--   + Added option to enable/disable specified list
--   + Shortened the timer to make it a bit more fun
--   + Added a few more phrase lists
--
-- Thanks to BottledHate who took a moment to pull my head from the other end !
--
-- Have you ever lost sight of the forest because of the trees?
--                           
--
--User Settings-------------------------------------------------------------------------------------
timer = 9000
BotName = "??????Gotham??????"
phrasefile = "phraselists.txt"
SendCmdMenu = "yes"   --Send context menu? (right click menu)  "yes"/"no"
gameon = "off"      --Game on at hub/script restart?  "off"/"on"
--End User Settings----------------------------------------------------------------------------------
--

phrases = {}
phraselists = {}
topscores = {}
answer = ""
remainscore = 0

phrasenumbers = {}
startingphrase = 1


function Main()
LoadFromFile(phrasefile)
SetTimer(timer)
doreadscores()
doreadphrases()
donewphrase()
if gameon == "on" then StartTimer() end
end

function NewUserConnected(user,data)
   if SendCmdMenu == "yes" then
      user:SendData(sBotName, "??????Gotham?????? Game menu enabled, right click hub tab for commands.")
         UserCmds(user)
         if user.bOperator then
            OpCmds(user)
         end
   end
end

OpConnected = NewUserConnected

function UserCmds(user)
user:SendData("$UserCommand 1 3 [Game]\\Game Show Lists$<%[mynick]> +porlist||")
user:SendData("$UserCommand 1 3 [Game]\\Game Top 10 Scores$<%[mynick]> +scores||")
user:SendData("$UserCommand 1 3 [Game]\\Game Your Score$<%[mynick]> +myscore||")
user:SendData("$UserCommand 1 3 [Game]\\Game Phrase Lists$<%[mynick]> +porlist||")
user:SendData("$UserCommand 1 3 [Game]\\Game Help$<%[mynick]> +porhelp||")
end

function OpCmds(user)
user:SendData("$UserCommand 1 3 [Game]\\Game On$<%[mynick]> +startgame||")
user:SendData("$UserCommand 1 3 [Game]\\Game Off$<%[mynick]> +stopgame||")
user:SendData("$UserCommand 1 3 [Game]\\Game Toggle Lists$<%[mynick]> +toggle %[line:List-Name]||")
user:SendData("$UserCommand 1 3 [Game]\\Game Skip Phrase$<%[mynick]> +skip||")
end


function OnExit()
   SaveToFile(phrasefile , phraselists , "phraselists")
end

function DataArrival(curUser, Data)
s,e,cmd = strfind(Data,"%b<>%s(%S+)")
s,e,cmd2,list = strfind(Data,"%b<>%s+(%S+)%s(.+)|")
s,e,scored = strfind(Data,"%b<>%s%S+%s+(%d+)")
s,e,mess = strfind(Data, "%b<>%s+(.*)")
if cmd == "+startgame|" then
dostartgame(curUser)
return 1
elseif cmd == "+stopgame|" then
dostopgame(curUser)
return 1
elseif cmd == "+scores|" then
displayscores(curUser)
return 1
elseif cmd == "+porhelp|" then
dohelp(curUser)
return 1
elseif cmd == "+porlist|" then
dolists(curUser)
return 1
elseif cmd =="+skip|" then
doskipphrase(curUser)
return 1
elseif cmd == "+myscore|" then
domyscore(curUser)
return 1
elseif cmd2 == "+toggle" then
editlists(curUser)
return 1
end

if mess ~= nil and answer ~= " " then
mess = gsub(mess,"%A","")
ants = gsub(answer,"%A","")
if strfind(strlower(mess),strlower(ants)) ~= nil then
addtoscore(curUser,remainscore)
answer, startingphrase = donewphrase()
end
end
end

function dolists(curUser)
local plist = ""
local status = ""
local which = ""
for i, v in phraselists do
which = i
if v == "on" then
status = "  Active"
else
status = "Inactive"
end
plist = plist.."\t"..status.."  -  "..which.."\r\n"
end
local dsp
dsp = "\r\n\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
dsp = dsp.."\t=-=-=   Available ??????Gotham?????? Game Lists  =-=-=\r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
dsp = dsp..plist
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
dsp = dsp.."\t=-=    Enable/Diable Lists: +toggle    =-=\r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
curUser:SendData(dsp)
plist = ""
status = ""
which = ""
dsp = ""
end


function editlists(curUser,Data)
if not phraselists
    then
    curUser:SendData("Syntax "..cmd2.."  Type +porlist for available phrase lists.")
    elseif phraselists
      == "on" then
      phraselists
        = "off"
        curUser:SendData(list.." - Disabled")
        elseif phraselists
          == "off" then
          phraselists
            = "on"
            curUser:SendData(list.." - Enabled")
            end
            SaveToFile(phrasefile , phraselists , "phraselists")
            end

            function OnTimer()
            doreveal()
            end

            function donewphrase()
            doreadphrases()
            answer = phrases[random(1,getn(phrases))]
            startingphrase = 1
            remainscore = random(1,3)
            e,f = gsub(answer,"%a","")
            timer = 200 / f * 1000
            SetTimer(timer)
            return answer,startingphrase
            end

            function doreveal()
            if startingphrase == 1 then testing = gsub(answer,"%a","?"); startingphrase = 0; SendToAll(BotName,"This Phrase will be worth "..remainscore.." point(s) per unrevealed letter plus 5 points for solution."); end
            t,p = gsub(testing,"?","")
            if p < 2 then
            SendToAll(BotName,"The Answer Was: "..answer)
            donewphrase()
            else
            curnumber = burp()
            testing = strsub(testing,1,curnumber-1)..strsub(answer,curnumber,curnumber)..strsub(testing,curnumber+1,strlen(testing))
            SendToAll(BotName,"[Category: "..phrasename.."] "..testing)
            end
            end

            function burp()
            curnumber = random(1,strlen(answer))
            if strsub(testing,curnumber,curnumber) ~= "?" then burp() end
            return curnumber
            end


            function dostartgame(curUser)
            if gameon == "off" then
            gameon = "on"
            donewphrase()
            StartTimer()
            SendToAll(BotName, curUser.sName.." Has Started a new ??????Gotham?????? Game!")
            end
            end

            function dostopgame(curUser)
            if gameon == "on" then
            gameon = "off"
            SendToAll(BotName, curUser.sName.." Has Ended the ??????Gotham?????? Game!  ")
            SendToAll(BotName,"The Answer Was: "..answer)
            StopTimer()
            answer = " "
            remainscore = 0
            dowritescores()
            end
            end

            function displayscores(curUser)
            tscores = ""
            sort(topscores, function(a,b) return a[1]>b[1] end)
            total = 10
            if getn(topscores) < total then total = getn(topscores) end
            for i = 1,total,1 do
            tscores = tscores.."\t["..i.."] "..topscores
[2].." - "..topscores[1].."\r\n"
end

local dsp
dsp = "\r\n\r\n\t=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=\r\n"
dsp = dsp.."\t=-=-= Top 10 Of the ??????Gotham?????? game Player =-=-=\r\n"
dsp = dsp.."\t=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=\r\n"
dsp = dsp..tscores
dsp = dsp.."\t=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=\r\n\r\n"
curUser:SendData(dsp)
tscores = ""
dsp = ""
end

function addtoscore(curUser,remainscore)
dude = getn(topscores)+1
oldscore = 0
for i = 1,getn(topscores),1 do
if topscores[2] == curUser.sName then
dude = i
oldscore = topscores[1]
break
end
end
a,b = gsub(testing,"?",".")
topscores[dude] = {(b*remainscore)+oldscore+5,curUser.sName}
dowritescores()
sort(topscores, function(a,b) return a[1]>b[1] end)
for i = 1,getn(topscores),1 do
if topscores[2] == curUser.sName then
SendToAll(BotName,curUser.sName.." Got It!! The Answer Was: "..answer)
SendToAll(BotName,curUser.sName.." has been awarded "..((b*remainscore)+5).." points!")
SendToAll(BotName,"["..i.."] "..topscores[2].." - "..topscores[1])
end
end
end

function dowritescores()
writeto("por/porscores.txt","w")
write("1&"..topscores[1][2].."$"..topscores[1][1])
writeto()
for i = 2,getn(topscores),1 do
appendto("por/porscores.txt")
write("\n"..(i).."&"..topscores[2].."$"..topscores[1])
writeto()
end
end

function doreadscores()
readfrom("por/porscores.txt")
A=1
while 1 do
line = read()
if line == nil then break end
s,e,rank,unick,score = strfind(line,"(%S+)&(%S+)$(%S+)")
topscores[tonumber(A)] = {tonumber(score),unick}
A = A+1
end
A = nil
end

function doreadphrases()
phrases = {}
tempTable = {}
for i,v in phraselists do
   if v == "on" then tinsert(tempTable,i) end
end
phrasename = tempTable[random(1,getn(tempTable))]
readfrom("por/"..strlower(phrasename)..".txt")
t = 1
while 1 do
line = read()
if line == nil then break end
phrases[t] = line
t = t+1
end
end

function dohelp(curUser)
SendToAll("...")
local tmp
tmp = "\r\n\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<>=-=\r\n"  
tmp = tmp.."\t\t??????Gotham?????? User Command Help\r\n"
tmp = tmp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<>=-=\r\n"
tmp = tmp.."\t+porlist  : Displays Active ??????Gotham?????? Lists\r\n"
tmp = tmp.."\t+scores : Displays Top 10 ??????Gotham?????? Scores\r\n"
tmp = tmp.."\t+myscore : Displays your ??????Gotham?????? Score\r\n"
tmp = tmp.."\t+porhelp : Displays ??????Gotham?????? Help\r\n"
tmp = tmp.."\t+porhelp : Displays ??????Gotham?????? Help\r\n"
if curUser.bOperator then
tmp = tmp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<>=-=\r\n"
tmp = tmp.."\t\t??????Gotham?????? OP Command Help\r\n"
tmp = tmp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<>=-=\r\n"
tmp = tmp.."\t+startgame : Begins ??????Gotham?????? Game\r\n"
tmp = tmp.."\t+stopgame : Stops ??????Gotham?????? Game\r\n"
tmp = tmp.."\t+skip : Skips the Current Phrase\r\n"
tmp = tmp.."\t+toggle : Enable/Diable Lists\r\n"
end
tmp = tmp.."\t---<>------------------------------------------------------------------<>---\r\n"  
--if curUser.bOperator then
curUser:SendData(tmp)

end

function domyscore(curUser)
sort(topscores, function(a,b) return a[1]>b[1] end)
for i = 1,getn(topscores),1 do
if topscores[2] == curUser.sName then
curUser:SendData(BotName,"Rank ["..i.."] "..topscores[2].." - "..topscores[1])
break
end
end
end

function doskipphrase(curUser)
if curUser.bOperator then
SendToAll(BotName,curUser.sName.." has Skipped this phrase.")
SendToAll(BotName,"No Points Awarded This Round.")
SendToAll(BotName,"The Answer was: "..answer)
donewphrase()
end
end

function Serialize(tTable, sTableName, sTab)
   assert(tTable, "tTable equals nil");
   assert(sTableName, "sTableName equals nil");
   assert(type(tTable) == "table", "tTable must be a table!");
   assert(type(sTableName) == "string", "sTableName must be a string!");
   sTab = sTab or "";
   sTmp = ""
   sTmp = sTmp..sTab..sTableName.." = {\n"
   for key, value in tTable do
      local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
      if(type(value) == "table") then
         sTmp = sTmp..Serialize(value, sKey, sTab.."\t"); -- The Bug was here
      else
         local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
         sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
      end
      sTmp = sTmp..",\n"
   end
   sTmp = sTmp..sTab.."}\r\n"
   return sTmp
end

function SaveToFile(file , table , tablename)
   writeto(file)
   write(Serialize(table, tablename))
   writeto()
end

function LoadFromFile(file)
   if (readfrom(file) ~= nil) then
      readfrom(file)
      dostring(read("*all"))
      readfrom()
   end
end

i hoop someone help me
Title:
Post by: Markitos on 03 July, 2005, 15:44:09
Download here (http://mznetwork.mozdesigners.com/i/forum_files/Phrase-O-Rama%20lua5.rar)
or
 here (http://mutor.no-ip.com:413/files/por1.0bL5.rar)
Title:
Post by: Tarot on 03 July, 2005, 18:34:01
Thanks Markitos the game is running now  :D  :D
Title:
Post by: Markitos on 03 July, 2005, 18:41:45
QuoteOriginally posted by Tarot
Thanks Markitos the game is running now  :D  :D

Ur welcome!
Title: scores
Post by: H?LL?L?L??nG?L on 20 July, 2005, 10:50:27
I know this may sound silly but i cant clear the scores on this game :D Ive deleted them from the score file but they came back also taken the score file out ..and guess wot  :D  they came back.. Plz help wot am i doing wrong ?( Is there not a command for this :P
Title:
Post by: TiMeTrAVelleR on 20 July, 2005, 22:06:21
Stop the script remove the scores  then turn script on again in ptokax

Greetzz  TT