PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: Hades on 16 May, 2005, 01:06:57

Title: CountDown Script!
Post by: Hades on 16 May, 2005, 01:06:57
Could someone modify countdown - happy new year script to lua 5??




THANX!
Title:
Post by: Dessamator on 16 May, 2005, 10:02:14
yep sure, just show us which script u want modded, btw try converting it using the gui converter !
Title:
Post by: plop on 16 May, 2005, 12:07:22
here it is dessamator (http://www.plop.nl/ptokaxbots/Plop/newyear.lua)

plop
Title:
Post by: jiten on 16 May, 2005, 13:11:22
Here goes a fast one (not tested):
------------------------------------------------------------------------------
-------                  Lua 5 version by jiten                        -------
-------                  countdown bot by plop                         -------
-------             original julian day made by tezlo                  -------
-------      modifyd by chilla 2 also handle hours, mins, seconds      -------
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-------           THE TEXT FILE LOADS ON BOT START                     -------
------------------------------------------------------------------------------
------- this may sound weird but this 2 make sure it shows on time,    -------
-------      as i allready seen some big ascii's come by               -------
------------------------------------------------------------------------------


------------------------------------------------------------------------------
Bot = "newyear"

--This the date the timer has 2 stop @ midnight
-- year (2 numbers), month, day
SylYear,SylMonth,SylDay = 05,12,31
-- this is the file 2 be shown
file = "happynewyear.txt"
------------------------------------------------------------------------------
------------------------------------------------------------------------------
function OnTimer()
if last == 0 then
SendToAll(Bot, TimeLeft())
Sync()
elseif last == 1 then
SendAscii() -- send the msg
StopTimer() -- kill the timer
end
end
------------------------------------------------------------------------------
function jdatehms(d, m, y,ho,mi,se)
local a, b, c = 0, 0, 0
if m <= 2 then y = y - 1 m = m + 12 end
if (y*10000 + m*100 + d) >= 15821015 then a = math.floor(y/100) b = 2 - a + math.floor(a/4) end
if y <= 0 then c = 0.75 end
return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b),ho*3600+mi*60+se
end
------------------------------------------------------------------------------
function TimeLeft()
local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
local sylday,sylsec = jdatehms(SylDay,SylMonth,SylYear,24,0,0)
local tmp = sylsec-cursec
local hours, minutes,seconds = math.floor(math.mod(tmp/3600, 60)), math.floor(math.mod(tmp/60, 60)), math.floor(math.mod(tmp/1, 60))
local day = sylday-curday
if day >= 0 then
line = "Time left till new year:"
if day ~= 0 then line = line.." "..day.." Day's" end
if hours ~= 0 then line = line.." "..hours.." Hours" end
if minutes ~= 0 then line = line.." "..minutes.." Minutes" end
if seconds ~= 0 then line = line.." "..seconds.." Seconds" end
return line
end
end
------------------------------------------------------------------------------
function ShowAscii()
local f = io.open(file)
if f then
text = f:read("*all")
f:close()
return string.gsub( text, "\n", "\r\n" )
end
end
------------------------------------------------------------------------------
function SendAscii()
SendToAll(Bot, text.." |")
SendToAll(Bot, "happy new year 2 everybody from all the guy's/girls/bot's from the lua forum|")
end
------------------------------------------------------------------------------
function ChatArrival(user, data)
data=string.sub(data,1,-2)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd == "!daysleft" then
local tmp = TimeLeft()
if tonumber(tmp) == nil then user:SendData(Bot, tmp.."|") end
return 1
end
end
------------------------------------------------------------------------------
function NewUserConnected(user)
local tmp = TimeLeft()
if tonumber(tmp) == nil then user:SendData(Bot, tmp.."|") end
end
------------------------------------------------------------------------------
OpConnected = NewUserConnected
------------------------------------------------------------------------------
function Main()
SetTimer(100 * 1000)
StartTimer()
local tmp = TimeLeft()
if tonumber(tmp) == nil then SendToAll(Bot, tmp.."|") end
Sync() ShowAscii() last = 0
end
------------------------------------------------------------------------------
function Sync()
local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
local sylday,sylsec = jdatehms(SylDay,SylMonth,SylYear,24,0,0)
local tmp = sylsec-cursec
local hours, minutes,seconds = math.floor(math.mod(tmp/3600, 60)), math.floor(math.mod(tmp/60, 60)), math.floor(math.mod(tmp/1, 60))
local day = sylday-curday
if day ~= 0 then
adjust = (math.floor(math.mod(minutes, 60))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
else
if tmp > 3600 then  --- every hours a msg
adjust = (math.floor(math.mod(minutes, 60))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
elseif tmp > 900 then  -- every 15 mins a msg
adjust = (math.floor(math.mod(minutes, 15))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(900 * 1000) end
elseif tmp > 300 then  -- every 5 mins a msg
adjust = (math.floor(math.mod(minutes, 5))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(300 * 1000) end
elseif tmp > 60 then  -- every min a msg
adjust = (math.floor(math.mod(minutes, 1))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(60 * 1000) end
elseif tmp > 15 then  -- every 15 secs a msg
adjust = math.floor(math.mod(seconds, 15))
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(15 * 1000) end
elseif tmp > 10 then  -- every 10 secs a msg
adjust = math.floor(math.mod(seconds, 10))
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(5 * 1000) end
elseif tmp > 1 then
SetTimer(1 * 1000)
else
last = 1
SetTimer(1 * 1000)
end
end
end
------------------------------------------------------------------------------

Cheers
Title:
Post by: Dessamator on 16 May, 2005, 13:44:26
hmm, nice one jiten, less work for me, :)
Title:
Post by: TiMeTrAVelleR on 16 May, 2005, 14:03:24
Got this in main  at ful hour

[14:00:00] 1


greetzzz TT
Title:
Post by: jiten on 16 May, 2005, 14:39:28
First post updated.

Cheers
Title:
Post by: TiMeTrAVelleR on 16 May, 2005, 15:01:50
[15:00:00] Time left till new year: 229 Days 9 Hours

works  fine  thanks  jiten

Greetzzz TT
Title:
Post by: jiten on 16 May, 2005, 21:11:48
You're welcome TT :]
Title:
Post by: kash? on 16 May, 2005, 22:23:51
As it is countdown for new year...,
Is it possiblt to have coundown for any
custom date which can be changed
For e.g. countdown for 26 may...instead 31 dec

Regards
Title:
Post by: jiten on 16 May, 2005, 22:40:09
QuoteOriginally posted by kash?
As it is countdown for new year...,
Is it possiblt to have coundown for any
custom date which can be changed
For e.g. countdown for 26 may...instead 31 dec

Regards
Just edit this in the Countdown script with your desired "finish" date:
--This the date the timer has 2 stop @ midnight
-- year (2 numbers), month, day
SylYear,SylMonth,SylDay = 05,12,31
Cheers
Title:
Post by: Tw?sT?d-d?v on 16 May, 2005, 22:41:31
QuoteOriginally posted by kash?
As it is countdown for new year...,
Is it possiblt to have coundown for any
custom date which can be changed
For e.g. countdown for 26 may...instead 31 dec

Regards

yes m8  just alter this part of the script for the date you require...
--This the date the timer has 2 stop @ midnight
-- year (2 numbers), month, day
SylYear,SylMonth,SylDay = 05,12,31   <<<<<<   Alter date
-- this is the file 2 be shown
file = "happynewyear.txt"

MMM beat me to it       :D
Title: Thankx a lot ppl!
Post by: Hades on 17 May, 2005, 06:28:27
This board still rulez!


Regards!
Title:
Post by: kash? on 17 May, 2005, 18:50:58
How to enable that ascii ??
Is it possible to show that countdown
timer in main chat at short interval with editable
time interval.......because of motd..that msg can
not be seen as it goes upwards



Regards
Title:
Post by: jiten on 17 May, 2005, 19:09:50
QuoteOriginally posted by kash?
How to enable that ascii ??
You need to create a file named "happynewyear.txt" in your script's main folder and then put the ASCII inside.
Quotebecause of motd..that msg cannot be seen as it goes upwards
Indeed. I'm going to change it so that it will come after the MOTD (maybe tomorrow).

Cheers
Title:
Post by: kash? on 18 May, 2005, 18:00:49
It displays countdown time every one hour
I wanna edit it and change that time interval
How can it be done ????

Regards...
Title:
Post by: plop on 19 May, 2005, 00:56:35
QuoteOriginally posted by kash?
It displays countdown time every one hour
I wanna edit it and change that time interval
How can it be done ????

Regards...

find the next lines in the sync() function.
if day ~= 0 then

adjust = (math.floor(math.mod(minutes, 60))*60)+seconds

if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
exchange 3600 for your prefered setting (3600 * 1000 = 1 hour in seconds).
but remember it's the syncronisation your messing with.

plop
Title:
Post by: kash? on 19 May, 2005, 10:40:04
Is it possible to display that message
after MOTD...
because of MOTD, that message can
not be seen as it goes upwards

Regards
Title:
Post by: dkt on 19 May, 2005, 14:42:58
just try changing the order in ptokax script editor...
use move up ..move down..
keep ur countdown script last
it shld work...as it worked for other scripts though
Title:
Post by: kash? on 19 May, 2005, 18:16:02
It doesn't work
Title:
Post by: jiten on 20 May, 2005, 20:00:33
QuoteOriginally posted by kash?
Is it possible to display that message
after MOTD...
because of MOTD, that message can
not be seen as it goes upwards

Regards
It's possible, but, if I am not wrong, it would mess up all the other timers, and so, all the script.

Cheers
Title:
Post by: Dessamator on 20 May, 2005, 20:13:10
QuoteOriginally posted by jiten
QuoteOriginally posted by kash?
Is it possible to display that message
after MOTD...
because of MOTD, that message can
not be seen as it goes upwards

Regards
It's possible, but, if I am not wrong, it would mess up all the other timers, and so, all the script.

Cheers

hmm, theres another way, disabling the motd from ptokax, and sending it via the  script, just like a normal text,  ;)
Title:
Post by: jiten on 20 May, 2005, 20:30:11
QuoteOriginally posted by Dessamator
hmm, theres another way, disabling the motd from ptokax, and sending it via the  script, just like a normal text,  ;)
Or sending the MOTD in PM too ;)
Title:
Post by: kash? on 23 May, 2005, 22:26:41
Can u plz try
if u have time
I really need this script and that too after MOTD
please have a try if u knw how to do it
take ur time

waiting for reply
Posted on: 20 May 2005, 19:35:16
Jiten can u plz. help
regarding this script,

waiting reply....
Title:
Post by: jiten on 24 May, 2005, 09:01:17
QuoteOriginally posted by kash?
Jiten can u plz. help
regarding this script,

waiting reply....
Well, I don't want to modify the timers because it would mess all the script up. So, here's my hint:


By doing this, you'll be sending the MOTD in PM and, logicaly, it won't come after the CountDown stats like it used to happen.
That's all I can do unless someone else has a better idea ;)

Cheers
Title:
Post by: kash? on 24 May, 2005, 20:10:59
I don't want to sned MOTD in PM
anyways,.....Thx
Title: Re: CountDown Script!
Post by: sidetrack on 10 November, 2006, 19:46:40
Would it be fairly easy to change constant (of time, currently set to midnight), to a varible, this would be very helpful for having meetings and such, with all the different time zones, ppl get very easy confused.. so if I could set the date, and time of meeting, and have it count down this could rock.. Also.. can it be used safely in DCDM or any other LUA script client that supports Lua 5?
Title: Re: CountDown Script!
Post by: Madman on 10 November, 2006, 22:28:21

------------------------------------------------------------------------------
-------                  Lua 5 version by jiten                        -------
-------                  countdown bot by plop                         -------
-------             original julian day made by tezlo                  -------
-------      modifyd by chilla 2 also handle hours, mins, seconds      -------
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-------           THE TEXT FILE LOADS ON BOT START                     -------
------------------------------------------------------------------------------
------- this may sound weird but this 2 make sure it shows on time,    -------
-------      as i allready seen some big ascii's come by               -------
------------------------------------------------------------------------------

-- Added: Hour,Min,Sec variables, make's it possibole to count to another time then midnight, Madman 10.11.06
-- Added: 5.1 support, Madman 10.11.06

------------------------------------------------------------------------------
Bot = "newyear"

--This the date the timer has 2 stop
-- year (2 numbers), month, day
SylYear,SylMonth,SylDay = 05,12,31
--This is the time
-- Hour, minute, second
SylHour,SylMin,SylSec = 24,00,00
-- this is the file 2 be shown
file = "happynewyear.txt"
------------------------------------------------------------------------------
if math.mod == nil then math.mod = math.fmod end

------------------------------------------------------------------------------
function OnTimer()
if last == 0 then
SendToAll(Bot, TimeLeft())
Sync()
elseif last == 1 then
SendAscii() -- send the msg
StopTimer() -- kill the timer
end
end
------------------------------------------------------------------------------
function jdatehms(d, m, y,ho,mi,se)
local a, b, c = 0, 0, 0
if m <= 2 then y = y - 1 m = m + 12 end
if (y*10000 + m*100 + d) >= 15821015 then a = math.floor(y/100) b = 2 - a + math.floor(a/4) end
if y <= 0 then c = 0.75 end
return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b),ho*3600+mi*60+se
end
------------------------------------------------------------------------------
function TimeLeft()
local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
local sylday,sylsec = jdatehms(SylDay,SylMonth,SylYear,SylHour,SylMin,SylSec)
local tmp = sylsec-cursec
local hours, minutes,seconds = math.floor(math.mod(tmp/3600, 60)), math.floor(math.mod(tmp/60, 60)), math.floor(math.mod(tmp/1, 60))
local day = sylday-curday
if day >= 0 then
line = "Time left till new year:"
if day ~= 0 then line = line.." "..day.." Day's" end
if hours ~= 0 then line = line.." "..hours.." Hours" end
if minutes ~= 0 then line = line.." "..minutes.." Minutes" end
if seconds ~= 0 then line = line.." "..seconds.." Seconds" end
return line
end
end
------------------------------------------------------------------------------
function ShowAscii()
local f = io.open(file)
if f then
text = f:read("*all")
f:close()
return string.gsub( text, "\n", "\r\n" )
end
end
------------------------------------------------------------------------------
function SendAscii()
SendToAll(Bot, text.." |")
SendToAll(Bot, "happy new year 2 everybody from all the guy's/girls/bot's from the lua forum|")
end
------------------------------------------------------------------------------
function ChatArrival(user, data)
data=string.sub(data,1,-2)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd == "!daysleft" then
local tmp = TimeLeft()
if tonumber(tmp) == nil then user:SendData(Bot, tmp.."|") end
return 1
end
end
------------------------------------------------------------------------------
function NewUserConnected(user)
local tmp = TimeLeft()
if tonumber(tmp) == nil then user:SendData(Bot, tmp.."|") end
end
------------------------------------------------------------------------------
OpConnected = NewUserConnected
------------------------------------------------------------------------------
function Main()
SetTimer(100 * 1000)
StartTimer()
local tmp = TimeLeft()
if tonumber(tmp) == nil then SendToAll(Bot, tmp.."|") end
Sync() ShowAscii() last = 0
end
------------------------------------------------------------------------------
function Sync()
local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
local sylday,sylsec = jdatehms(SylDay,SylMonth,SylYear,SylHour,SylMin,SylSec)
local tmp = sylsec-cursec
local hours, minutes,seconds = math.floor(math.mod(tmp/3600, 60)), math.floor(math.mod(tmp/60, 60)), math.floor(math.mod(tmp/1, 60))
local day = sylday-curday
if day ~= 0 then
adjust = (math.floor(math.mod(minutes, 60))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
else
if tmp > 3600 then  --- every hours a msg
adjust = (math.floor(math.mod(minutes, 60))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
elseif tmp > 900 then   -- every 15 mins a msg
adjust = (math.floor(math.mod(minutes, 15))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(900 * 1000) end
elseif tmp > 300 then -- every 5 mins a msg
adjust = (math.floor(math.mod(minutes, 5))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(300 * 1000) end
elseif tmp > 60 then  -- every min a msg
adjust = (math.floor(math.mod(minutes, 1))*60)+seconds
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(60 * 1000) end
elseif tmp > 15 then  -- every 15 secs a msg
adjust = math.floor(math.mod(seconds, 15))
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(15 * 1000) end
elseif tmp > 10 then  -- every 10 secs a msg
adjust = math.floor(math.mod(seconds, 10))
if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(5 * 1000) end
elseif tmp > 1 then
SetTimer(1 * 1000)
else
last = 1
SetTimer(1 * 1000)
end
end
end
------------------------------------------------------------------------------


Quick mode, untested, but should work...
Also added the line needed for 5.1...

And no, atm it can't be used in a client... not untill somebody mod it to be...
Title: Re: CountDown Script!
Post by: jiten on 11 November, 2006, 11:56:46
Quote from: sidetrack on 10 November, 2006, 19:46:40
Would it be fairly easy to change constant (of time, currently set to midnight), to a varible, this would be very helpful for having meetings and such, with all the different time zones, ppl get very easy confused.. so if I could set the date, and time of meeting, and have it count down this could rock.. Also.. can it be used safely in DCDM or any other LUA script client that supports Lua 5?


Have a look at this thread: http://forum.ptokax.org/index.php?topic=5928.0
Title: Re: CountDown Script!
Post by: CrazyGuy on 11 November, 2006, 18:27:42
SylYear,SylMonth,SylDay = 05,12,31

Hope you don't mind we wont wait a whole year for you Madman and continue looking forward to 07  ;D