PtokaX forum

Archive => Archived 5.1 boards => Request for scripts => Topic started by: speedX on 06 October, 2006, 19:10:54

Title: Area's and Places
Post by: speedX on 06 October, 2006, 19:10:54
hello,
In my hub i would like introduce a script wich would save the name of the area where tht particular user lives....a command for eg: !addarea <nick> <area>  would be fine........this would be saved in the database..

Result of the command....
I would like any of the following two results...
1) The area where tht particular user lives would come in his description...

2) when any user type's....for eg: +bombay  thn all the people living in bombay would be displayed to all along wid the command but not the result....
-----------------------------------------------------------------------------------------

Hope i have not confused you'll....as i tried my best to describe my request........plzz post ur doubts if u r not clear about my request......thank u........

Title: Re: Area's and Places
Post by: Thor on 06 October, 2006, 22:06:30
What this script do:
!addarea <nick> <area> - to add
!delarea <nick> - to del
!listareas - to list
!listareas <area> - to list given area (what you asked as +bombay)
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.
]]
function Main()
sBot = frmHub:GetHubBotName() -- The botname who send us the messages
tAllowedUsers={  -- those users who can use the script
[-1] = 0, -- Unregistered users
[0] = 1, -- Master users
[1] = 1, -- Operator users
[2] = 1, -- VIP users
[3] = 1, -- Registered users
[4] = 1, -- Moderator users (RoboCop)
[5] = 1, -- NetFounder users (RoboCop)
[6] = 1, -- Owner users (Levithian)
}
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[nick] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
SetTimer(60000) -- Update the MyINFO-s in every minute
StartTimer() -- start the timer

end

function ChatArrival(curUser,data)
if tAllowedUsers[curUser.iProfile] == 1 then
local _,_,data = string.find(data,"%b<>%s*(.*)|")
local _,_,command = string.find(data,"%p(%S+)")
if command then
if command == "addarea" then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(.*)")
if nick then
tUserAreas[nick] = area
curUser:SendData(sBot,nick.." successfully added to the database with area "..area)
else
curUser:SendData(sBot,"Usage: !addarea <nick> <area>")
end
return 1
elseif command == "listareas" then
local _,_,opt = string.find(data,"%p%S+%s*(.*)")
if opt == "" then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
curUser:SendData(sBot,"The database is empty yet...")
else
curUser:SendData(sBot,msg)
end
else
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if tUserAreas[k] == opt then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
curUser:SendData(sBot,"Check your syntax! There is nobody from "..opt)
else
curUser:SendData(sBot,msg)
end
end
return 1
elseif command == "delarea" then
local _,_,nick = string.find(data,"%p%S+%s*(%S*)")
if tUserAreas[nick] then
tUserAreas[nick] = nil
curUser:SendData(sBot,nick.." has been successfully deleted from the database.")
else
curUser:SendData(sBot,"This user is not in my database, please check your syntax. Use the !listareas command")
end
return 1
end
end
end
end

function ToArrival(curUser,data)
local _,_,nickto = string.find(data, "^%$To:%s(%S+)")
if nickto == sBot then
ChatArrival(curUser,data)
end
end

function NewUserConnected(curUser)
if tAllowedUsers[curUser.iProfile] == 1 then
if tUserAreas[curUser.sName] then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\You are now from "..tUserAreas[curUser.sName].."$<%[mynick]> !addarea "..curUser.sName.." %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\If you want to change this, click here$<%[mynick]> !addarea "..curUser.sName.." %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 0 3")
else
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add yourself to the database$<%[mynick]> !addarea "..curUser.sName.." %[line:Your area:]&#124;|")
end
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete a user$<%[mynick]> !delarea %[line:Nick to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from database$<%[mynick]> !listareas&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from the given area$<%[mynick]> !listareas %[line:From where:]&#124;|")
end
end
OpConnected = NewUserConnected

function OnTimer()
for i,v in ipairs(frmHub:GetOnlineUsers()) do
if tUserAreas[v.sName] then
local myinfo = "$MyINFO $ALL "..v.sName.." "..tUserAreas[v.sName].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte).."$"..(v.sEmail or "").."$"..v.iShareSize.."$"
SendToAll(myinfo)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
end

