Author Topic: Help needed to convert [8-Ball] 1.03 - LUA 5.0/5.1 version by jiten  (Read 1634 times)

0 Members and 1 Guest are viewing this topic.

Offline miago

  • Fulll Member
  • ****
  • Posts: 57
  • Karma: +2/-0
  • QueenBiatch, SuperBiatch or PsychoBiatch :)
Hiya.

Since we are kinda childish in our hub I rly would like this script to get converted.  ;D
There are some lines in swedish, but not in the coding part, only for the answers and RCmenu, hope thats ok.

Regards
miago

Code: [Select]
--[[

[8-Ball] 1.03 - LUA 5.0/5.1 version by jiten

Based: on Bonki's [8-Ball]

Changelog:

- Converted to lua 5 by Madman
- Some small changes to...
- Converted to lua 5.1 by TT

- Rewritten: Code structure;
- Added: add/del/show support - Requested by TT
- Fixed: Rightclick Prefix - thanks to TT
- Added: _VERSION - reported by Alexinno;
- Removed: Unnecessary timer and randomseed stuff - thanks to Mutor;
- Added: Check for existing 'to' - thanks to Mutor (6/18/2006)

]]--

tBall = {
sName = "8?@LL",
sAskPhrase = "8ball",
sFile = "tBall.tbl",
sAnswers = {
"Nej.",
"Ja.",
"NEEEEEEEJJJJJJJJJJJJJJJJJJJJJJ!",
"Helt klart!",
"Alla tecken tyder p? ett ja.",
"Yeah :)",
"HELLSKOTTA NEJ!!",
"Inte en chans min v?n!",
"Aldrig n?gonsin.",
"Lika s?kert som att d?den kommer!",
"Nej...g? nu och gn?ll p? bonki!",
"R?kna inte med det.",
"Utan tvekan!",
"Mitt svar ?r nej.",
"Du kan lita p? det.",
"Jag kan inte f?rutsp? det nu, beh?ver ?ta f?rst!",
"Mina k?llor s?ger nej...",
"Jo, n?stan s?kert.",
"Koncentrera dig och fr?ga igen.",
"V?ldigt tveksamt.",
"Better not tell you know ;-)",
"Jag r?knade ut att m?jligheten ?r 50 procent.",
"Jag vet, men jag t?nker inte ber?tta f?r dig :-)",
"Betala mig s? ska jag ber?tta f?r dig.",
"Fr?ga din mammsing, hon vet b?ttre !",
"Skojar du???",
"Va? Jag ?r lessen, har inte m?rkt n?got h?r, fr?ga igen...",
"Hmmm?",
"Blah blahhh blahh...",
"Du m?ste sk?mta!",
"?r du allvarlig?",
"Haha, jag gillar dig....rolig typ du :-)",
"Herreminjeee...vilken dum fr?ga.",
"Sluta med drogerna :-P",
"Hur kan du ens t?nka p? s?na saker?",
"Hur ska jag kunna veta?",
"Och dom s?ger att det inte finns n?gra dumma fr?gor...",
"Skaffa ett liv och l?mna mig ifred!",
"H?mta pengar f?rst.",
"Fr?ga TiMeTrAVelleR, han vet nog med s?kerhet :-)",
"Ja...ehh jag menar...Nej.",
}
}

Main = function()
getn = table.getn; if _VERSION == "Lua 5.1" then getn = table.maxn end
if loadfile(tBall.sFile) then dofile(tBall.sFile) end
end

ChatArrival = function(user,data)
local s,e,to = string.find(data,"^$To:%s(%S+)%s+From:")
local s,e,cmd = string.find(data,"%b<>%s(%S+).*|$")
if cmd then
if tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
if to and to == tBall.sName then user.SendMessage = user.SendPM else user.SendMessage = user.SendPM end
if tCommands[cmd].tLevels[user.iProfile] then
return tCommands[cmd].tFunc(user,data), 1
end
end
end
end

ToArrival = ChatArrival

NewUserConnected = function(user)
if user.bUserCommand then
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] then
local sRC = string.gsub(v.tRC,"{}",i)
user:SendData("$UserCommand 1 3 - FunStuff -\\- Other -\\- 8Ball -\\"..sRC.."&#124;")
end
end
end
end

