Save to file
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Save to file

Started by b_w_johan, 21 June, 2005, 16:23:19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

b_w_johan

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
checkout http://wwhublist.com/index.php for my World Wide HubList project!

b_w_johan

#1
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
checkout http://wwhublist.com/index.php for my World Wide HubList project!

plop

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

b_w_johan

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
checkout http://wwhublist.com/index.php for my World Wide HubList project!

SMF spam blocked by CleanTalk