And refresh the MyINFOs in every minutes. Bugreports and featurerequests are always welcomed
Title: Re: Area's and Places
Post by: speedX on 06 October, 2006, 22:25:54
excellent, marvellous, gr8 ..........thank u Hungarista for ur help......

I had one last request......can u make tht !addarea !delarea and !listareas available to masters only.....i would like only 1 command for reg users and VIp's tht they can use !listareas <area> ..........thank u...

And could u modify it in such a way tht !listareas and !listareas <area> comes in PM

No bugs Found......script is working gr8.....
Title: Re: Area's and Places
Post by: Thor on 06 October, 2006, 23:30:30
Here is it:
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.
]]
function Main()
sBot = frmHub:GetHubBotName() -- The botname who send us the messages
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[nick] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
SetTimer(60000) -- Update the MyINFO-s in every minute
StartTimer() -- start the timer

end

function ChatArrival(curUser,data)
local _,_,data = string.find(data,"%b<>%s*(.*)|")
local _,_,command = string.find(data,"%p(%S+)")
if command then
if command == "addarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(.*)")
if nick then
tUserAreas[nick] = area
curUser:SendData(sBot,nick.." successfully added to the database with area "..area)
else
curUser:SendData(sBot,"Usage: !addarea <nick> <area>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "listareas" then
local _,_,opt = string.find(data,"%p%S+%s*(.*)")
if opt == "" then
if curUser.iProfile == 0 then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
curUser:SendPM(sBot,"The database is empty yet...")
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
else
if curUser.iProfile == 2 or curUser.bOperator then
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if tUserAreas[k] == opt then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
curUser:SendPM(sBot,"Check your syntax! There is nobody from "..opt)
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
end
return 1
elseif command == "delarea" then
if curUser.iProfile == 0 then
local _,_,nick = string.find(data,"%p%S+%s*(%S*)")
if tUserAreas[nick] then
tUserAreas[nick] = nil
curUser:SendData(sBot,nick.." has been successfully deleted from the database.")
else
curUser:SendData(sBot,"This user is not in my database, please check your syntax. Use the !listareas command")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
end
end
end

function ToArrival(curUser,data)
local _,_,nickto = string.find(data, "^%$To:%s(%S+)")
if nickto == sBot then
ChatArrival(curUser,data)
end
end

function NewUserConnected(curUser)
if curUser.iProfile == 0 then
if tUserAreas[curUser.sName] then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\You are now from "..tUserAreas[curUser.sName].."$<%[mynick]> !addarea "..curUser.sName.." %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\If you want to change this, click here$<%[mynick]> !addarea "..curUser.sName.." %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 0 3")
else
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add yourself to the database$<%[mynick]> !addarea "..curUser.sName.." %[line:Your area:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete a user$<%[mynick]> !delarea %[line:Nick to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from database$<%[mynick]> !listareas&#124;|")
end
end
if curUser.iProfile == 2 or curUser.bOperator then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from the given area$<%[mynick]> !listareas %[line:From where:]&#124;|")
end
end
OpConnected = NewUserConnected

function OnTimer()
for i,v in ipairs(frmHub:GetOnlineUsers()) do
if tUserAreas[v.sName] then
local myinfo = "$MyINFO $ALL "..v.sName.." "..tUserAreas[v.sName].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte).."$"..(v.sEmail or "").."$"..v.iShareSize.."$"
SendToAll(myinfo)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
end
Title: Re: Area's and Places
Post by: speedX on 07 October, 2006, 06:44:33
hey thx hungarista....the script works gr8....but need one more addition.....
When a master add's someone with area Rabodi........and a user type !listareas rabodi ...he doesnt get the result....can u make it for lower case also......thank u...

and u add one more command for changing a user's area....
eg: !chgarea <nick> <newarea>   --------------> Only for masters......

Title: Re: Area's and Places
Post by: Thor on 07 October, 2006, 07:44:44
Hehe, first bug found :D The string.lower() request is totally right. New feature added:
+chgarea <nick> <new_area> - to modify an existing area
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.
]]
function Main()
sBot = frmHub:GetHubBotName() -- The botname who send us the messages
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[nick] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
SetTimer(60000) -- Update the MyINFO-s in every minute
StartTimer() -- start the timer

