PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: ruler on 12 June, 2005, 20:41:15

Title: [LUA 5]last seen logger
Post by: ruler on 12 June, 2005, 20:41:15
howdy
i'm trying to create a "last seen" logger for Registered users.

the file that holds the info looke like this..

jed|06/12/05|18:58:27
john|06/12/05|15:40:11
joe|06/12/05|17:22:54

where its nick,date,time storred in a .dat or .txt file.
only when the user is registered the nick is added and when a registered user logs off it should edit the date and time of the logoff.
oh and also when shutting down the hubsoft the changes will need to be saved.
anyone know of a script like this please send me a link. many thanks
Title:
Post by: jiten on 12 June, 2005, 20:58:50
QuoteOriginally posted by ruler
howdy
i'm trying to create a "last seen" logger for Registered users.

the file that holds the info looke like this..

jed|06/12/05|18:58:27
john|06/12/05|15:40:11
joe|06/12/05|17:22:54

where its nick,date,time storred in a .dat or .txt file.
only when the user is registered the nick is added and when a registered user logs off it should edit the date and time of the logoff.
oh and also when shutting down the hubsoft the changes will need to be saved.
anyone know of a script like this please send me a link. many thanks
Search the forum for "Seen Bot".
With some minor changes it will fulfill your request.

Cheers
Title:
Post by: ruler on 13 June, 2005, 19:11:19
i didnt find anything like what i am looking for, most of the scripts i did see were massive. i'm sure it can be done with a smaller script.
thanks for the reply anyway
Title:
Post by: Dessamator on 13 June, 2005, 20:07:09
QuoteOriginally posted by ruler
i didnt find anything like what i am looking for, most of the scripts i did see were massive. i'm sure it can be done with a smaller script.
thanks for the reply anyway

well if u think it can be done with a smaller script do it urself, and plus, every script starts with a smaller version, find it !

Good luck
Title:
Post by: ruler on 14 June, 2005, 12:07:29
if i could do it myself i wouldnt have made a post here now would i?
if it were in the old LUA then it would have been simple as hell but i am not quiter familar with the way the new LUA works hence the reason for my request.
there isnt much explanation or examples on how to read/write/edit text files yet how ever i did see a nice little post from Plop which did help.
everything i have tried either gives me an error or wont work the way i expected but thanks for the reply anyhows
Title:
Post by: Dessamator on 14 June, 2005, 12:29:29
well, u obviously dont know what ur talking about , in the how to section,

there is a detailed explanation on how to do all of that in lua 5 scripts,  if u havent found it than u obviously need to fine tune ur searching habilities

either way, try clicking here (http://board.univ-angers.fr/thread.php?threadid=4528&boardid=29&sid=00cf1a7d452094e9ad34c2ac6494e42e)  

and for help on how to manipulate  files  search the howto sections !
Title:
Post by: ruler on 14 June, 2005, 13:23:44
thanks for that link and now for the last question  :D
i know the line...

f:write("blablabla") -- writes to file

but who can i remove or replace a line?
i am looking still in the forums but with no luck as yet!
thanks
Title:
Post by: Dessamator on 14 June, 2005, 13:43:51
replacing a line is easy, just use a loop and replace it,

if line =="blah" then -- line=nil line="blah2"
or use string.gsub(line, "blah", "") or string.gsub(line,"blah", "blah2"

 same thing for removing a line !
Title:
Post by: ruler on 14 June, 2005, 14:46:38
no luck, it didnt remove the line  ?(
when i open the text file, the same line is still there and has not been removed or over written.
im not sure if i need to use...

local f = io.open(filename, "w")
local f = io.open(filename, "w+")
local f = io.open(filename, "a")
local f = io.open(filename, "a+")


the basic loop looks like this ...

   for line in io.lines("../scripts/RegUserLastSeen.txt") do

      s,e,nme,dat,tme=string.find(line,"(.+)%|(.+)%|(%d+)")
      if nick == nme then
-- user name matched in text file
-- delete this user/line from text file
-- replace with same nick but new date and time
      break end

   end

thats is kind of what i have so far and what i am trying to do followed by the --
hope it makes sence  8o
Title:
Post by: Dessamator on 14 June, 2005, 18:17:31
ok lets try it another way,
1. put all the lines in a variable, excluding the lines u dont need, and with all the changes u require !
2.Erase the old file,
3.Create a new file
4.Write the changes to the new file !

P.S.: this is easier to do with tables, doing it like this isnt very efficient !
Title:
Post by: ruler on 14 June, 2005, 22:53:53
i thought about doing it with tables too but lots more work involved  :D
i was just looking for a simpler way of doing it but i am now beginning to think i might have to do it with tables after all  8o
thanks for the reply and the help, much appreciated