Quote-- regonly by bastya_elvtars
-- requested by aL1en
-- sorry 4 possible bugs, cannot test it and forgot lua a bit :)
-- disconnects unreg users if hub is set private
-- well, here is an array that contains allowed ppl. this is the safest.
-- command prefixes: + ! # ? (as usual)
-- ptokax>advanced>registered users only must be unmarked ;)
-- enjoy
-- // settings
userswhocansetregonly={ -- ppl who are allowed to use it
"aL1en",
}
-- the bot1s name:
Bot="TheKEY"
--- // end of settings, do not edit below
regO={}
regonly=0 -- for safety only
dofile("regonly.ini") -- loads settings
function Main() -- loads on script start
for b=1,getn(userswhocansetregonly) do
regO[userswhocansetregonly]=1 -- makes a metatable to use l8r
end
end
function NewUserConnected(user) -- user connects
if regonly==1 then
if user.iProfile==-1 then
user:SendData(Bot,"This hub is for registered users only.")
user:Disconnect()
end
end
end
function DataArrival(user,data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd=strfind(data,"%b<>%s+[%+%!%#%?](%S+)")
if cmd=="private" then
if regO[user.sName] then
if regonly~=1 then
regonly=1
save()
user:SendData(Bot,"Hub is now private.")
else
user:SendData(Bot,"Hub is already private.")
end
else
user:SendData(Bot,"You are not allowed to use this command.")
end
elseif cmd=="public" then
if regO[user.sName] then
if regonly~=0 then
regonly=0
save()
user:SendData(Bot,"Hub is now public.")
else
user:SendData(Bot,"Hub is already public.")
end
else
user:SendData(Bot,"You are not allowed to use this command.")
end
end
end
end
function save()
writeto("regonly.ini")
write("regonly="..regonly)
writeto()
end
Hi, here we go:
A. First you need to make a file called "regonly.dat" and put that in the scripts folder!
B. The table in this file should be this (copy paste this in the file "regonly.dat"):Setting = {
["regonly"] = 1,
}
C. This is the script u asked for (have fun), please report bugs:-----------------------------------------------------------------------------
-- regonly by bastya_elvtars
-- requested by aL1en
-----------------------------------------------------------------------------
-- Changed to LUA5 on request by TTB (30-07-05)
-- Table in txt is serialized... ow my, I love that function!
-----------------------------------------------------------------------------
-- sorry 4 possible bugs, cannot test it and forgot lua a bit :)
-- disconnects unreg users if hub is set private
-- well, here is an array that contains allowed ppl. this is the safest.
-- command prefixes: + ! # ? (as usual)
-- ptokax>advanced>registered users only must be unmarked ;)
-- enjoy
-----------------------------------------------------------------------------
-- // settings
-->> Who can reg set the regonly?
userswhocansetregonly={
"aL1en",
"[SU]TTB",
}
-->> What is the name of your bot?
Bot="TheKEY"
-->> What is the filename of the settings?
file = "regonly.dat"
--- // end of settings, do not edit below
regO={}
function Main() -- loads on script start
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
else
SendToAll(Bot, "The file: "..file.." has not been found in the scripts folder!")
end
for b=1,table.getn(userswhocansetregonly) do
regO[userswhocansetregonly[b]]=1 -- makes a metatable to use l8r
end
end
function NewUserConnected(user) -- user connects
if Setting["regonly"] == 1 then
if user.iProfile==-1 then
user:SendData(Bot,"This hub is for registered users only.")
user:Disconnect()
end
end
end
function ChatArrival(user,data)
mijntabel = "Setting"
data = string.sub(data,1,string.len(data)-1)
local _,_,cmd=string.find(data,"%b<>%s+[%+%!%#%?](%S+)")
if cmd=="private" then
if regO[user.sName] then
if Setting["regonly"] ~=1 then
Setting["regonly"] = 1
WriteFile(Setting,mijntabel,file)
user:SendData(Bot,"Hub is now private.")
else
user:SendData(Bot,"Hub is already private.")
end
else
user:SendData(Bot,"You are not allowed to use this command.")
end
return 1
elseif cmd=="public" then
if regO[user.sName] then
if Setting["regonly"] ~= 0 then
Setting["regonly"] = 0
WriteFile(Setting,mijntabel,file)
user:SendData(Bot,"Hub is now public.")
else
user:SendData(Bot,"Hub is already public.")
end
else
user:SendData(Bot,"You are not allowed to use this command.")
end
return 1
end
end
function Serialize(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(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
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
hFile:write(sTab.."}");
end
function WriteFile(table, tablename, file)
local handle = io.open(file, "w")
Serialize(table, tablename, handle)
handle:close()
end
thanks TTB ;)
YW! :D