ok, not that easy i think what im looking for ...
i want to save to a .txt file when this happens
elseif cmd == "addclient" and user.sName == "b_w_johan" or "[MR]johan" then
local s,e,pre,cmd,client,numberc = strfind(data,"%b<>%s+(%p)(%S+)%s+(%S+)%s+(%S+)")
SendToAll(GuardName, "client "..client.." versie "..numberc.." is toegevoegd aan de lijst")
return 1
ok so if command +addclient vDC 0.001 is send to main
the script filters vDC and 0.001
now it sends directly to main.
but i want it to save to .txt file.
if you can give me this part it would be great already but i want it even m,ore difficult now =-p
ok so savinf to file that happened now it was placed on bottom of the .txt file.
BUT thats not what i want i want it to be organized alfabetical so when i send +addclient vDC 0.001 .
it shouldn't get on bottom of script but on the place in list starting with V
so the .txt is not empty at begin ...
ill add
a
b
c
d
e
etc
so when +addclient dc++ 0.667
it will be placed between
d
and
e
and when sending +addclient dc++ 0.001
it should be..
d
here
dc++ 0.667
e
maybe a bit confusing... im not that good in english but hope you get what im trieing to explain.
with writing to file part im happy to but when you have time please help me to get alfabetical order !
greetings b_w_johan
Quote--Guard v1.001 by b_w_johan
-- part to read from file and save to file
GuardName = "[BOT]Guard" --Main Bot, all functions go by him
clients = "txt/clientlist.txt"
function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
local s,e,pre,cmd = strfind(data,"%b<>%s+(%p)(%S+)")
if cmd == "clientlist" then
file = clients
WhileRead(user,file)
return 1
elseif cmd == "addclient" and user.sName == "b_w_johan" or "[MR]johan" then
local s,e,pre,cmd,client,number = strfind(data,"%b<>%s+(%p)(%S+)%s+(%S+)%s+(%S+)")
SendToAll(GuardName, "client "..client.." versie "..number.." is toegevoegd aan de lijst")
SendToAll(GuardName, "wil je de complete lijst zien met alle clients van Johan type +clientlist. - <%[mynick]> is kicking %[nick] because:")
--read in clientlist.txt
--check if client or version are in there already
--if not then
--find line to place
--and place it there
--else
User:SendPm(Guardname, "im sorry this one is in list already")
return 1
end
end
end
function WhileRead(user,file)
readfrom(file)
while 1 do
line = read()
if line == nil then
break
end
user:SendPM(GuardName,line)
end
readfrom()
end
please help me to fill in the editors notes with real code, would be much apreciated
--if someone could tell me how i make code like its shown in here with thos spaces at begin would be cool QUOTE aint doing the trick hehe
vallue's or keys=vallue's in lua tables move around a bit.
so you would need a function 2 sort them on showing.
for the rest there shouldn't be any need 2 use a sorted table.
plop
QuoteOriginally posted by plop
so you would need a function 2 sort them on showing.
plop
lo0ol youre serieus =-p afcourse i need that, please post =-p, NightLitch gave me some code have to test / change that trying to make that work if you think youve got a better way then nightlitch please post it to plop =-p hehe
greetings Johan
List = {}
List.Sort = function( iTable )
table.sort(iTable,function(a,b) if a < b then return b end end)
return iTable
end
List.AddStr = function( iString, iTable )
table.insert(iTable, string.lower(iString) )
end
List.RemoveStr = function( iString, iTable )
for i = 1,table.getn(iTable) do
if string.lower(iTable
) == string.lower(iString) then
table.remove(iTable, i )
end
end
end
List.SaveToFile = function(iTable, iFilename )
iTable = List.Sort( iTable )
local file = io.open(iFilename, "w")
for i = 1,table.getn(iTable) do
file:write(iTable.."\n")
end
file:close()
end
List.LoadFromFile = function(iTable, iFilename )
local file = io.open(iFilename, "r")
for line in file:lines() do
local _,_,str = string.find(line, "(%S+)")
if str then
table.insert(iTable, string.lower(str))
end
end
file:close()
end
--// Example Code
local Temp = {}
List.LoadFromFile(Temp, "list.txt")
List.AddStr("donald duck", Temp)
List.SaveToFile(Temp, "list.txt")
this is what i get .... don't realy get why i have that list. on it its looking difficult now lol ...
well going to bed now school tentams to morow morning.
so im off to bed hope someone can't sleep and make a nice script combining this thing from NL and what i have below THX THX and goodnight to u all !!
Greetings Johan