end

function ChatArrival(curUser,data)
local _,_,data = string.find(data,"%b<>%s*(.*)|")
local _,_,command = string.find(data,"%p(%S+)")
if command then
if command == "addarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(.*)")
if nick then
if tUserAreas[nick] then
curUser:SendData(sBot,nick.." is already in the database from "..area)
else
tUserAreas[nick] = area
curUser:SendData(sBot,nick.." has been successfully added to the database with area "..area)
end
else
curUser:SendData(sBot,"Usage: !addarea <nick> <area>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "chgarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(.*)")
if nick then
if not tUserAreas[nick] then
curUser:SendData(sBot,nick.." is not in the database, so you can't change his/her area.")
else
tUserAreas[nick] = area
curUser:SendData(sBot,nick.." has been successfully modified in the database with new area: "..area)
end
else
curUser:SendData(sBot,"Usage: !addarea <nick> <area>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "listareas" then
local _,_,opt = string.find(data,"%p%S+%s*(.*)")
if opt == "" then
if curUser.iProfile == 0 then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
curUser:SendPM(sBot,"The database is empty yet...")
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
else
if curUser.iProfile == 2 or curUser.bOperator then
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if string.lower(tUserAreas[k]) == string.lower(opt) then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
curUser:SendPM(sBot,"Check your syntax! There is nobody from "..opt)
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
end
return 1
elseif command == "delarea" then
if curUser.iProfile == 0 then
local _,_,nick = string.find(data,"%p%S+%s*(%S*)")
if tUserAreas[nick] then
tUserAreas[nick] = nil
curUser:SendData(sBot,nick.." has been successfully deleted from the database.")
else
curUser:SendData(sBot,"This user is not in my database, please check your syntax. Use the !listareas command")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
end
end
end

function ToArrival(curUser,data)
local _,_,nickto = string.find(data, "^%$To:%s(%S+)")
if nickto == sBot then
ChatArrival(curUser,data)
end
end

function NewUserConnected(curUser)
if curUser.iProfile == 0 then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add a new value$<%[mynick]> !addarea "..curUser.sName.." %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Modify an existing value$<%[mynick]> !chgarea %[line:Nick:] %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 0 3")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete a user$<%[mynick]> !delarea %[line:Nick to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from database$<%[mynick]> !listareas&#124;|")
end
if curUser.iProfile == 2 or curUser.bOperator then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from the given area$<%[mynick]> !listareas %[line:From where:]&#124;|")
end
end
OpConnected = NewUserConnected

function OnTimer()
for i,v in ipairs(frmHub:GetOnlineUsers()) do
if tUserAreas[v.sName] then
local myinfo = "$MyINFO $ALL "..v.sName.." "..tUserAreas[v.sName].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte).."$"..(v.sEmail or "").."$"..v.iShareSize.."$"
SendToAll(myinfo)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
end
Title: Re: Area's and Places
Post by: speedX on 07 October, 2006, 07:49:42
When they type !showareas ------> only for masters and op's
all the areas will come wich have been added in the script.....(i think for a .tbl shud be created)

1 = Delhi
2 = Rabodi
3 = MP

so tht the op or master who uses !addarea command wouldn't have to type to full name again and again...like