OpConnected = NewUserConnected

tCommands = {
["!8add"] = {
tFunc = function(user,data)
local s,e,args = string.find(data,"^%b<>%s+%S+%s+(.+)|$")
if args then
table.insert(tBall.sAnswers,args); SaveToFile(tBall.sFile,tBall.sAnswers,"tBall.sAnswers")
user:SendMessage(tBall.sName,"*** "..args.." has been successfully added to 8Ball's Answer list!")
else
user:SendMessage(tBall.sName,"*** Syntax Error: Type !8add <answer>")
end
end,
tLevels = {
[0] = 1, [1] = 1, [4] = 1, [5] = 1,
},
sDesc = "\t\tL?gg till ett 8Ball svar",
tRC = "L?gg till ett 8Ball svar$<%[mynick]> {} %[line:Answer]"
},
["!8del"] = {
tFunc = function(user,data)
local s,e,ID = string.find(data,"^%b<>%s+%S+%s+(%d+)|$")
if ID then
if tBall.sAnswers[tonumber(ID)] then
user:SendMessage(tBall.sName,"*** "..tBall.sAnswers[tonumber(ID)].." has been successfully "..
"deleted from 8Ball's Answer list")
table.remove(tBall.sAnswers,ID); SaveToFile(tBall.sFile,tBall.sAnswers,"tBall.sAnswers")
else
user:SendMessage(tBall.sName,"*** Error: There is no ID "..ID.." in 8Ball's Answer list!")
end
else
user:SendMessage(tBall.sName,"*** Syntax Error: Type !8del <ID>")
end
end,
tLevels = {
[0] = 1, [5] = 1,
},
sDesc = "\t\tTa bort ett specifikt 8Ball svar",
tRC = "Ta bort ett 8Ball svar$<%[mynick]> {} %[line:ID]"
},
["!8show"] = {
tFunc = function(user)
if next(tBall.sAnswers) then
local sMsg = "\r\n\t"..string.rep("=",105).."\r\n\tID.\tAnswer:\r\n\t"..
string.rep("-",210).."\r\n"
for i in ipairs(tBall.sAnswers) do
sMsg = sMsg.."\t"..i..".\t"..tBall.sAnswers[i].."\r\n"
end
user:SendMessage(tBall.sName,sMsg)
else
user:SendMessage(tBall.sName,"*** Error: There are no saved 8Ball answers!")
end
end,
tLevels = {
[0] = 1, [1] = 1, [4] = 1, [5] = 1,
},
sDesc = "\t\tVisa alla 8Ball svar",
tRC = "Visa alla 8Ball svar$<%[mynick]> {}"
},
["8ball"] = {
tFunc = function(user, data)
local _,_,args = string.find(data,"^%b<>%s+%S+%s*([^%|]*)%|$"); SendToAll(data);
-- quick-check whether it COULD be a question somehow
if string.find(string.sub(args,-3),"%?") and string.find(args,"%s+") then
SendToAll(tBall.sName,tBall.sAnswers[math.random(getn(tBall.sAnswers))]);
else
SendToAll(tBall.sName,"Jaa?");
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
sDesc = "\t\tSt?ll en fr?ga till "..tBall.sName.."med ? p? slutet",
tRC = "St?ll en fr?ga med ? p? slutet$<%[mynick]> {} %[line:Question]"
},
["!8help"] = {
tFunc = function(user)
local sMsg = "\r\n\t\t"..string.rep("=",75).."\r\n"..string.rep("\t",6).."8Ball by Bonki"..
"\r\n\t\t"..string.rep("-",150).."\r\n\t\tAvailable Commands:".."\r\n\r\n"
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] then
sMsg = sMsg.."\t\t"..i.."\t\t"..v.sDesc.."\r\n"
end
end
user:SendMessage(tBall.sName, sMsg.."\t\t"..string.rep("-",150));
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
sDesc = "\t\tVisa hj?lpmeddelande",
tRC = "Visa kommandon$<%[mynick]> {}"
},
}

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in pairs(tTable) do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
end
hFile:write(sTab.."}");
end

SaveToFile = function(file,table,tablename)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
end
Being a biatch aint easy ;)

PtokaX forum