PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Conversion Requests => Topic started by: Annie on 11 August, 2009, 16:55:43

Title: Magic 8 Ball
Post by: Annie on 11 August, 2009, 16:55:43
Hiya can this script be converted to the new hub please


-- [8-Ball] - v0.21
--
-- Written by bonki 2003
--
-- ABOUT:
-- A very simple magic 8-ball implementation.
--
-- AVAILABLE COMMANDS:
-- !8-ball
--
-- If iInterval is set it even answers if somebody asks a question in main chat
-- and nobody answers after iInterval milliseconds.
--
-- CHANGELOG:
-- v0.21: Bugfix: Auto-answer is now not sent when users PM eachother
-- v0.2: Added: Auto-answer in main chat, see "available commands" for further details.
-- Added: Neat-looking tag :)
-- v0.11: Bugfix: can't remember :P
-- v0.1: Initial Version

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

sAskPhrase = "!8-ball";

iInterva = 8 * 1000;
--iInterval = nil; -- uncomment this if you don't want to use this feature

function Main()
math.randomseed(os.clock());
Bot = {
["Name"] = "8-Ball", -- Bot's name
["Email"] = "northeast.co.uk",
["Speed"] = "Sol", -- "Speed of Light" =)
["Tag"] = "<++ V:0.21,P:bonki,T:"..table.getn(aAnswers)..">",
["Descr"] = "Magic 8-Ball-Bot v0.21 written by bonki 2003",
["Share"] = 0
};
frmHub:RegBot(Bot.Name);
SetTimer(iInterval);
sBotInfo = "$MyINFO $ALL "..Bot.Name.." "..Bot.Descr..Bot.Tag.."$ $"..Bot.Speed..string.char(1).."$"..Bot.Email.."$"..Bot.Share.."$" ;
SendToAll(sBotInfo);
end

aAnswers = {
"No.",
"Yes.",
"NOOOOOOOOOOOOOOOOOOO!",
"Definitely.",
"All signs point to yes.",
"Yeah :)",
"HELL NO!",
"No way my friend!",
"Never ever.",
"As certain as death!",
"No...now go and blame bonki!",
"Don't count on it.",
"Without a doubt!",
"My reply is no.",
"You may rely on it.",
"I can't predict now, need some food first!",
"My sources say no...",
"Yes, most likely.",
"Concentrate and ask again.",
"This is very doubtful.",
"Better not tell you know ;-)",
"Couldn't read from brain. (A)bort, (R)etry, (I)gnore?_",
"I calculated the probability to 50 percent.",
"I know but I won't tell you :-)",
"Pay me and I'm gonna tell you.",
"Ask your mummy, she knows better than a stupid billard ball!",
"Are you kidding?",
"What? Sorry I haven't paid attention, ask again...",
"Huh?",
"Blah blahhh blahh...",
"You must be kidding!",
"Are you serious?",
"Haha, I like you...funny guy, you are :-)",
"Geeeeee...what a stupid question.",
"Stop doing drugs :-P",
"How could you think of such things?",
"How should I know?",
"And they say there are no stupid questions...",
"Get a life and leave me alone!",
"BLOOD SHALL COME UPON YOU!",
"TRUE NORWEGIAN BLACK METAL!!!", -- sue me!!!
"Get some money first.",
"Ask RabidWombat, he'll know for sure :-)", -- honor to whom honor is due! :-)
"W-e  a-r-e  B-o-r-g,  y-o-u  w-i-l-l  b-e  a-s-s-i-m-i-l-a-t-e-d,  R-e-s-i-s-t-a-n-c-e  i-s  f-u-t-i-l-e ! Err...I mean...No.",
};

sLastNick = nil;

function NewUserConnected(curUser)
curUser:SendData(sBotInfo);
end

OpConnected = NewUserConnected

function ChatArrival(curUser, sData)
local _, _, cmd, args = string.find(sData, "^%b<>%s+(%S+)%s*([^%|]*)%|$");
if (cmd == nil) then
return 0; end;
cmd = string.lower(cmd);
if (cmd == sAskPhrase) then
SendToAll(sData);
-- quick-check whether it COULD be a question somehow
if (string.find(string.sub(args, -3), "%?") and string.find(args, "%s+")) then
SendToAll(Bot.Name, GetRandomSentence());
else
SendToAll(Bot.Name, "I'm a magic 8-ball you fool. Ask me a question or leave me alone!");
end
return 1;
end
if (iInterval) then
if (string.find(string.sub(args, -3), "%?") and string.find(args, "%s+")) then
bQuestion = 1;
StartTimer();
else
bQuestion = nil;
StopTimer();
end
end
return 0;
end