!addarea speedx 2

this user's area will be saved as Rabodi....

and if there is some other area wich is not saved in tht .tbl file......thn a message will appear to tht particular op....tht contact "user" to add tht area into the list or check whether u have entered wrong command......

some thing like tht.....

Is it possible??
Title: Re: Area's and Places
Post by: Thor on 07 October, 2006, 07:56:48
Hmmz, now just masters can add new value to the database. If they can add just the existing values, who will add that values to the database? Maybe netfounders? Or just you? Please explain this to me.
Quote from: speedX on 07 October, 2006, 07:49:42
Is it possible??
There is no impossible...
Title: Re: Area's and Places
Post by: speedX on 07 October, 2006, 08:05:54
!addarea ---->> will be used by op's and masters....

if there are 5 values in the database......and there is a new 6 th one wich has not been added.....so tht op will report to me tht "this area" is not there in the database and there is one user who lives there.....
Then later in the evening......i'll add tht area to the database (.tbl) manually.......

Or if it possible thn a command would be better like !areaaddition <no.> <area name>
Title: Re: Area's and Places
Post by: Thor on 10 October, 2006, 14:49:24
Endly i did it, not too many tested, but i think it works well (I was busy with a Verli script).
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.
]]
function Main()
sBot = frmHub:GetHubBotName() -- The botname who send us the messages
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[nick] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
local file2 = io.open("userareas.tbl", "r")
if (file2) then
tAreas = {}
local line = file2:read()
while line do
local _,_,area = string.find(line,"(.*)")
table.insert(tAreas,area)
line = file2:read()
end
file2:close()
table.sort(tAreas,  function(a,b) return a<b end)
else
tAreas = {}
end
SetTimer(60000) -- Update the MyINFO-s in every minute
StartTimer() -- start the timer

end

