PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: Genius on 30 April, 2005, 18:36:13

Title: rules script
Post by: Genius on 30 April, 2005, 18:36:13
Hi evryone
I nedd a script for users see the rules typing !regras
Sory my bad inglish
Title:
Post by: jiten on 30 April, 2005, 19:12:29
Here you go (not tested):
-- rules by jiten

sConf = {
sBot = frmHub:GetHubBotName(),
sFile1 = "file1.txt",
}

function Main()
frmHub:RegBot(sConf.sBot)
end

function ChatArrival(user,data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find (data, "%b<>%s+[%!%?%+%#](%S+)" )
if cmd then
local tCmds = {
["regras"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile1))
end,
}
if tCmds[cmd] then
return tCmds[cmd](user,data), 1
end
end
end

function ReadFile(file)
local fFile = io.open(file)
if fFile then
local message = ""
for line in io.lines(file) do
message = message..line.."\n"
end
fFile:close()
return message
else
return file.." not found!"
end
end

Cheers
Title:
Post by: Genius on 01 May, 2005, 04:45:26
Hi

Tank you

The script its working :)
Tankx again
Title:
Post by: jiten on 01 May, 2005, 11:28:16
yw :]
Title:
Post by: chettedeboeuf on 01 May, 2005, 14:53:23
Merci pour le script
Title:
Post by: dkt on 17 May, 2005, 13:34:32
hi jiten,
nice script..
but i need to know who uses the script in the hub i.e the name of the user using the command and also what command he i using to be displayed in main chat...the current above script doesnt show the command in main chat

for eg :- i want the below to be displayed in main chat

!regras

is it possible..

also the text file is read in pm...
can we read tat file in main chat and a option in it..for the file to be viewed by you only or by all others in main chat ...

waiting for your reply .
Title:
Post by: Dessamator on 17 May, 2005, 14:21:19
-- rules by jiten

sConf = {
sBot = frmHub:GetHubBotName(),
sFile1 = "file1.txt",
ShowAll = true -- true/false to show all
}

function Main()
frmHub:RegBot(sConf.sBot)
end

function ChatArrival(user,data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find (data, "%b<>%s+[%!%?%+%#](%S+)" )
if cmd then
local tCmds = {
["regras"] = function(user,data)
if sConf.ShowAll then
SendToAll(sConf.sBot,ReadFile(sConf.sFile1))
else
user:SendData(sConf.sBot,ReadFile(sConf.sFile1))
end
end,
}
if tCmds[cmd] then
tCmds[cmd](user,data)
end
end
end

function ReadFile(file)
local fFile = io.open(file)
if fFile then
local message = ""
for line in io.lines(file) do
message = message..line.."\n"
end
fFile:close()
return message
else
return file.." not found!"
end
end


Done !
Title:
Post by: jiten on 17 May, 2005, 14:29:11
Something like this? Have a look at Rotating Message. It may be more useful for you.
-- rules by jiten
-- Added option to send .txt to Main/PM/All

sConf = {
sBot = frmHub:GetHubBotName(),
sFile1 = "file1.txt",
sView = 0 -- 0: Rules in PM; 1: Rules in Main; 2: Rules sent to everyone
}

function Main()
frmHub:RegBot(sConf.sBot)
end

function ChatArrival(user,data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find (data, "%b<>%s+[%!%?%+%#](%S+)" )
if cmd then
local tCmds = {
["regras"] = function(user,data)
if sConf.sView == 0 then
user:SendPM(sConf.sBot,ReadFile(sConf.sFile1))
elseif sConf.sView == 1 then
user:SendData(sConf.sBot,ReadFile(sConf.sFile1))
else
SendToAll(sConf.sBot,ReadFile(sConf.sFile1))
end
end,
}
if tCmds[cmd] then return tCmds[cmd](user,data) end
end
end

function ReadFile(file)
local fFile = io.open(file)
if fFile then
local message = ""
for line in io.lines(file) do
message = message..line.."\n"
end
fFile:close()
return message
else
return file.." not found!"
end
end
Cheers