Well i know i'm a little crazy but i want a script that show's you when you tipe your birthday what sign of the zodiac it is :)))) ! i'f any 1 can help me i will be verry grateful :P
This is ok?
Part1:
--- BirthdayMan v 3.5
--- by Herodes -- Update 5/10/2004
--- Converted to Lua 5 by jiten (some ideas taken from BirthdayMan v 2.6 LUA_5.0 by TT and Jelf)
--- --- --- --- --- ---
-- v2.5
--- When Users are connected if there is a birthday it informs
--- When a Birhtday-User connect it plays surprise and informs the Hub
-- v2.6
--- Fix from ... comment for the display age
-- v 3
--- ability to display the Birthday nicks in the topic of the hub ... ( all of them ... the Ofline ones are in parentheses like (Herodes))
--- added agecmd to get exact age
--- added bhelpcmd
--- added display of birthdays in the findcmd
--- added ability for pm or main cmds .. ;)
-- v3.5
--- added integration of zodiac signs in various parts of the script
--- added celebrities birthdays with a switch to load or not the file
--- added celebcmd ,... works like findcmd but for celebrities
--- added switch for displaying birthday in topic
--- --- --- --- --- ---
----- do not edit these four lines
sec = 1000
minutes = 1000*60
hours = 1000*(60^2)
TxtSend = nil
----- Edit at will
bBot = "Surprise"
timecheck = 12*hours --- how much time before checking for birthdays ...
TopicShow = 1 --- to display the birthday nicks in the Hub's Topic ... ( 1/0 : enabled / disabled )
tProfiles = { ---- profile rights to commands, 0 cant use the bot at all, 1 can use listcmd/addcmd/findcmd/agecmd/agecmd/bhelpcmd , 2 can also use delcmd and addbircmd...
["-1"] = 1, --- Unregs
["0"] = 2, --- Masters
["1"] = 2, --- Operators
["2"] = 1, --- VIPs
["3"] = 1, --- Regs
["4"] = 1, --- Moderator
["5"] = 2, --- NetFounder
}
--- ( carry on typing your profiles in the right format : ["profile_number"] = value (0/1/2)
addcmd = "!mybirthday" --- !mybirthday dd/mm/yyyy dd = day , mm = month , yyyy = year .... Sets your birthday!
delcmd = "!delbirthday" --- !delbirthday is needed ... deletes 's birthday from the list
listcmd = "!birthdays" --- !birthdays Lists the birthdays stored
addbircmd = "!addbirth" --- !addbirth same as addcmd
findcmd = "!bornon" --- !bornon Shows a nice list of the ppl you share dates with ;)
celebcmd = "!celeb" --- !celeb Shows a nice list of celebrities that share the same dates with your birthday :) (only if celebrities are loaded!! )
agecmd = "!myage" --- !myage Shows you your age :)
bhelpcmd = "!bhelp" --- !bhelp Shows the cmds for the bot and some short explaination
birthdayfile = "cake.txt" --- The file that will be displayed on Birthday
oldestyear = 1900 --- !mybirthday 0/0/0000 situations are avoided ( lol )
allowedage = 6 --- !mybirthday situations are avoided (in years)
titshow = 1 --- Set this to 0 if you dont want to display the birthday ppl in the Hubs Topic
birthlog = "birthdays.tbl" --- The file where we'll be storing the birthdays ... << has to be in your scripts folder
loadcelebs = 1 --- Set this to 0 if you dont want to load the celebrities file ( costs about 2Mbs of mem )
celbirhtfile = "CelebBirths.tbl"
local f,e = io.open( birthlog, "a+" ) --//Error handle.. makes sure save file and dir exist...
f,e = io.open( birthlog, "a+" )
if f then
f:write("" )
f:close() --// file and path did not exist.. now they do.
else
birthlog = "birthdays.tbl"--//this is only if the path provided is invalid to winblows. defaults to a file in the scripts dir.
end
require(birthlog)
--- // --- Script-Starts
tBirthdays = {}
tCelebs = {}
tCalendar = {
[1] = { 31, "January", },
[2] = { 28, "February", },
[3] = { 31, "March", },
[4] = { 30, "April", },
[5] = { 31, "May", },
[6] = { 30, "June", },
[7] = { 31, "July", },
[8] = { 31, "August", },
[9] = { 30, "September", },
[10] = { 31, "October", },
[11] = { 30, "November", },
[12] = { 31, "December", },
}
function Main()
dofile(birthlog)
if loadcelebs ~= 0 then
dofile(celbirhtfile)
else
tCelebs = nil
end
tCalendar[2][1] = FixFebruary(tonumber(os.date("%Y")))
local hr = tonumber(os.date("%H"))*60*60*1000
local mins = 0
if tonumber(os.date("%M")) == 0 then
mins = 1
else
mins = tonumber(os.date("%M"))*60*1000
end
fixTime(hr+mins)
frmHub:UnregBot(bBot)
frmHub:RegBot(bBot)
end
function OnTimer()
CheckBirthdays()
TxtSend = nil
end
function NewUserConnected(user)
for i, v in tBirthdays do
if tBirthdays[i][2] == tonumber(os.date("%m")) and tBirthdays[i][1] == tonumber(os.date("%d")) then
if user.sName ~= i then
local msg = "Its "..i.."'s birhtday today .. ;D Turning "..(tonumber(os.date("%Y"))-tBirthdays[i][3] ).." today,... give a wish :)"
if GetItemByName(i) then
user:SendData(bBot, msg)
else user:SendData(bBot, msg.." when he comes online")
end
else
user:SendData(bBot, "Hey I know !!! YOU HAVE YOUR BIRTHDAY TODAY !!! HAPPIEST OF BIRTHDAYS !!!! ")
SendToAll(bBot, "Guys !! "..user.sName.." is here! What do we say ?? : )")
end
end
end
end
OpConnected = NewUserConnected
function CheckBirthdays()
tNow = {}
local count = 0
local yeah = nil
for i, v in tBirthdays do
if tBirthdays[i][2] == tonumber(os.date("%m")) then
if tBirthdays[i][1] == tonumber(os.date("%d")) then
if GetItemByName(i) then
local happy = GetItemByName(i)
DoHappyBirthday(happy)
yeah = 1
end
count = count + 1
if yeah == nil then
tNow[count] = "("..i..")"
else
tNow[count] = i
end
end
end
yeah = nil
end
if titshow ~= 0 then
local tit = ""
local ct = 0
for i,v in tNow do
if ct == 0 then
tit = " "..v
else
tit = tit..", "..v
end
ct = ct +1
end
if ct > 1 then
tit = "s "..tit
end
topic = frmHub:GetHubName()
frmHub:SetHubName(topic.." - Today is the birthday of the following user"..tit)
end
end
function FixFebruary(y)
local value = 0
if (tonumber(y)/4) - (math.floor(tonumber(y)/4)) == 0 then
value = 29
else value = 28
end
return value
end
function fixTime(now)
if now < timecheck then
now = timecheck-now
elseif now > timecheck then
now = now-timecheck
else now = timecheck
end
SetTimer(now)
StartTimer()
end
function ChatArrival(user, data)
prof = user.iProfile
local how = nil
if prof == nil then
prof = "-1"
end
if tProfiles[""..prof..""] >= 1 then
data = string.sub(data, 1, string.len(data)-1)
s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
if cmd == addcmd then
CheckBirthdays()
AddBirthDay(user, args, how)
return 1
elseif cmd == addbircmd and tProfiles[""..prof..""] == 2 then
CheckBirthdays()
AddBirthDay(user, args, how)
return 1
elseif cmd == delcmd and tProfiles[""..prof..""] == 2 then
DelBirth(user, args, how)
return 1
elseif cmd == listcmd then
ListBirths(user, how)
return 1
elseif cmd == findcmd then
BornOn(user, tBirthdays, "people", how)
return 1
elseif cmd == celebcmd then
if loadcelebs ~= 0 then
BornOn(user, tCelebs, "celebrities", how)
else
SendBack(" The celebrities file is not loaded.", user, how)
end
return 1
elseif cmd == agecmd then
ExactAge(user, how)
return 1
elseif cmd == bhelpcmd then
BHelp(user, how)
return 1
end
end
end
ToArrival = ChatArrival
function Zodiac(table)
tZodiacs = {
[1] = { 21, "Capricorn", "Aquarius" },
[2] = { 20, "Aquarius", "Pisces" },
[3] = { 21, "Pisces", "Aries" },
[4] = { 21, "Aries", "Taurus" },
[5] = { 22, "Taurus", "Gemini" },
[6] = { 22, "Gemini", "Cancer" },
[7] = { 23, "Cancer", "Leo" },
[8] = { 22, "Leo", "Virgo" },
[9] = { 24, "Virgo", "Libra" },
[10] = { 24, "Libra", "Scorpio" },
[11] = { 23, "Scorpio", "Sagittarius" },
[12] = { 23, "Sagittarius", "Capricorn"},
}
if tZodiacs[table[2]][1] > table[1] then
return tZodiacs[table[2]][2]
else
return tZodiacs[table[2]][3]
end
end
function BornOn(user, table, what, how)
if tBirthdays[user.sName] then
local lmsg = "\r\n These are the "..what.." that are born the same number-day as you\r\n"
lmsg = lmsg..FindSame(table, tBirthdays[user.sName][1] , "day", user.sName).."\r\n"
lmsg = lmsg.." These are the "..what.." that are born the same month as you\r\n"
lmsg = lmsg..FindSame(table, tBirthdays[user.sName][2] , "month", user.sName).."\r\n"
lmsg = lmsg.." These are the "..what.." that are born the same year as you\r\n"
lmsg = lmsg..FindSame(table, tBirthdays[user.sName][3] , "year", user.sName).."\r\n"
lmsg = lmsg.." These are the "..what.." that are born the same month and day with you \r\n"
lmsg = lmsg..FindSame(table, tBirthdays[user.sName][1].."/"..tBirthdays[user.sName][2] , "monthday", user.sName).."\r\n"
lmsg = lmsg.." These are the "..what.." that have the same birthday as yours\r\n"
lmsg = lmsg..FindSame(table, tBirthdays[user.sName][1].."/"..tBirthdays[user.sName][2].." - "..tBirthdays[user.sName][3] , "all", user.sName).."\r\n"
SendBack(lmsg, user, how)
else
SendBack("I dont have your birthday,... please use the "..addcmd.." dd/mm/yyyy command to enter your birthday", user, how)
end
end
function FindSame(tTab, val , var, name)
local tTmp = {}
local msg = ""
if var == "day" then
for i, v in tTab do
if val == v[1] and i ~= name then
tTmp[i] = v[1].."/"..v[2].." - "..v[3]
end
end
elseif var == "month" then
for i, v in tTab do
if val == v[2] and i ~= name then
tTmp[i] = v[1].."/"..v[2].." - "..v[3]
end
end
elseif var == "year" then
for i, v in tTab do
if val == v[3] and i ~= name then
tTmp[i] = v[1].."/"..v[2].." - "..v[3]
end
end
elseif var == "monthday" then
for i, v in tTab do
if val == v[1].."/"..v[2] and i ~= name then
tTmp[i] = v[1].."/"..v[2].." - "..v[3]
end
end
elseif var == "all" then
for i, v in tTab do
if val == v[1].."/"..v[2].." - "..v[3] and i ~= name then
tTmp[i] = v[1].."/"..v[2].." - "..v[3]
end
end
end
for i,v in tTmp do
msg = msg.."\t - "..i.."\t("..v..")\r\n"
end
if msg == "" then
msg = "\t - noone\r\n"
end
return msg
end
function DelBirth(user, args, how)
if args ~= nil then
if tBirthdays[args] then
if GetItemByName(args) then
GetItemByName(args):SendPM(bBot, ">>>> "..user.sName.." has deleted your birthday from my list .. ;( <<<<")
end
tBirthdays[args] = nil
SendBack("You deleted "..args.." bithday ...", user, how)
SaveFile(birthlog, tBirthdays, "tBirthdays")
else
SendBack(args.." is not in my birthday list ...", user, how)
end
else
SendBack("You need to give me a name ...", user, how)
end
end
function SendBack(what, user, how)
if how == nil then
user:SendData(bBot, what)
else
user:SendPM(bBot, what)
end
end
function ListBirths(user, how)
local str = "The Birthday List of the users of this Hub"
local msg = "\r\n ..-*'~ "..str.." ~'*-..\r\n"..string.rep("^", string.len(str)+2).."\r\n\t"
local c = 0
local status = ""
for i, v in tBirthdays do
if GetItemByName(i) then status = "online" else status = "offline" end
c = c + 1
tip = ". - "..tBirthdays[i][1].."/"..tBirthdays[i][2].."/"..tBirthdays[i][3].."\t- \t"..i.."\t"..Zodiac(tBirthdays[i]).."\t ( "..status.." )"
if tBirthdays[i][1].."/"..tBirthdays[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
if loadcelebs ~= 0 then
for i, v in tCelebs do
status = ":Celebrity:"
c = c + 1
tip = ". - \t"..tCelebs[i][1].."/"..tCelebs[i][2].."/"..tCelebs[i][3].."\t- \t"..i.."\t"..Zodiac(tCelebs[i]).."\t ( "..status.." )"
if tCelebs[i][1].."/"..tCelebs[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
end
SendBack(msg, user, how)
end
Part 2:
function AddBirthDay(user, args, how)
local pers = ""
if args ~= nil then
local s,e,name,day,month,year = string.find(args, "(%S+)%s+(%d+)/(%d+)/(%d+)")
if name == nil then
name = user.sName
pers = "you"
s,e,day,month,year = string.find(args, "(%d+)/(%d+)/(%d+)")
else pers = name
end
if month ~= nil and day ~= nil and year ~= nil and (tonumber(month) >= 1) and (tonumber(month) <= 12) then
day = tonumber(day)
month = tonumber(month)
year = tonumber(year)
if year > oldestyear then
if year < (tonumber(os.date("%Y")) - allowedage) then
if month == 2 then
daylimit = FixFebruary(year)
else daylimit = tCalendar[month][1]
end
if day <= daylimit and day >= 1 then
if tBirthdays[name] then
month = tBirthdays[name][2]
if user.sName == name then
SendBack("I have your birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2], user, how)
else
SendBack("I have "..name.."'s birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how)
end
local profstr = ""
for i,v in tProfiles do
if tProfiles[i] == 2 then
profstr = GetProfileName(tonumber(i)).."s"
break
end
end
SendBack("If you dont think this is correct ... then talk to one of our "..profstr , user, how)
else tBirthdays[name] = {}
tBirthdays[name][1] = day
tBirthdays[name][2] = month
tBirthdays[name][3] = year
SaveFile(birthlog, tBirthdays, "tBirthdays")
SendToAll("You Are a "..Zodiac(tBirthdays[name]).."!!!")
if user.sName == name then
SendBack("Your birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how)
SendBack("I didnt know you are "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)" , user, how)
else
SendBack(name.."'s birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how)
SendBack("I didnt know "..name.." is "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)" , user, how)
end
if user.sName == name then
SendBack("New birthday added by "..user.sName.." his/her is on the "..tBirthdays[name][1].." of "..tCalendar[month][2].." a "..Zodiac(tBirthdays[name]) , user, how)
else
SendBack(user.sName.." added "..name.."'s birthday, which is on the "..tBirthdays[name][1].." of "..tCalendar[month][2].." a "..Zodiac(tBirthdays[name]) , user, how)
end
end
end
else
SendBack("Come ON! "..pers.." cant be less than "..allowedage.." years old !!! LIAR >:(" , user, how)
end
else SendBack("Come ON! "..pers.." cant be more than "..(year-oldestyear).." years old !!! LIAR >:(" , user, how)
end
else SendBack("The date you provided was not valid ... ( syntax example : 14/5/1981 )" , user, how)
end
else SendBack("Please enter your birthday after the command ..." , user, how)
end
end
function FindCorrectAge(table)
if table[2] > tonumber(os.date("%m")) then
return ( tonumber(os.date("%Y")) - table[3] ) - 1
elseif table[2] < tonumber(os.date("%m")) then
return tonumber(os.date("%Y")) - table[3]
elseif table[2] == tonumber(os.date("%m")) then
if table[1] <= tonumber(os.date("%d")) then
return tonumber(os.date("%Y")) - table[3]
else
return ( tonumber(os.date("%Y")) - table[3] ) - 1
end
end
end
function DoHappyBirthday(nick)
if TxtSend == nil then
SendToAll(ReadTextFile(birthdayfile))
TxtSend = 1
end
local age = tonumber(os.date("%Y")) - tBirthdays[nick.sName][3]
local tSurpises = {
nick.sName.." is gonna have a PAAARTY, today he is turning "..age.." Happy Birthday !!!!",
"All of you spam "..nick.sName.." with Birthday messages ;), ...turning "..age.." today !!!",
"Who's turning "..age.." today ?? :D... The day AND the night belongs to "..nick.sName,
"Happy Birthday to you, Happy Birthday dear "..nick.sName..", we all wish you your "..age.." will be better than your "..(age-1).." !! :)",
" I think Mr"..nick.sName.." has his/her birthday today ... he/she should be turning "..age.." today ;D",
"A "..Zodiac(tBirthdays[nick.sName]).." is turning "..age.." today!!! ... it's "..nick.sName.."'s birthday!!!"
};
SendToAll( bBot , tSurpises[math.random(1, table.getn(tSurpises)) ] )
end
function ExactAge(user, how)
local table = tBirthdays[user.sName]
if table == nil then
SendBack("I dont have your birthday,... please use the "..addcmd.." dd/mm/yyyy command to enter your birthday", user, how)
return 1
else
local curAge = FindCorrectAge(table)
local finMonth = 0
if tonumber(os.date("%m")) < table[2] then
finMonth = 12 - ( table[2] - tonumber(os.date("%m")) )
elseif tonumber(os.date("%m")) > table[2] then
finMonth = ( tonumber(os.date("%m")) - table[2] )
end
local finDays = 0
if tonumber(os.date("%d")) < table[1] then
finMonth = finMonth - 1
local tempMonth = table[2] - 1
finDays = ( tCalendar[tempMonth][1] + ( tonumber(os.date("%d")) - table[1] ) )
if tonumber(os.date("%d")) > tCalendar[tonumber(os.date("%m"))][1] then
finMonth = finMonth + 1
finDays = tCalendar[tonumber(os.date("%m"))][1] - finDays
end
else
finDays = tonumber(os.date("%d")) - table[1]
end
if finMonth <= 0 then
finMonth = 12 + finMonth
if curAge == tonumber(os.date("%Y")) - table[3] then
SendToAll("yeah")
curAge = curAge - 1
end
end
if finMonth == 12 then
curAge = curAge + 1
finMonth = 0
end
SendBack("You are "..curAge.." years, "..finMonth.." months and "..finDays.." days old (that according to the Hub's clock :)", user, how)
end
end
function BHelp(user, how)
if tProfiles[""..prof..""] ~= 0 then
local msg = "\r\n\t\t You can use the following commands for "..bBot.."\r\n"
if tProfiles[""..prof..""] >= 1 then
msg = msg.."\t - "..bhelpcmd.." \t\t\t\t- this text :)\r\n"
msg = msg.."\t - "..listcmd.." \t\t\t- this will list the birthdays in store\r\n"
msg = msg.."\t - "..addcmd.." dd/mm/yyyy \t\t- put your own birthday :)\r\n"
msg = msg.."\t - "..findcmd.." \t\t\t- this will display the people that have similar birthday to yours\r\n"
if loadcelebs ~= 0 then
msg = msg.."\t - "..celebcmd.." \t\t\t\t- this will display the celebrities that have similar birthday to yours\r\n"
end
msg = msg.."\t - "..agecmd.." \t\t\t\t- this shows you your exact age ( days months years )\r\n"
if tProfiles[""..prof..""] == 2 then
msg = msg.."\t - "..delcmd.." \t\t- this deletes the birthday of \r\n"
msg = msg.."\t - "..addbircmd.." dd/mm/yyyy \t- this adds the birthday of "
end
end
SendBack(msg, user, how)
end
end
--- // --- Table Serialization --- Thanks NL
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 string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
---------------------------
function LoadFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
----------------------------
function SaveFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function ReadTextFile(file)
local message = "\r\n"
local handle = io.open(file,"r")
if (handle ~= nil) then
while 1 do
local line = handle:read()
if ( line == nil ) then
break
else
message = message.."\t"..line.."\r\n"
end
end
handle:close()
return message
else
end
end
C ya
Herodes' Birthday Bot maybe knows it...
well thanks..... :D ....... i needed that script :P
Ok, what if I learned to write a reply in less than 3 minutes? :D 8) :P
Yes Herodes script.. i have read thread of Danuts.. and I things this script is ok for he :D
6Marilyn6Manson6 ...... thx bro :D ....... why in the world thouse emoticons dont work.... :))
QuoteOriginally posted by Danutz
6Marilyn6Manson6 ...... thx bro :D ....... why in the world thouse emoticons dont work.... :))
Welcome Danutz... ps: for active smile in post.. when you reply disable this:
Deactivate smilies in this post.
in page of post.. and you see smile. C ya
BotName = "TrIvIaBoT"
ScriptVersion = "v2.2"
BotVersion = BotName.." "..ScriptVersion
-- This file is not needed it will be created if it not exists
strTrivScoreFile = "TriviaScores.dat"
-- This file is needed unless you want to run a Trivia with only two questions ;)
strDefTrivFile = "triviaa.dat"
strTrivFile = strDefTrivFile
strQFile = "Questions.dat"
-- This char will be the global separator? (Make it one that is not used in nicknames nor questions ;)
strGSep = "*"
-- This char is used to mask the unrevealed chars
strCMask = "*"
-- Default startup mode of Trivia!
lngDefMode = 0 -- (0 = game is played in chat!, 1 = game is played in chat but questions only show for players, 2 = game is played in pm with players)
lngMode = lngDefMode
-- Max number of questions to show when a Operator ask to see list Questions 0 = 0, -1 = Disabled
lngMaxShowList = 50
-- Max no of Hints per word, and always hit on a hidden char
lngMaxHints = 5
boolHintAlwaysHitHidden = nil -- (nil = off, 1 = on)
-- How much time before a question end. Time in Trivia is measured in 15 seconds, 1 = 15 seconds, 2 = 30 seconds etc!
-- Rest is how long to rest after a question is solved depening on when the word is solved in the Timer loop it is ?10 secs to the setting!
lngMaxTime = 8 -- (Needs to be a multiple of 4 i.e. 4 / 8 / 12 / 16)
lngRestTime = 1
lngHintTime = lngMaxTime / 4
-- How often should the bot autosave the scores
boolAutoSaveScores = 1 -- (nil = off, 1 = on)
countSaveTurns = 1 -- After how many questions should the scores be saved
-- Should bot reveal the correct answer once time is up?
boolRevealAnswer = 1 -- (nil = off, 1 = on)
-- Should the bot display what guess made the word become a little clearer if played in PM!
boolShowGuessesInPM = 1 -- (nil = off, 1 = on)
-- Should the bot Auto Reveal Hints?
boolAutoHint = 1 -- (nil = off, 1 = on)
-- Should the bot auto login every user on connect ?
boolAutoLogin = 1 -- (nil = off, 1 = on)
-- Do you want users to be able to add questions ? Operators can always add questions.
boolAddQuestion = No -- (nil = No, 1 = Yes)
-- TriggStart is what char the commands should begin with I use ! but you can use # or whatever
TriggStart = ""
-- Theese are the different triggers I've tried to name them so that one easily understand what they do!
-- I include TriggStart and then the word within "" this word is not casesensitive!
JoinTrigg = TriggStart.."Joc"
PartTrigg = TriggStart.."Nujoc"
StartTrigg = TriggStart.."Start"
StopTrigg = TriggStart.."Stop"
WordTrigg = TriggStart.."Word"
QuizTrigg = TriggStart.."curent"
RestartTrigg = TriggStart.."Restartoiul"
PointTrigg = TriggStart.."Puncte"
ScoreTrigg = TriggStart.."Scor"
PlayerTrigg = TriggStart.."Jucatori"
QuestionsTrigg = TriggStart.."Intrebari"
ReloadTrigg = TriggStart.."Reload"
HelpTrigg = TriggStart.."Help"
ExtraHelpTrigg = TriggStart.."Help+"
SaveTrigg = TriggStart.."Salveazascoru"
LoadTrigg = TriggStart.."Load"
ModeTrigg = TriggStart.."Mod"
HintTrigg = TriggStart.."Indiciu"
TopTrigg = TriggStart.."Top20"
AddTrigg = TriggStart.."Adauga"
bcount = 0
scount = 0
sQuestion = "intrebari"
sAnswer = ""
guessArray = {}
lngGuessmax = 0
playerArray = {}
pointArray = {}
lngWord = 0
lngPassed = 0
lngHinted = 0
strWord = ""
strQuestion = "intrebari"
strSolved = ""
strBanner = ""
strStart = "Trivia a fost pornita de catre un Operator!"..strBanner
strStopp = "Trivia a fost oprita de catre un Operator!"..strBanner
function Main()
frmHub:RegBot(BotName)
ReloadQuestions()
setlocale("swe")
LoadScores()
end
function NewUserConnected(curUser)
if (boolAutoLogin) then
if (not (playerArray[curUser.sName])) then
playerArray[curUser.sName] = 1
else
playerArray[curUser.sName] = nil
end
end
--topten(curUser)
end
function OpConnected(curUser)
if (boolAutoLogin) then
if (not (playerArray[curUser.sName])) then
playerArray[curUser.sName] = 1
else
playerArray[curUser.sName] = nil
end
end
end
function UserDisconnected(curUser)
playerArray[curUser.sName] = nil
end
function OpDisconnected(curUser)
playerArray[curUser.sName] = nil
end
function DataArrival(curUser, data)
local boolPlaydata = nil
if (strsub(data, 1, 1) == "<") then
data = strsub(data, 1, (strlen(data) - 1))
if ((lngMode == 0) or (lngMode == 1)) then
boolPlaydata = 1
end
elseif (strsub(data, 1, 4) == "$To:") then
data = strsub(data, 1, (strlen(data) - 1))
local _, _, whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == BotName) then
data = strsub(data, (15 + strlen(BotName) + strlen(curUser.sName)))
if (lngMode == 2) then
boolPlaydata = 1
local _, _, chat = strfind(data, "%b<>%s(.+)")
SendChatToOthers(chat, curUser)
end
end
end
local _, _, firstWord = strfind(data, "%b<>%s+(%S+)")
if (firstWord ~= nil) then
if ((strlower(firstWord) == strlower(HelpTrigg)) or (strlower(firstWord) == strlower(ExtraHelpTrigg))) then
showHelp(curUser)
elseif (strlower(firstWord) == strlower(SaveTrigg)) then
if (curUser.bOperator) then
SaveScores(curUser)
end
elseif (strlower(firstWord) == strlower(LoadTrigg)) then
if (curUser.bOperator) then
LoadScores(curUser)
end
elseif (strlower(firstWord) == strlower(TopTrigg)) then
TopTen(user)
elseif (strlower(firstWord) == strlower(AddTrigg)) then
if (boolAddQuestion) then
s,e,sQuestion,sAnswer = strfind(data, "%b<>%s+%S+%s+(.+)#(.+)")
AddQuestion(curUser,sQuestion,sAnswer)
elseif (curUser.bOperator) then
s,e,sQuestion,sAnswer = strfind(data, "%b<>%s+%S+%s+(.+)#(.+)")
AddQuestion(curUser,sQuestion,sAnswer)
else
SendToPlayers("Questions cannot be added by users at this time")
end
elseif (strlower(firstWord) == strlower(ModeTrigg)) then
if (curUser.bOperator) then
local _, _, ModeDigit = strfind(data, "%b<>%s+%S+%s+(%d+)")
if (ModeDigit ~= nil) then
lngMode = tonumber(ModeDigit)
if (lngMode == 0) then
SendToPlayers("Game is played in chat")
elseif (lngMode == 1) then
SendToPlayers("Game is played in chat but Questions only show for players")
elseif (lngMode == 2) then
SendToPlayers("Game is played in PM with Players")
else
SendToPlayers("Errorous mode, mode set to default")
lngMode = lngDefMode
end
end
end
elseif (strlower(firstWord) == strlower(JoinTrigg)) then
if (not (playerArray[curUser.sName])) then
playerArray[curUser.sName] = 1
SendToPlayers(curUser.sName.." e jucator(e)!")
else curUser:SendPM(BotName, "Deja ejti jucator(e)...")
end
elseif (strlower(firstWord) == strlower(PartTrigg)) then
if (playerArray[curUser.sName]) then
SendToPlayers(curUser.sName.." nu mai e jucator(e)!")
playerArray[curUser.sName] = nil
end
elseif (strlower(firstWord) == strlower(RestartTrigg)) then
if (curUser.bOperator) then
SendToPlayers("TriviaBot restarted. All points etc are lost!")
SendToPlayers("If Save is used now it will overwrite the old save!")
pointArray = {}
StopQuiz(1)
end
elseif ((strlower(firstWord) == strlower(PointTrigg)) and (playerArray[curUser.sName])) then
if (pointArray[curUser.sName]) then
SendToPlayers(curUser.sName.." ai "..pointArray[curUser.sName].." puncte!")
else
SendToPlayers(curUser.sName.." ai 0 puncte!")
end
elseif ((strlower(firstWord) == strlower(HintTrigg)) and (playerArray[curUser.sName])) then
if ((lngWord ~= 0) and strfind(strSolved, strCMask, 1, plain)) then
if (lngHinted < lngMaxHints) then
for nn=1,bcount do
local lngRepChar = random(1, strlen(strWord))
while 1 do
if (boolHintAlwaysHitHidden) then
if (strsub(strSolved, lngRepChar, lngRepChar) == strCMask) then
break
end
else
break
end
lngRepChar = random(1, strlen(strWord))
end
local strTurn = ""
for x=1, strlen(strWord) do
if (x == lngRepChar) then
strTurn = strTurn..strsub(strWord, x, x)
else
strTurn = strTurn..strsub(strSolved, x, x)
end
end
strSolved = strTurn
end
lngHinted = lngHinted + 1
lngHintTimeCount = lngHintTimeCount + lngHintTime
SendToPlayers("Indiciu: "..strSolved)
acount = ""
else
SendToPlayers("Toate indiciile au fost folosite pentru acest cuvant!")
end
else
SendToPlayers("Nu e nevoie de indiciu!")
end
elseif ((strlower(firstWord) == strlower(ScoreTrigg)) and (playerArray[curUser.sName])) then
curUser:SendPM(BotName, "SCORES:")
curUser:SendPM(BotName, "---------------------------------------------------------")
for index, value in pointArray do
curUser:SendPM(BotName, index.."'s points: "..value)
end
curUser:SendPM(BotName, "---------------------------------------------------------")
elseif ((strlower(firstWord) == strlower(PlayerTrigg)) and (playerArray[curUser.sName])) then
curUser:SendPM(BotName, "PLAYERS:")
curUser:SendPM(BotName, "---------------------------------------------------------")
for index, value in playerArray do
curUser:SendPM(BotName, index)
end
curUser:SendPM(BotName, "---------------------------------------------------------")
elseif (strlower(firstWord) == strlower(QuestionsTrigg)) then
if (curUser.bOperator) then
curUser:SendPM(BotName, "TOP "..lngMaxShowList.." QUESTIONS:")
curUser:SendPM(BotName, "---------------------------------------------------------")
local lngShowMax = lngMaxShowList
for index, value in guessArray do
if (lngShowMax == 0) then
break
end
arrTmp = tokenize(guessArray[index], strGSep)
strTmp = arrTmp[1]
curUser:SendPM(BotName, "["..index.."] "..strTmp)
lngShowMax = lngShowMax - 1
end
curUser:SendPM(BotName, "Total # of questions: "..lngGuessmax)
curUser:SendPM(BotName, "---------------------------------------------------------")
curUser:SendPM(BotName, " ")
end
elseif (strlower(firstWord) == strlower(StartTrigg)) then
if (curUser.bOperator) then
if (lngWord == 0) then
playerArray[curUser.sName] = 1
SendToAll(BotName, strStart)
if (lngMode == 2) then
SendToPlayers(strStart)
end
StopQuiz(1)
else
SendToAll(BotName, "There is already a game going on type "..JoinTrigg.." to join!")
end
else
curUser:SendPM(BotName, "Doar operatori pot sa porneasca sau sa opreasca Trivia.")
end
elseif (strlower(firstWord) == strlower(StopTrigg)) then
if (curUser.bOperator) then
HoldQuiz()
StopQuiz()
SendToAll(BotName, strStopp)
if (lngMode == 2) then
SendToPlayers(strStopp)
end
end
elseif (strlower(firstWord) == strlower(WordTrigg)) then
if ((lngWord ~= 0) and (playerArray[curUser.sName] == "Player")) then
SendToPlayers("Current intrebarea e: "..strSolved.." ("..strlen(strSolved)..")")
end
elseif (strlower(firstWord) == strlower(QuizTrigg)) then
if ((lngWord ~= 0) and (playerArray[curUser.sName])) then
SendToPlayers("Intrebarea e: "..strQuestion)
end
elseif (strlower(firstWord) == strlower(ReloadTrigg)) then
if (curUser.bOperator) then
local _, _, secondWord = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (secondWord) then
handle = openfile(secondWord, "r")
if (handle) then
closefile(handle)
strTrivFile = secondWord
end
end
HoldQuiz()
ReloadQuestions()
end
else
if ((lngWord ~= 0) and (boolPlaydata)) then
if (playerArray[curUser.sName]) then
local msg = strsub(data, (4 + strlen(curUser.sName)))
if (strlen(msg) >= strlen(strWord)) then
local boolDisc = nil
local strTurn = ""
if strlower(msg) == strlower(strWord) then
strTurn = strWord
boolDisc = 1
else
strTurn = strSolved
end
if (boolDisc) then
strSolved = strTurn
end
if (boolDisc) then
if (strlower(msg) ~= strlower(strWord)) then
SendToOthers(curUser, msg)
SendToPlayers("Raspunsul e: "..strSolved)
end
end
if (strlower(msg) == strlower(strWord)) then
if (not (pointArray[curUser.sName])) then
pointArray[curUser.sName] = 0
end
if lngHinted == 3 then pointArray[curUser.sName] = pointArray[curUser.sName] + 1
elseif lngHinted == 2 then pointArray[curUser.sName] = pointArray[curUser.sName] + 2
elseif lngHinted == 1 then pointArray[curUser.sName] = pointArray[curUser.sName] + 3
else pointArray[curUser.sName] = pointArray[curUser.sName] + 4
end
SendToPlayers("Raspunsul a fost: "..strSolved)
SendToPlayers("Raspunsul a fost rezolvat de: "..curUser.sName)
SendToPlayers("Urmatoarea intrebare in "..(lngRestTime * 15).." (?15) Secunde")
lngPassed = lngMaxTime
SendToPlayers(curUser.sName.."'s points: "..pointArray[curUser.sName])
HoldQuiz()
end
end
end
end
end
end
end
function HoldQuiz()
strWord = ""
strQuestion = ""
strSolved = ""
end
function StopQuiz(restart)
lngWord = 0
lngPassed = 0
strWord = ""
strQuestion = ""
strSolved = ""
StopTimer()
if (restart) then
StartQuiz()
end
end
function StartQuiz()
lngWord = random(1, lngGuessmax)
QWarray = tokenize(guessArray[lngWord], strGSep)
strQuestion = QWarray[1]
strWord = QWarray[2]
strSolved = ""
for x=1, strlen(strWord) do
if (strsub(strWord, x, x) == " ") then
strSolved = strSolved.." "
else
strSolved = strSolved..strCMask
end
end
lngPassed = 0
lngHinted = 0
lngHintTimeCount = lngHintTime
if strlen(strWord) < 4 then
bcount = random(1, 2)
elseif strlen(strWord) >= 4 and strlen(strWord) <= 9 then
bcount = random(1, 3)
elseif strlen(strWord) >= 9 and strlen(strWord) <= 20 then
bcount = random(2, 4)
else
bcount = random(3, 5)
end
SetTimer(15000)
StartTimer()
SendToPlayers("Intrebare: "..strQuestion)
SendToPlayers("Raspuns: "..strSolved.." ("..strlen(strSolved)..")")
end
function OnTimer()
lngPassed = lngPassed + 1
if (lngPassed == lngMaxTime) then
scount = scount + 1
if scount == countSaveTurns then
local handle = openfile(strTrivScoreFile, "w")
for index, value in pointArray do
write(handle,index..strGSep..value.."\r\n")
end
closefile(handle)
scount = 0
end
if (boolRevealAnswer) then
SendToPlayers("Raspunsul a fost '"..strWord.."' shi nu a fost rezolvat!")
else
SendToPlayers("Raspunsul nu a fost rezolvat!")
end
SendToPlayers("Urmatoarea intrebare in "..(lngRestTime * 15).." Secunde")
HoldQuiz()
elseif (lngPassed >= (lngRestTime + lngMaxTime)) then
StopQuiz(1)
elseif (lngPassed == lngHintTimeCount) then
if (boolAutoHint) then
for nn=1,bcount do
local lngRepChar = random(1, strlen(strWord))
while 1 do
if (boolHintAlwaysHitHidden) then
if (strsub(strSolved, lngRepChar, lngRepChar) == strCMask) then
break
end
else
break
end
lngRepChar = random(1, strlen(strWord))
end
local strTurn = ""
for x=1, strlen(strWord) do
if (x == lngRepChar) then
strTurn = strTurn..strsub(strWord, x, x)
else
strTurn = strTurn..strsub(strSolved, x, x)
end
end
strSolved = strTurn
end
lngHinted = lngHinted + 1
lngHintTimeCount = lngHintTimeCount + lngHintTime
SendToPlayers("Indiciu: "..strSolved)
end
end
end
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
function ReloadQuestions()
guessArray = {}
lngGuessmax = 0
local boolRestart = nil
if (lngWord ~= 0) then
SendToPlayers("Reloading questions, game will be shut down!")
StopQuiz()
boolRestart = 1
end
handle = openfile(strTrivFile, "r")
if (handle) then
local line = read(handle)
while line do
if ((line ~= "") and (strfind(line, strGSep, 1, plain))) then
tinsert(guessArray, line)
lngGuessmax = lngGuessmax + 1
end
line = read(handle)
end
closefile(handle)
end
if (lngGuessmax < 1) then
guessArray = {
"The finest car there is?"..strGSep.."Honda CRX del Sol",
"Who brought you this TriviaBot"..strGSep.."Leon a.k.a. Don Leon"
}
lngGuessmax = 2
end
if (boolRestart) then
SendToPlayers("Reloaded questions, game will be restarted! Current # of questions: "..lngGuessmax)
StartQuiz()
end
strTrivFile = strDefTrivFile
end
function SaveScores(curUser)
local handle = openfile(strTrivScoreFile, "w")
for index, value in pointArray do
write(handle,index..strGSep..value.."\r\n")
end
curUser:SendData(BotName,"Scores saved")
closefile(handle)
end
function LoadScores(curUser)
local handle = openfile(strTrivScoreFile, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
pointArray[arrTmp[1]] = tonumber(arrTmp[2])
end
line = read(handle)
end
curUser:SendData(BotName,"Scores Loaded")
closefile(handle)
end
end
function AddQuestion(curUser, sQuestion, sAnswer)
local handle = openfile(strQFile, "a")
write(handle,"Submitted by <"..curUser.sName.."> "..sQuestion..strGSep..sAnswer.."\r\n")
SendToPlayers(curUser.sName.." a adaugat intrebarea "..sQuestion)
curUser:SendPM(BotName,curUser.sName.." intrebarea ta a fost acceptata .. iar raspunsul este: "..sAnswer)
closefile(handle)
end
function SendToPlayers(msg)
if ((lngMode > 2) or (lngMode < 0)) then
lngMode = lngDefMode
end
if (lngMode == 0) then
SendToAll(BotName, msg)
elseif (lngMode == 1) then
for index, value in playerArray do
SendToNick(index, "<"..BotName.."> "..msg)
end
elseif (lngMode == 2) then
for index, value in playerArray do
SendPmToNick(index, BotName, msg)
end
end
end
function SendToOthers(msg, curUser)
if ((lngMode == 2) and (boolShowGuessesInPM)) then
for index, value in playerArray do
if (index ~= curUser.sName) then
SendPmToNick(index, BotName, "<"..curUser.sName.."> "..msg)
end
end
end
end
function SendChatToOthers(chat, curUser)
if (lngMode == 2) then
for index, value in playerArray do
if (index ~= curUser.sName) then
SendToNick(index, "$To: "..index.." From: "..BotName.." $<"..curUser.sName.."> "..chat)
end
end
end
end
function showHelp(curUser)
curUser:SendData(" ")
curUser:SendData(" "..BotVersion.." Comenzi:")
curUser:SendData(" ")
if (lngMode == 0) then
curUser:SendData(" Trivia e setata sa fie jucata in Chat <>")
elseif (lngMode == 1) then
curUser:SendData(" "..BotVersion.." is set to be played in chat (hidden)")
else
curUser:SendData(" "..BotVersion.." is set to be played in PM")
end
curUser:SendData(" "..HelpTrigg.." - Iti arata toate comenzile")
curUser:SendData(" "..JoinTrigg.." - Intri in joc")
curUser:SendData(" "..PartTrigg.." - ieshi din joc")
curUser:SendData(" "..WordTrigg.." - Iti arata prima litera (raspuns)")
curUser:SendData(" "..QuizTrigg.." - Iti arata intrebarea curenta")
curUser:SendData(" "..PointTrigg.." - Iti arata punctele tale")
curUser:SendData(" "..ScoreTrigg.." - Arata scorul")
curUser:SendData(" "..PlayerTrigg.." - Iti arata totzii jucatorii care joaca TRIVIA")
curUser:SendData(" "..HintTrigg.." - Iti da un indiciu de raspuns")
curUser:SendData(" "..TopTrigg.." - Arata topul color mai buni jucatorii ")
curUser:SendData(" "..AddTrigg.." - Adaugi o intrebare pt. Trivia. La raspuns tre sa pui in fata #")
curUser:SendData(" EXEMPLU : adauga Cat de repede zboara o pasare?#Nu stiu")
if (curUser.bOperator) then
curUser:SendData(" ")
curUser:SendData(" "..BotVersion.." Comenzi pentru Operatori:")
curUser:SendData(" "..StopTrigg.." - Opreste botu de Trivia")
curUser:SendData(" "..RestartTrigg.." - Reseteaza botu shi scorurile!")
curUser:SendData(" "..QuestionsTrigg.." - Arata top intrebari (50)")
curUser:SendData(" "..ReloadTrigg.." () - Incarca intrebrile din "..strDefTrivFile)
curUser:SendData(" "..ModeTrigg.." - Pentru a schimba modu de joc (0-2)!")
curUser:SendData(" "..SaveTrigg.." - Salveaza scoru in "..strTrivScoreFile)
curUser:SendData(" "..LoadTrigg.." - Pune scou ru din "..strTrivScoreFile)
curUser:SendData(" "..StartTrigg.." - Daca dai start la Trivia automat ejti jucator(operatori)")
curUser:SendData(" ")
curUser:SendData(" "..BotVersion.." Moduri:")
curUser:SendData(" ".."0 = Jocul se joaca in Chat!")
curUser:SendData(" ".."1 = Jocul se joaca in Chat dar intrebarile se vad doar de JUCATORI")
curUser:SendData(" ".."2 = Jocul se joaca in PM cu jucatori")
end
end
function TopTen(user)
local index = {n=0}
foreach(pointArray, function(nick, score) tinsert(%index, nick) end)
local func = function(a, b) return %pointArray[a] > %pointArray end
sort(index, func)
x = x or 20
if x > index.n then x = index.n end
local result = "\r\n\r\nTop "..x.." Trivia scores in this hub..\r\n Pos\t Score\t\t Nick\t\r\n"
for i = 1, x do result = result.."\r\n "..i..".\t"..pointArray[index].."\t\t"..index end
msg = result
SendToPlayers(msg)
end
i dont know why but i'v change 5 scripts of trivia but the same erro come's:
Syntax Error: attempt to index local `curUser' (a nil value)
Syntax Error: attempt to perform arithmetic on global `share' (a nil value)
can you help me pls ?
The script you posted above is Lua4. Assuming you have a recent version of PtokaX you need a Lua5 version (Lua4 can be recognised by the function DataArrival which was broken down into several routines such as ChatArrival and ToArrival, etc. in Lua5).
I'm sure there have been Lua5 trivia posted here that you will find if you look.
p.s. does anyone have the celeb table file to go with the horoscope script?
well i'm using ptokax 3.026 :D
Don't know what version PtokaX went Lua5 but the Horoscope is Lua5 so if that works you need to get sorted with a Lua5 trivia.