PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: htb222 on 31 May, 2005, 07:27:32

Title: My First script
Post by: htb222 on 31 May, 2005, 07:27:32
Hy all!
I finished my first script. Is not a very difficult script but i'm glad that this happened.
The script shows time as a user and have functions for users to set an alarm at a specified time.
I hope u enjoy this and i'm listening to all opions.
This is the script:
-- My first script
-- Thanks to all

hours = os.date("%H")
minutes = os.date("%M")
seconds = os.date("%S")
current =hours.."."..minutes.."."..seconds
sec = 1000
AlarmUsers={}
RemindUsers={}
sMsg=""
--------------------------------------------------------
function Main()
frmHub:RegBot("-=" ..current .."=-")
SetTimer(sec)
StartTimer()
end
----------
function ChatArrival(user, data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if string.lower(cmd) == "!alarm" then
local s,e,time,Reminder =  string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if time ~= nil and Reminder ~= nil then
AlarmUsers[user.sName] = time
RemindUsers[user.sName] = Reminder
user:SendPM ("Alarm-Bot","You set the alarm at : "..time.." with the reminder: "..Reminder)
return 1
else
user:SendData("Sintaxa: !alarm . Note: Hour format is hour.minutes.seconds. Ex: 07.00.00 for activate the alarm at 7 o'clock in the morning.")
return 1
end
end
if string.lower(cmd) == "!delalarm" then
 if AlarmUsers[user.sName] ~= nil then
user:SendPM ("Alarm-Bot","The alarm: "..AlarmUsers[user.sName].." with the remider: "..RemindUsers[user.sName]..", was deleted!")
 else user:SendPM("Alarm-Bot","There is no activated alarm!")
 end
return 1
end
if (string.lower(cmd) == "!showalarm") and (user.bOperator) then
sMsg = sMsg.."\r\n------------------------------- ALL ALARMS -------------------------------\r\n"
         for i,v in AlarmUsers do
 sMsg = sMsg.."\t"..i.." has the alarm activated at : "..AlarmUsers[user.sName].." with de reminder: "..RemindUsers[i]
         end
sMsg = sMsg.."\r\n-------------------------------------- END --------------------------------------\r\n"
         user:SendPM("Alarm-Bot", sMsg)
return 1
end
end
--------------------------------------------------------
function OnTimer()
frmHub:UnregBot("-=" ..current .."=-")
hours = os.date("%H")
minutes = os.date("%M")
seconds = os.date("%S")
current =hours.."."..minutes.."."..seconds
for i,v in AlarmUsers do
 if AlarmUsers[i] == current then
  TheUser = GetItemByName(i)
  TheUser:SendPM ("Alarm-Bot",RemindUsers[i])
  TheUser:SendData ("Alarma",RemindUsers[i])
  AlarmUsers[TheUser] = nil
  RemindUsers[TheUser] = nil
 end
end
frmHub:RegBot("-=" ..current .."=-")
end
P.S. Sorry for my english.
Title:
Post by: TTB on 31 May, 2005, 08:56:46
Nice one... keep it up m8!
Title:
Post by: htb222 on 31 May, 2005, 11:26:47
Thx all. I hope you enjoied! I still wait for others opinios.
Cheers
Title:
Post by: Skippy84 on 31 May, 2005, 12:01:10
Hello thats a nice Script :D

i translatet it into german language it can found here

http://skippy.dyndns.ws/Forum/viewtopic.php?p=54#54
 
i found a little mistake


      user:SendPM ("Alarm-Bot","The alarm: "..AlarmUsers[user.sName].." with the reminder: "..RemindUsers[user.sName]..", was deleted!")

and here

  TheUser:SendPM ("Alarm-Bot",RemindUsers)

  TheUser:SendData ("Alarma",RemindUsers)
is Alarma right or is it Alarm-Bot to?
Title:
Post by: htb222 on 31 May, 2005, 12:31:26
Yes Skippy84 there was 2 mistakes

1. After user:SendPM ("Alarm-Bot","The alarm: "..AlarmUsers[user.sName].." with the reminder: "..RemindUsers[user.sName]..", was deleted!")
 u will write this:

   AlarmUsers[user.sName] = nil
   RemindUsers[user.sName] = nil

2. Replace string "Alarma" with "Alarm-Bot". The first version was in romanian and when i translated i forgot to translate this.

Thx for translate my script in german.
Thx for show me those 2 errors.
Cheers