Олдфаг
- Статус
- Оффлайн
- Регистрация
- 28 Дек 2018
- Сообщения
- 2,623
- Реакции
- 1,455
Будильник
Код:
local alarms = {}
ffi.cdef[[
typedef unsigned short WORD;
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
}
SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
void GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
]]
alarms.notify = function(type, descr)
Cheat.AddNotify(type, descr)
end
alarms.get_time = function()
local systym_time = ffi.new("SYSTEMTIME")
ffi.C.GetLocalTime(systym_time)
return {
hour = systym_time.wHour,
minute = systym_time.wMinute,
second = systym_time.wSecond,
milliseconds = systym_time.wMilliseconds,
}
end
alarms.menu_data = {}
alarms.menu_data.hour = {}
for i = 0, 23 do
local hour = ("%02d"):format(i)
table.insert(alarms.menu_data.hour, hour)
end
alarms.menu_data.minute = {}
for i = 0, 60 do
local minute = ("%02d"):format(i)
table.insert(alarms.menu_data.minute, minute)
end
alarms.menu = {}
alarms.menu.global_tab_name = "Alarms"
alarms.menu.new_alarm_tab_name = "Create Alarm"
alarms.menu.active_alarms_tab_name = "Active Alarms"
alarms.menu.draw_time = Menu.Switch(alarms.menu.global_tab_name, "Draw Time", false)
alarms.menu.name = Menu.TextBox(alarms.menu.new_alarm_tab_name, "Name", 64, "Alarm")
alarms.menu.hour = Menu.Combo(alarms.menu.new_alarm_tab_name, "Hour", alarms.menu_data.hour, 0)
alarms.menu.minute = Menu.Combo(alarms.menu.new_alarm_tab_name, "Minute", alarms.menu_data.minute, 0)
alarms.menu.new = Menu.Button(alarms.menu.new_alarm_tab_name, "Create", "")
alarms.data = {}
alarms.new = function()
local name = alarms.menu.name:Get()
local hour = alarms.menu.hour:Get()
local minute = alarms.menu.minute:Get()
-- @note: Checking for the same alarms
for i, data in ipairs(alarms.data) do
if (data.hour == hour and data.minute == minute and data.name == name) then
alarms.notify("Error", "You cannot create the same alarms!")
return
end
end
table.insert(alarms.data, {
alarm_item = Menu.Switch(alarms.menu.active_alarms_tab_name, ("[%s] %02d:%02d"):format(name, hour, minute), false, "Delete on Switch"),
name = name,
hour = hour,
minute = minute,
})
-- @note: anti-neverlose save data
for i, data in ipairs(alarms.data) do
data.alarm_item:Set(false)
end
end
alarms.menu.new:RegisterCallback(alarms.new)
alarms.update_delete_callback = function()
for i, data in ipairs(alarms.data) do
if data.alarm_item:Get() then
Menu.DestroyItem(data.alarm_item)
table.remove(alarms.data, i)
end
end
end
alarms.update_alarms = function()
local time = alarms.get_time()
for i, data in ipairs(alarms.data) do
if (time.hour == data.hour and time.minute == data.minute and time.second == 0 and time.milliseconds <= 2) then
alarms.notify("Alarm", data.name)
EngineClient.ExecuteClientCmd("play music\\kill_03")
end
end
end
alarms.draw_time = function()
if alarms.menu.draw_time:Get() then
local time = alarms.get_time()
local menu_pos = Render.GetMenuPos()
local menu_visible = Cheat.IsMenuVisible()
local improve_time = ("%02d:%02d:%02d"):format(time.hour, time.minute, time.second)
if menu_visible then
Render.Text(improve_time, Vector2.new(menu_pos.x + 350, menu_pos.y - 15), Color.RGBA(255, 255, 255), 15, true)
end
end
end
alarms.on_draw = function()
alarms.draw_time()
alarms.update_alarms()
alarms.update_delete_callback()
end
Cheat.RegisterCallback("draw", alarms.on_draw)
Пожалуйста, авторизуйтесь для просмотра ссылки.