CountDown Script! - Page 2
 

News:

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

CountDown Script!

Started by Hades, 16 May, 2005, 01:06:57

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kash?

I don't want to sned MOTD in PM
anyways,.....Thx

sidetrack

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?

Madman

#27
------------------------------------------------------------------------------
-------                  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...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

jiten

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

CrazyGuy

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

SMF spam blocked by CleanTalk