function OnTimer()
if (bQuestion) then
SendToAll(Bot.Name, GetRandomSentence());
end
StopTimer();
end

function GetRandomSentence()
local iRnd = math.random(table.getn(aAnswers));
return aAnswers[iRnd];
end



thanks :D
Title: Re: Magic 8 Ball
Post by: ?ippe?? on 25 August, 2009, 19:05:15
Here comes the converted script.
hehe, though i don't anything about coding this script is converted to new API using the 'APIConverter'.
Tested and worked in my hub, hope it will work for you too  :).
Title: Re: Magic 8 Ball
Post by: Annie on 26 August, 2009, 09:52:55
Thank you :D.  I have added it in  but cant see no right click menu for it
Title: Re: Magic 8 Ball
Post by: TZB on 26 August, 2009, 13:19:23

-- [8-Ball] - v0.21
--
-- Written by bonki 2003
--
-- ABOUT:
-- A very simple magic 8-ball implementation.
--
-- AVAILABLE COMMANDS:
-- !8-ball
--
-- If iInterval is set it even answers if somebody asks a question in main chat
-- and nobody answers after iInterval milliseconds.
--
-- CHANGELOG:
-- v0.21: Bugfix: Auto-answer is now not sent when users PM eachother
-- v0.2: Added: Auto-answer in main chat, see "available commands" for further details.
-- Added: Neat-looking tag :)
-- v0.11: Bugfix: can't remember :P
-- v0.1: Initial Version

-- Converted to lua 5 by Madman
-- Some small changes to...
-------------------------------------------------------------------------------------------
-- New Changes
-- Converted using  PtokaX LUA API Converter v1.0 at 8/25/2009 9:59:32 PM by ?ippe??
-- Added Right click and menue option using help from mutors scripts by TZB
-- Added Profile Permissions by TZB
-------------------------------------------------------------------------------------------
-- Profile permission as per new ptokax
-------------------------------------------------------------------------------------------
tProfile = {
[-1] = 0, -- Unregistered Users
[0] = 1, -- Masters
[1] = 1, -- Operators
[2] = 1, -- VIP
[3] = 1, -- Registered
}
--------------------------------------------------------------------------------------------
-- Settings
----------------------------------------------------------------------------------------------
Menu = SetMan.GetString(21); --[Add your customed menu in " " instead of SetMan.GetString(21)]--
SubMenu = "8-Ball"; --[Use Seperator if neccessary // ]--
sAskPhrase = "!8-ball";
----------------------------------------------------------------------------------------------

iInterva = 8 * 1000;
--iInterval = nil; -- uncomment this if you don't want to use this feature

function OnStartup()
math.randomseed(os.clock());
Bot = {
["Name"] = "8-Ball", -- Bot's name
["Email"] = "northeast.co.uk",
["Speed"] = "Sol", -- "Speed of Light" =)
["Tag"] = "<++ V:0.21,P:bonki,T:"..#aAnswers..">",
["Descr"] = "Magic 8-Ball-Bot v0.21 written by bonki 2003",
["Share"] = 0
};
Core.RegBot(Bot.Name,"","",true);

sBotInfo = "$MyINFO $ALL "..Bot.Name.." "..Bot.Descr..Bot.Tag.."$ $"..Bot.Speed..string.char(1).."$"..Bot.Email.."$"..Bot.Share.."$" ;
Core.SendToAll(sBotInfo);
end