function ChatArrival(curUser,data)
local _,_,data = string.find(data,"%b<>%s*(.*)|")
local _,_,command = string.find(data,"%p(%S+)")
if command then
if command == "areaadd" then
if curUser.iProfile == 0 then
local _,_,area = string.find(data,"%p%S+%s*(.*)")
for i in ipairs(tAreas) do
if string.lower(tAreas[i]) == string.lower(area) then
bIsExist = true
end
end
if bIsExist then
curUser:SendData(sBot,"This value is still in the database.")
bIsExist = nil
else
area = string.gsub(area," ","_")
table.insert(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
curUser:SendData(sBot,area.." has been successfully added to the database with index "..table.getn(tAreas))
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "areadel" then
if curUser.iProfile == 0 then
local _,_,area = string.find(data,"%p%S+%s*(%d+)")
if area then
if tonumber(area) <= table.getn(tAreas) then
curUser:SendData(sBot,tAreas[tonumber(area)].." has been successfully deleted from the list.")
table.remove(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
bIsExist = nil
else
curUser:SendData(sBot,"There is no area with index '"..area.."' on the list. Use the !arealist command.")
end
else
curUser:SendData(sBot,"Usage: !areadel <index>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "arealist" then
if curUser.iProfile == 0 then
local msg = "Currently avaible areas are:\r\n"
for i in ipairs(tAreas) do
msg = msg..i.." - "..tAreas[i].."\r\n"
end
if msg == "Currently avaible areas are:\r\n" then msg = "The list is empty." end
curUser:SendPM(sBot,msg)
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "addarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(%d+)")
if nick then
if tUserAreas[nick] then
curUser:SendData(sBot,nick.." is already in the database from "..tUserAreas[nick])
else
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[nick] = tAreas[tonumber(area)]
curUser:SendData(sBot,nick.." has been successfully added to the database "..
"with area "..tAreas[tonumber(area)])
else
curUser:SendData(sBot,"Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command.")
end
end
else
curUser:SendData(sBot,"Usage: !addarea <nick> <areaindex>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "delarea" then
if curUser.iProfile == 0 then
local _,_,nick = string.find(data,"%p%S+%s*(%S*)")
if tUserAreas[nick] then
tUserAreas[nick] = nil
curUser:SendData(sBot,nick.." has been successfully deleted from the database.")
else
curUser:SendData(sBot,"This user is not in my database, please check your syntax. Use the !listareas command")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "chgarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(%d+)")
if nick then
if not tUserAreas[nick] then
curUser:SendData(sBot,nick.." is not in the database, so you can't change his/her area.")
else
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[nick] = tAreas[area]
curUser:SendData(sBot,nick.." has been successfully modified in the database with new area: "..tAreas[tonumber(area)])
else
curUser:SendData(sBot,"Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command.")
end
end
else
curUser:SendData(sBot,"Usage: !addarea <nick> <area>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "listareas" then
local _,_,opt = string.find(data,"%p%S+%s*(.*)")
if opt == "" then
if curUser.iProfile == 0 then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
curUser:SendPM(sBot,"The database is empty yet...")
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
else
if curUser.iProfile == 2 or curUser.bOperator then
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if string.lower(tUserAreas[k]) == string.lower(opt) then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
curUser:SendPM(sBot,"Check your syntax! There is nobody from "..opt)
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
end
return 1
end
end
end

function ToArrival(curUser,data)
local _,_,nickto = string.find(data, "^%$To:%s(%S+)")
if nickto == sBot then
ChatArrival(curUser,data)
end
end

function NewUserConnected(curUser)
if curUser.iProfile == 0 then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add a new area$<%[mynick]> !areaadd %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete area$<%[mynick]> !areadel %[line:Area to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List avaible areas$<%[mynick]> !arealist&#124;|")
curUser:SendData("$UserCommand 0 3")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add a new user to the db.$<%[mynick]> !addarea %[line:Nick:] %[line:area index:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Modify an existing user$<%[mynick]> !chgarea %[line:Nick:] %[line:New area index:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete a user$<%[mynick]> !delarea %[line:Nick to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from database$<%[mynick]> !listareas&#124;|")
end
if curUser.iProfile == 2 or curUser.bOperator then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from the given area$<%[mynick]> !listareas %[line:From where:]&#124;|")
end
end
OpConnected = NewUserConnected

function OnTimer()
for i,v in ipairs(frmHub:GetOnlineUsers()) do
if tUserAreas[v.sName] then
local myinfo = "$MyINFO $ALL "..v.sName.." "..tUserAreas[v.sName].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte).."$"..(v.sEmail or "").."$"..v.iShareSize.."$"
SendToAll(myinfo)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
local file2 = io.open("userareas.tbl", "w")
if file2 then
for index, value in ipairs(tAreas) do
file2:write(value.."\r\n")
end
end
file2:close()
end

I see now, it requested in LUA5.11, so please convert it into it first.
New commands are:
Quote!areaadd <area>
!areadel <area_index>
!arealist
Areas will be sorted always in ABC order.
Others:
Quote!addarea <nick> <area_index>
!chgarea <nick> <new_area_index>
!delarea <nick>
!listarea <where>
!listarea
Use the rightclick menu, or rewrite command names if you think they're difficult.
Title: Re: Area's and Places
Post by: speedX on 10 October, 2006, 15:11:15
Quote from: Hungarista on 06 October, 2006, 22:06:30
And refresh the MyINFOs in every minutes.

Wat do u mean by this..??wat i have to do??

and i tried to convert it to Lua 5.1 by Mutor's app.  but still not workin....i dont kno the other method.......



And 1 last addition......When a operator or master add's a user to db thn tht user shud be already regged in tht hub......i tried to add a user to db who is not regged..and he got added.....so could plzz make this change.....and is it possible to kno how many users r remaining to add to db frm the regged users?? plzz add it if possible...thank u.....
Title: Re: Area's and Places
Post by: Thor on 10 October, 2006, 20:11:56
The first part of your message is clean to me, but the second one... :-\
Quote from: speedX on 10 October, 2006, 15:11:15
and is it possible to kno how many users r remaining to add to db frm the regged users?? plzz add it if possible...thank u.....
You want to know how many users in the database? Or what? Please explain this to me.
Quote from: speedX on 10 October, 2006, 15:11:15
Quote from: Hungarista on 06 October, 2006, 22:06:30
And refresh the MyINFOs in every minutes.
Wat do u mean by this..??wat i have to do??
You don't need to do anything. You requested to show the place in the users description, so I had to use a timer, and on every minute had to send to all users on the hub the new myinfo-string.
Title: Re: Area's and Places
Post by: speedX on 10 October, 2006, 20:23:55
kk....my first part tht could u plzz convert it to Lua 5.1 coz i dont kno how to do it......

My second part:
1) Suppose there r 100 users regged in my hub......now in this script when i type !addarea hacker 1 thn the user Hacker gets added to db of area script.....but in real tht user Hacker is not reggged on the hub......so could u plzz cuztomize it in such a way tht only regged users on the hub r added to area script db.....if there is some other user being added who is not regged on hub thn the master entering the command would get an error message tht " this user is not regged on the hub" so he cant add tht user to area script db...

(if the 1st part is done...thn only 2nd part is possible)

2) if there r 100 users regged in my hub......and 50 r added to area script db.....when i type !usersleft   it shud show me the remaining 50 users to be added to area script db.....

Hope now i have confused you......if still u r not clear with my post thn plzz tel me i'll try to be more clear on my next post........thank u.....
Title: Re: Area's and Places
Post by: Thor on 10 October, 2006, 21:28:53
Here is it:
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.
]]
function Main()
sBot = frmHub:GetHubBotName() -- The botname who send us the messages
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[nick] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
local file2 = io.open("userareas.tbl", "r")
if (file2) then
tAreas = {}
local line = file2:read()
while line do
local _,_,area = string.find(line,"(.*)")
table.insert(tAreas,area)
line = file2:read()
end
file2:close()
table.sort(tAreas,  function(a,b) return a<b end)
else
tAreas = {}
end
SetTimer(60000) -- Update the MyINFO-s in every minute
StartTimer() -- start the timer
end

function ChatArrival(curUser,data)
local _,_,data = string.find(data,"%b<>%s*(.*)|")
local _,_,command = string.find(data,"%p(%S+)")
if command then
if command == "areaadd" then
if curUser.iProfile == 0 then
local _,_,area = string.find(data,"%p%S+%s*(.*)")
for i in ipairs(tAreas) do
if string.lower(tAreas[i]) == string.lower(area) then
bIsExist = true
end
end
if bIsExist then
curUser:SendData(sBot,"This value is still in the database.")
bIsExist = nil
else
area = string.gsub(area," ","_")
table.insert(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
curUser:SendData(sBot,area.." has been successfully added to the database with index "..table.getn(tAreas))
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "areadel" then
if curUser.iProfile == 0 then
local _,_,area = string.find(data,"%p%S+%s*(%d+)")
if area then
if tonumber(area) <= table.getn(tAreas) then
curUser:SendData(sBot,tAreas[tonumber(area)].." has been successfully deleted from the list.")
table.remove(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
bIsExist = nil
else
curUser:SendData(sBot,"There is no area with index '"..area.."' on the list. Use the !arealist command.")
end
else
curUser:SendData(sBot,"Usage: !areadel <index>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "arealist" then
if curUser.iProfile == 0 then
local msg = "Currently avaible areas are:\r\n"
for i in ipairs(tAreas) do
msg = msg..i.." - "..tAreas[i].."\r\n"
end
if msg == "Currently avaible areas are:\r\n" then msg = "The list is empty." end
curUser:SendPM(sBot,msg)
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "addarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(%d+)")
if nick then
if tUserAreas[nick] then
curUser:SendData(sBot,nick.." is already in the database from "..tUserAreas[nick])
else
if frmHub:isNickRegged(nick) == 1 then
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[nick] = tAreas[tonumber(area)]
curUser:SendData(sBot,nick.." has been successfully added to the database "..
"with area "..tAreas[tonumber(area)])
else
curUser:SendData(sBot,"Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command.")
end
else
curUser:SendData(sBot,"This user isn't registered in this hub. Please register him/her first.")
end
end
else
curUser:SendData(sBot,"Usage: !addarea <nick> <areaindex>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "delarea" then
if curUser.iProfile == 0 then
local _,_,nick = string.find(data,"%p%S+%s*(%S*)")
if tUserAreas[nick] then
tUserAreas[nick] = nil
curUser:SendData(sBot,nick.." has been successfully deleted from the database.")
else
curUser:SendData(sBot,"This user is not in my database, please check your syntax. Use the !listareas command")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "chgarea" then
if curUser.iProfile == 0 then
local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(%d+)")
if nick then
if not tUserAreas[nick] then
curUser:SendData(sBot,nick.." is not in the database, so you can't change his/her area.")
else
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[nick] = tAreas[area]
curUser:SendData(sBot,nick.." has been successfully modified in the database with new area: "..tAreas[tonumber(area)])
else
curUser:SendData(sBot,"Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command.")
end
end
else
curUser:SendData(sBot,"Usage: !addarea <nick> <area>")
end
else
curUser:SendData(sBot,"You can't use this command!")
end
return 1
elseif command == "listareas" then
local _,_,opt = string.find(data,"%p%S+%s*(.*)")
if opt == "" then
if curUser.iProfile == 0 then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
curUser:SendPM(sBot,"The database is empty yet...")
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
else
if curUser.iProfile == 2 or curUser.bOperator then
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if string.lower(tUserAreas[k]) == string.lower(opt) then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
curUser:SendPM(sBot,"Check your syntax! There is nobody from "..opt)
else
curUser:SendPM(sBot,msg)
end
else
curUser:SendPM(sBot,"You can't use this command!")
end
end
return 1
elseif command == "areastat" then
local tCount = {}
for k in pairs(tUserAreas) do
table.insert(tCount,k)
end
local iACounter = table.getn(tCount)
local iRCounter = table.getn(frmHub:GetRegisteredUsers())
curUser:SendData(sBot,"There are "..iACounter.." users in the area-database, and there are "..
iRCounter.." registered users in the hub-database ("..iRCounter-iACounter.." users "..
"are remaining)! Totally "..math.floor((iACounter/iRCounter)*100).."% of registered users in the database.")
return 1
end
end
end

function ToArrival(curUser,data)
local _,_,nickto = string.find(data, "^%$To:%s(%S+)")
if nickto == sBot then
ChatArrival(curUser,data)
end
end

function NewUserConnected(curUser)
if curUser.iProfile == 0 then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add a new area$<%[mynick]> !areaadd %[line:New area:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete area$<%[mynick]> !areadel %[line:Area to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List avaible areas$<%[mynick]> !arealist&#124;|")
curUser:SendData("$UserCommand 0 3")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Add a new user to the db.$<%[mynick]> !addarea %[line:Nick:] %[line:area index:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Modify an existing user$<%[mynick]> !chgarea %[line:Nick:] %[line:New area index:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Delete a user$<%[mynick]> !delarea %[line:Nick to delete:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from database$<%[mynick]> !listareas&#124;|")
end
if curUser.iProfile == 2 or curUser.bOperator then
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\List users from the given area$<%[mynick]> !listareas %[line:From where:]&#124;|")
curUser:SendData("$UserCommand 1 3 -=USERAREAS=-\\Get statistics$<%[mynick]> !areastat&#124;|")
end
end
OpConnected = NewUserConnected

function OnTimer()
for i,v in ipairs(frmHub:GetOnlineUsers()) do
if tUserAreas[v.sName] then
local myinfo = "$MyINFO $ALL "..v.sName.." "..tUserAreas[v.sName].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte).."$"..(v.sEmail or "").."$"..v.iShareSize.."$"
SendToAll(myinfo)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
local file2 = io.open("userareas.tbl", "w")
if file2 then
for index, value in ipairs(tAreas) do
file2:write(value.."\r\n")
end
end
file2:close()
end

New command: !areastat
(I checked now the syntax, convert is unnecessary)
Title: Re: Area's and Places
Post by: speedX on 11 October, 2006, 15:03:28
the command !areaadd is not working and showing the following error:
Quote
[18:30] Syntax ...ushil\PtokaX & Scripts\test 0.3.5.1\scripts\area.lua:57: attempt to compare function with string
Title: Re: Area's and Places
Post by: Thor on 11 October, 2006, 15:08:27
What area you add?
Title: Re: Area's and Places
Post by: speedX on 11 October, 2006, 15:10:50
!areaadd Vasant vihar
Title: Re: Area's and Places
Post by: Thor on 11 October, 2006, 16:30:55
Try to re-add, I can't reproduce the problem. (tried with LUA5.02 and 5.11 also)
Title: Re: Area's and Places
Post by: speedX on 12 October, 2006, 15:33:29
When i try to add any new area to the db, it shows the following error in Ptokax:
Quote
[18:56] Syntax ...ushil\PtokaX & Scripts\test 0.3.5.1\scripts\area.lua:58: attempt to concatenate local 'area' (a function value)
Title: Re: Area's and Places
Post by: Thor on 12 October, 2006, 15:54:59
Try to re-download it. string.gsub was string.gmatch :o
Title: Re: Area's and Places
Post by: speedX on 12 October, 2006, 16:27:17
Yup, now working as requested, thank you. My one last request abt the commands. Is it possible to make the command
!areastat -----> Only for masters
!addarea -----> For maters & OP's both
(Only these two changes nothin else)

plzz make this change if possible.
Title: Re: Area's and Places
Post by: Thor on 12 October, 2006, 17:48:28
Maybe it would be easy to make global tables from the each commands, who can use it ;D
Title: Re: Area's and Places
Post by: speedX on 13 October, 2006, 20:37:06
Yes it would be better to use global tables for each command as request's may vary from user to user.
Posted on: 12 October 2006, 19:04:57
Quote
There are 2 users in the area-database, and there are 5 registered users in the hub-database (3 users are remaining)! Totally 40% of registered users in the database.

I would like if the result is displayed like this:
Quote
There are 2 users in the area-database, and there are 5 registered users in the hub-database (3 users are remaining)! Totally 40% of registered users in the database.

Remaining Users:
speedX
Hacker

Plzz make this change if possible.
Title: Re: Area's and Places
Post by: ninad_laud on 25 January, 2007, 06:56:34
Thnx for the script it is a gr8 script ................. but can u make a change in it ........ when a user is regd in the hub as soon as he login the script must automatically ask the user 2 put his area .......until he does not put the area he should not be allowed 2 enter in chat (JUST LIKE THE TERMS & CONDITION SCRIPT) is it possible 2 do such change in the script
Thnx in Advance........ :D
(http://forum.ptokax.org/Themes/dilbermc/images/warnban.gif) Double registration to avoid effects of the warning -- bastya_elvtars
Title: Re: Area's and Places
Post by: speedX on 08 February, 2007, 20:15:25
Hi Hungarista,
Is it possible to make this script for lower case also, like when I add an area for a user speedX thn is shud be applicable for speedx also....

eg. when i add an area for Hungarista, the area comes in his description, but when he login's with nick hungarista thn his area does not come in description....coz "h" is small