--- --- --- --- --- --- --- --- --- --- ---
--- MainStop v 1
--- by Herodes
--- --- --- --- --- --- --- --- --- --- ---
---- Look at the NOTES of this script
--- stops mainchat for selected users or whole profiles
--- remembers state after hub restarts..
--- protects profiles ( set the priorities correctly look at the notes below .. )
--- --- --- --- --- --- --- --- --- --- ---
--- NOTES:
--- Put this file in your scripts folder of Ptokax and then Start and Stop the Hub ...
--- Then go and open the File MainStop-Profiles.dat with Notepad.exe
--- explanation of contents follows ...
--
-- tProfiles = {
-- ["1"] = { --- this is the profile number for which the following settings apply ...
-- [1] = 1, --- [1] = 0 means no chat, no scripts commands, 1 chat, no script commands, 2 both chat and command use allowed
-- [2] = 2, --- [2] = is the priority number .. the lower the better .. ( no negative values pls ... )
-- [3] = "Operator",
-- }, --- end for the settings of profile number : "1"
-- ["0"] = {
-- [1] = 2,
-- [2] = 1,
-- [3] = "Master",
-- },
-- }
--
--- --- --- --- --- --- --- --- --- --- ---
---- !!!!! Look at the NOTES of this script !!!!!!
cmdclist = "!lschat"
cmdcstop = "!chat"
cmdchelp = "!chelp"
cmdcprof = "!cprofile"
FiletoSaveNoChatNicks = "MainStop-Nicks.dat"
FiletoSaveNoChatProfiles = "MainStop-Profiles.dat"
tUsrs = {}
function Main()
LoadFromFile(FiletoSaveNoChatNicks)
if readfrom(FiletoSaveNoChatProfiles) == nil then
tProfiles = {}
local nu = 0
for i, v in GetProfiles() do
nu = nu + 1
tProfiles[""..i..""] = { 1, nu, v }
end
tProfiles["-1"] = { 1, nu + 1, "Unregs" }
SaveToFile(FiletoSaveNoChatProfiles , tProfiles , "tProfiles")
readfrom()
end
readfrom()
LoadFromFile(FiletoSaveNoChatProfiles)
end
function UserConnected(user)
if tUsrs[user.sName] == 1 or tProfiles[""..user.iProfile..""][1] == 0 then
user:SendData("MainChatBlocker", "You cant use the mainchat for now. ...")
end
end
function DataArrival(user, data)
if strsub(data, 1,1) == "<" or "*" then
if tUsrs[user.sName] == 1 or tProfiles[""..user.iProfile..""][1] == 0 then
user:SendData("MainChatBlocker", "You cant chat in main...")
return 1
else
if tProfiles[""..user.iProfile..""][1] == 2 then
data = strsub(data, 1, -2)
s,e,cmd,args = strfind(data, "%b<>%s+(%S+)%s*(%S*)")
if cmd == cmdclist then
local msg = "\r\n - The following users are gagged in mainchat\r\n"
for nick, v in tUsrs do
msg = msg.."\t -- "..nick.."\r\n"
end
msg = msg.." - The profile permissions are as follows\r\n"
msg = msg.." - \tProfile Name\tCmds/MainChat\r\n"
local cmds, chat = "yes", "yes"
for i,v in tProfiles do
if v[1] == 0 then
cmds, chat = "no", "no"
elseif v[1] == 1 then
cmds , chat = "no", "yes"
elseif v[1] == 2 then
cmds , chat = "yes", "yes"
end
local prstr = v[3].." ("..i..")"
if strlen(prstr) < 8 then
prstr = prstr.."\t"
end
msg = msg.."\t+ "..prstr.."\t "..cmds.."/"..chat.."\r\n"
end
user:SendData("MainChatBlocker", msg)
return 1
elseif cmd == cmdcstop then
if (not args) or (strlen(args) == 0) then
user:SendData("MainChatBlocker", "Syntax Error! Please Use like : "..cmdstop.."
")
else
local usr = GetItemByName(args)
if tUsrs[usr.sName] then
tUsrs[usr.sName] = nil
usr.SendData("MainChatBlocker", GetProfileName(user.iProfile).." "..user.sName.." you are now able to chat in mainchat.")
user:SendData("MainChatBlocker", usr.sName.." now can chat in main")
else
if usr then
tUsrs[usr.sName] = 1
usr.SendData("MainChatBlocker", GetProfileName(user.iProfile).." "..user.sName.." has blocked your ability to chat in mainchat.")
user:SendData("MainChatBlocker", usr.sName.." now can't chat in main")
else
user:SendData("MainChatBlocker", "Error : "..args.." is not in the hub.")
end
end
end
SaveToFile(FiletoSaveNoChatNicks , tUsrs , "tUsrs")
elseif cmd == cmdchelp then
local msg = "\t\t--- MainChatBlocker Commands --- \r\n"
msg = msg.."][\t "..cmdclist.."\t - lists the users that are blocked\r\n"
msg = msg.."][\t "..cmdcstop.." \t - gags the mainchat of nick\r\n"
msg = msg.."][\t "..cmdchelp.."\t - shows this helpful text :P\r\n"
user:SendData(msg)
elseif cmd == cmdcprof then
if (not args) or (strlen(args) == 0) then
user:SendData("MainChatBlocker", "Syntax Error! Please Use like : "..cmdcprof.." ")
else
if args == "-1" then
if tProfiles[args][1] == 1 then
tProfiles[args][1] = 0
user:SendData("MainChatBlocker", "Normal Users now are unable to chat in mainchat")
SendToAll("MainChatBlocker", "Notice! : Normal Users now are unable to chat in mainchat")
elseif tProfiles[args][1] == 0 then
tProfiles[args][1] = 1
user:SendData("MainChatBlocker", "Normal Users now are able to chat in mainchat")
SendToAll("MainChatBlocker", "Notice: Normal Users now are able to chat in mainchat")
end
else
s,e,pr = strfind(args, "(%d+)")
pr = tonumber(pr)
if GetProfiles()[pr] then
if tProfiles[""..user.iProfile..""][2] < tProfiles[""..pr..""][2] then --- priority checking ..
if tProfiles[""..pr..""][1] == 0 then
tProfiles[""..pr..""][1] = 1
user:SendData("MainChatBlocker", GetProfileName(pr).."s now are unable to chat in mainchat")
SendToAll("MainChatBlocker", "Notice: "..GetProfileName(pr).."s now are unable to chat in mainchat")
elseif tProfiles[""..pr..""][1] == 1 then
tProfiles[""..pr..""][1] = 0
user:SendData("MainChatBlocker", GetProfileName(pr).."s now are able to chat in mainchat")
SendToAll("MainChatBlocker", "Notice: "..GetProfileName(pr).."s now are able to chat in mainchat")
end
else
user:SendData("MainChatBlocker", "Error! : You are not allowed to block the mainchat of "..GetProfileName(pr).."s")
SendToOps("MainChatBlocker", "Mr."..user.sName.." behaves stupidly ...")
end
else
user:SendData("MainChatBlocker", "There is no such profile number")
end
end
SaveToFile(FiletoSaveNoChatProfiles , tProfiles , "tProfiles")
end
end
end
end
end
end
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 format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end
function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end
lol. but i get this error
[14:13] Syntax E:\pto\scripts\MainStop_v1.lua:200: attempt to call global `readfrom' (a nil value)
Thats beacuse that is the lua 4 version, Dessamator meant it has been done.. and you have to search for the lua 5 version...