aAnswers = {
"No.",
"Yes.",
"NOOOOOOOOOOOOOOOOOOO!",
"Definitely.",
"All signs point to yes.",
"Yeah :)",
"HELL NO!",
"No way my friend!",
"Never ever.",
"As certain as death!",
"No...now go and blame bonki!",
"Don't count on it.",
"Without a doubt!",
"My reply is no.",
"You may rely on it.",
"I can't predict now, need some food first!",
"My sources say no...",
"Yes, most likely.",
"Concentrate and ask again.",
"This is very doubtful.",
"Better not tell you know ;-)",
"Couldn't read from brain. (A)bort, (R)etry, (I)gnore?_",
"I calculated the probability to 50 percent.",
"I know but I won't tell you :-)",
"Pay me and I'm gonna tell you.",
"Ask your mummy, she knows better than a stupid billard ball!",
"Are you kidding?",
"What? Sorry I haven't paid attention, ask again...",
"Huh?",
"Blah blahhh blahh...",
"You must be kidding!",
"Are you serious?",
"Haha, I like you...funny guy, you are :-)",
"Geeeeee...what a stupid question.",
"Stop doing drugs :-P",
"How could you think of such things?",
"How should I know?",
"And they say there are no stupid questions...",
"Get a life and leave me alone!",
"BLOOD SHALL COME UPON YOU!",
"TRUE NORWEGIAN BLACK METAL!!!", -- sue me!!!
"Get some money first.",
"Ask RabidWombat, he'll know for sure :-)", -- honor to whom honor is due! :-)
"W-e  a-r-e  B-o-r-g,  y-o-u  w-i-l-l  b-e  a-s-s-i-m-i-l-a-t-e-d,  R-e-s-i-s-t-a-n-c-e  i-s  f-u-t-i-l-e ! Err...I mean...No.",
};

sLastNick = nil;

function UserConnected(curUser)
Core.SendToUser(curUser,sBotInfo);
end

OpConnected = UserConnected

function ChatArrival(curUser,sData)
local _, _, cmd, args = string.find(sData, "^%b<>%s+(%S+)%s*([^%|]*)%|$");
if (cmd == nil) then
return false; end;
cmd = string.lower(cmd);
if (cmd == sAskPhrase) then
Core.SendToAll(sData);
-- quick-check whether it COULD be a question somehow
if (string.find(string.sub(args, -3), "%?") and string.find(args, "%s+")) then
Core.SendToAll("<"..Bot.Name.."> ".. GetRandomSentence());
else
Core.SendToAll("<"..Bot.Name.."> I'm a magic 8-ball you fool. Ask me a question or leave me alone!");
end
return true;
end
if (iInterval) then
if (string.find(string.sub(args, -3), "%?") and string.find(args, "%s+")) then
bQuestion = 1;
tmr = TmrMan.AddTimer(iInterval);
else
bQuestion = nil;
TmrMan.RemoveTimer(tmr);
end
end
return false;
end

function OnTimer(tmr)
if (bQuestion) then
Core.SendToAll("<"..Bot.Name.."> ".. GetRandomSentence());
end
TmrMan.RemoveTimer(tmr);
end

function GetRandomSentence()
local iRnd = math.random(#aAnswers);
return aAnswers[iRnd];
end
---------------------------------------------------------------------------------------------
--Right Click As per Profile permissions Given Above.
---------------------------------------------------------------------------------------------
RcCmds = {
{1,"$UserCommand 1 3 "..Menu.."\\"..SubMenu.."\\Ask Phrase$<%[mynick]> "..sAskPhrase.." %[line:Message] &#124;|"},
}

UserConnected = function(user)
local lvl,x = tProfile[user.iProfile],""
if lvl then
for i,v in ipairs(RcCmds) do if lvl >= v[1] then x = x..v[2] end end
if #x > 0 then Core.SendToUser(user,x) end
collectgarbage("collect")
end
end
RegConnected,OpConnected = UserConnected,UserConnected


I suppose it should do the needful haven't tested in details just added few things. Sorry for any credits mistakes please do notify if anythings missed out.
Title: Re: Magic 8 Ball
Post by: Annie on 26 August, 2009, 14:03:42
Ive added the box in the right click to add a question


{1,"$UserCommand 1 3 "..Menu.."\\"..SubMenu.."\\Ask Phrase$<%[mynick]> "..sAskPhrase.." %[line:Message] &#124;|"},


;D

Thank you ?ippe?? and TZB   ;D  Im going to play with it now   ;D ;D ;D ;D
Title: Re: Magic 8 Ball
Post by: TZB on 26 August, 2009, 14:34:57
:P Had no idea it required a box.Never used this script :P
Thanks anyways Script updated.