PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Help with scripts => Topic started by: satya on 03 July, 2008, 11:15:26

Title: Why the time is not changin
Post by: satya on 03 July, 2008, 11:15:26
Hey guys take a look at the following code


--bot name
local bot="User Alert"
local desc="I give ops alert about user login"

OnStartup = function()
Core.RegBot(bot,desc,"user@domain.com",true)
end

UserConnected = function(user)
local time=os.date("%B %d %Y %I:%m %p")
local msg="\r\n\r\n\t\t\t\t\t\t\tUSER ALERT\r\n"
msg=msg.."\t\t\t\t\t\tUser "..user.sNick.." logged in the hub at "..time.."\r\n"
msg=msg.."\t\t\t\t\t\twith the IP "..user.sIP.."\r\n"
Core.SendToOpChat("<"..bot.."> "..msg.."|")
end



Its a simple script wich i wanted and i tried on it myself. its a simple script where the scripts sends a message to the ops.

now the problem here is in the message the Date wich i retrieve with the function
local time=os.date("%B %d %Y %I:%m %p")
this time remains static
it never changess
And also it runs only for one user the first to login the hub..
can ne1 tell me the reason n also how to correct it!.

thanks in advance
Title: Re: Why the time is not changin
Post by: CrazyGuy on 03 July, 2008, 12:42:33
Can you give an example of the formatted time as the user sees it ? I'm not familiar with all the parameters.
Mind you that you use only UserConnected, therefor this script is only triggered when unregistered users enter, this seems to be your purpose, just making sure.

What you could try is the table returned by os.date("*t")
For that I'd suggest the following changes:

Change

local time=os.date("%B %d %Y %I:%m %p")


to

local tTime = os.date("*t")


and change

msg=msg.."\t\t\t\t\t\tUser "..user.sNick.." logged in the hub at "..time.."\r\n"


to

msg=msg.."\t\t\t\t\t\tUser "..user.sNick.." logged in the hub at "..Ttime.hour..":"..tTime.min..":"..tTime.sec.."\r\n"


The default format for os.date() without parameters is date + time

Title: Re: Why the time is not changin
Post by: satya on 03 July, 2008, 13:16:26
Here is the message wich the ops used to get with the earlier script


                                                               USER ALERT
User asshole logged in the hub at July 03 2008 04:07 PM
with the IP **.**.***.***


and after doin the changes as u said the script aint displayin any message at alll


so wat change do i need to do to make this work for all users (registered n unregistered)
Title: Re: Why the time is not changin
Post by: Madman on 03 July, 2008, 15:49:22
Typo by CG

it says Ttime.hour insted of tTime.hour
Title: Re: Why the time is not changin
Post by: satya on 04 July, 2008, 09:44:39
thanks guys

workin like a charm........


i will b back with more queries as i know started to know the lua scripting basics!  :P
Title: Re: Why the time is not changin
Post by: CrazyGuy on 04 July, 2008, 14:41:08
Quote from: Madman on 03 July, 2008, 15:49:22
Typo by CG

it says Ttime.hour insted of tTime.hour

thnx :)

As an addition for satya, the tTime table holds more values if you would want them.

Quote from: http://www.lua.org/manual/5.1/manual.html
if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1--12), day (1--31), hour (0--23), min (0--59), sec (0--61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean).