PtokaX forum

Archive => Archived 5.1 boards => Conversion Requests => Topic started by: LeChuck on 05 March, 2008, 12:21:21

Title: Conversion LUA4 -> LUA5.1.2
Post by: LeChuck on 05 March, 2008, 12:21:21
Hello,
i need a conversion of this script from PtokaX 0.3.2.6 Testdrive with ChannelBot (LUA4) to PtokaX 0.3.6.0 with RoboCop 10.0.23 (LUA 5.1.2).

botname = "-= TimeBot =-"
bot_speed = "Atomic"
bot_descr = "Stunden-Timer"



function Main()
frmHub:RegBot(botname)
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"
end

function zeitAnzeige()
local sHour = date("%H")
local sMin = date("%M")
UhrZeit=("\t\t\t Current Time is " ..sHour.. ":" ..sMin.. " .")
if sMin=="00" then
SendToAll("Time", UhrZeit)
StopTimer()
local sSec = date("%S")
SetTimer(60*60*1000-sSec)
StartTimer()
end
end

function OnTimer()
zeitAnzeige()
end

function Main()
SetTimer(57000)
StartTimer()
end


Can anybody help, please !  :-*
Title: Re: Conversion LUA4 -> LUA5.1.2
Post by: LeChuck on 06 March, 2008, 16:11:22
Thanks Mutor,

but dosn't work with PtokaX 0.3.6.0.  :'(

[15:12] No syntax errors in script file lua/showtime_everyhour.lua

... on startup hub, on 16:00 pm local time no message.

Any idea what's wrong ?  :-*
Title: Re: Conversion LUA4 -> LUA5.1.2
Post by: Madman on 06 March, 2008, 19:03:20
Yup, this is made for 0.4.0.0
Title: Re: Conversion LUA4 -> LUA5.1.2
Post by: LeChuck on 08 March, 2008, 20:40:19
Thanks Mutor,
its work ........ but not so i will.

--[[

ChimeBot 1.0 LUA 5.1x [Strict][API 1&2]

By Mutor 03/06/08

Sends current hub time [UTC/GMT] to all in main chat
at preset minute of the hour [any 00 - 59]
]]

local bot_name = "-=TimeBot=-"
local bot_descr = "? Stunden-Timer ?"
--Minute of the hour to chime [00 - 59]
local chime_time = 00


--local Tmr,Id = 0
--OnStartup = function()
-- Tmr = TmrMan.AddTimer(1000)
-- Core.RegBot(bot_name:gsub("[$|<>:?*\"/\\]",string.char(95)),bot_descr,"",true)
--end

Main = function()
SetTimer(1000) StartTimer()
frmHub:RegBot(bot_name:gsub("[$|<>:?*\"/\\]",string.char(95)),1,bot_descr,"")
Tmr = nil
end

OnTimer = function(Id)
if Id == Tmr then
local sHour,sMin = os.date("%H"),os.date("%M")
if sMin == tostring(chime_time) then
local UhrZeit=("\t\t Hello members, it is now " ..sHour.. ":" ..sMin.. " exaktly !")
if Core then
Core.SendToAll("<"..bot_name.."> "..UhrZeit.."|")
TmrMan.RemoveTimer(Tmr)
Tmr = TmrMan.AddTimer(60*60000)
else
SendToAll(bot_name,UhrZeit)
StopTimer() SetTimer(60*60000) StartTimer()
end
end
end
end

--Returns UTC timezone as a string by Mutor
--TimeZone = function()
-- local h,m = math.modf((os.time()-os.time(os.date"!*t"))/ 3600)
-- return string.format("%+d UTC",(h + (60 * m)))
--end


You see, i've little modified, but the mysterium is the message don't make when chime_time = 00 or 01 or 02 ....... or 09.
I will use it whenever full hour, also 00.
It's works perfektly 0n 11 .... 59.

Do you have a little help for idea, PLEASE.  :'(
Title: Re: Conversion LUA4 -> LUA5.1.2
Post by: LeChuck on 08 March, 2008, 22:08:14
YEAH !
Now it's run !
I've make more modified, now running.

--[[
ChimeBot 1.0 LUA 5.1x [Strict][API 1&2]

By Mutor 03/06/08

Sends current hub time [UTC/GMT] to all in main chat
at preset minute of the hour [any 00 - 59]
]]

local bot_name = "-=TimeBot=-"
local bot_descr = "? Stunden-Timer ?"

Main = function()
SetTimer(1000) StartTimer()
frmHub:RegBot(bot_name:gsub("[$|<>:?*\"/\\]",string.char(95)),1,bot_descr,"")
Tmr = nil
end

OnTimer = function(Id)
if Id == Tmr then
local sHour,sMin = os.date("%H"),os.date("%M")
if sMin == "00" then
local UhrZeit=("\t\t Hello members, it is now " ..sHour.. ":" ..sMin.. " exaktly !")
if Core then
Core.SendToAll("<"..bot_name.."> "..UhrZeit.."|")
TmrMan.RemoveTimer(Tmr)
Tmr = TmrMan.AddTimer(60*60000)
else
SendToAll(bot_name,UhrZeit)
StopTimer() SetTimer(60*60000) StartTimer()
end
end
end
end


Now message is : Hello members, it is now 22:00 exaktly !

;)

@Mutor,
it's my own german closed Hub with only german member, so i don't need UTC Timezones.