The idea behind plugin is this: admin sets time (in his region or whatever, eg. 13-30), custom message, and makes list of resources and items.
So. Every day, 13-30 sharp, after custom message (eg. "SERVER: Happy hours event launched") every active (not sleeping) player on server will recieve those selected resources and items.
I think it's not that hard to implement, except maybe "auto-time", which i guess have to do with cron, or maybe i am wrong.
Solved Happy hour for active players
Discussion in 'Plugin Requests' started by Groovyboy, Feb 4, 2015.
-
-
So the goal would be to have people on at certain hours of the day to get items? Like bombardir said this sounds more like something custom to be made and not something that would be wildly used.
-
i dont get why you wouldnt release it anyways? if someone is browsing the plugins comes by it and might like it. they could have never thought of the idea but now seeing it they like it. i myself kinda like it. i think i would use it for an event, if youre in the server by this time you get this stuff
-
Seems like i'll have to do it myself..
-
i would totally help you but i have no idea on this stuff
-
-
wooo!
-
I already made some basic noob coding, so if anyone wants to join, pls visit this page tomorrow, i guess. I'll put code here.
[DOUBLEPOST=1423170413][/DOUBLEPOST]Here some bare stuff.. a lot of things in "to do" state. And some things just dont work.
I know there's a lot of noob stuff - it's my 1st plugin.
Code:PLUGIN.Title = "Happy Hours" PLUGIN.Description = "Gives all players on server custom stuff at specific time" PLUGIN.Author = "Groovyboy" PLUGIN.Version = V(0, 1, 2) PLUGIN.HasConfig = truefunction PLUGIN:Init() print( "Happy Hours activated" ) --timer self.Interval = tonumber(self.Config.Settings.checkInterval) -- Start delay timer self.DelayTimer = {} self.DelayTimer = timer.Repeat(self.Interval , 0 , function() self:GiveAwayStuff( ) end ) --/hh.on turns hh active --/hh.off turns hh non-active --/hh.run manual override run of plugin --/hh.chat change chat message before giving presents out --/hh.check shows whether giveaway was or not --console (or server) commands command.AddConsoleCommand( "hh.rnd", self.Object, "GiveAwayManual" ) command.AddConsoleCommand( "hh.giveon", self.Object, "GiveOn" ) command.AddConsoleCommand( "hh.activate", self.Object, "GiveAwayActivate" ) command.AddConsoleCommand( "hh.deactivate", self.Object, "GiveAwayDeactivate" ) command.AddConsoleCommand( "hh.settime", self.Object, "GiveAwaySetTime" ) endfunction PLUGIN:Unload() -- Stop delay timer on unload if self.DelayTimer then self.DelayTimer:Destroy() endendfunction PLUGIN:LoadDefaultConfig() self.Config.pluginActive = true self.Config.Settings = {} self.Config.Settings.ChatPrefix = "AZbuka SERVER" self.Config.Settings.checkInterval = 15 self.Config.Settings.HappyHour = 23 self.Config.Settings.giveAwayAvailable = true self.Config.Messages = { forbidden = "Вы не можете использовать эту комманду.", hh1 = "Счастливые Часы настали, все игроки получают ресурсы.", hh2 = "Заходите завтра в то же время и получите их вновь.", timeInfo = "Начало Счастливых Часов с: {number}-00.", timeInfoSet = "Вы установили начало выдачи ресурсов на: {number}-00.", hhrnd = "Пришло время случайных подарков всем игрокам ;)" } end------------------------------------------ -- TIME STUFFlocal function CurrentHour() return time.GetCurrentTime():ToLocalTime():ToString("HH") endlocal function CurrentMin() return time.GetCurrentTime():ToLocalTime():ToString("mm") endfunction PLUGIN:GiveAwayDeactivate( ) self.Config.pluginActive = false self:SaveConfig() print("HH auto giveaway deactivated") endfunction PLUGIN:GiveAwayActivate( ) self.Config.pluginActive = true self:SaveConfig() print("HH auto giveaway activated") end----------------------------------------- --getter setter of time function PLUGIN:GiveAwaySetTime( player , args ) --TODO chk for admin --inform (getter) if (args.Length == 0) then rust.SendChatMessage(player, self.Config.Settings.ChatPrefix, self:FormatString(self.Config.Messages.timeInfo, "{number}", self.Config.Settings.HappyHour)) return end --set (setter) local hhStartHour = tonumber(Args[0]) if (not hhStartHour) then return end self.Config.Settings.HappyHour = hhStartHour self:SaveConfig() rust.SendChatMessage(player, self.Config.Settings.ChatPrefix, self:FormatString(self.Config.Messages.timeInfoSet, "{number}", hhStartHour)) print("HH auto giveaway activated") end------------------------------------------ --auto run when the time comes (timer) function PLUGIN:GiveAwayStuff( player ) if (not self.Config.pluginActive) then print("Scheduled giveaway skipped: pluginActive=false") return end local curH = tonumber(CurrentHour()) local curM = tonumber(CurrentMin()) local hhStart = tonumber(self.Config.Settings.HappyHour) local hhEnd = 0 if hhStart == 23 then hhEnd = 0 else hhEnd = hhStart + 1 end --if it's midnight then reset counter and make giveAway available again if curH >= 0 and curH < 1 then self.Config.Settings.giveAwayAvailable = true self:SaveConfig() elseif curH >= hhStart and curH < hhEnd and curM < 59 and self.Config.Settings.giveAwayAvailable then print("Счастливые Часы настали, все игроки получают ресурсы") print("...выдача...") --rust.BroadcastChat(self.Config.Settings.ChatPrefix, self.Config.Messages.hh1 ) --rust.BroadcastChat(self.Config.Settings.ChatPrefix, self.Config.Messages.hh2 ) --player:SendConsoleCommand("inv.giveall \"wood\" 7500") --player:SendConsoleCommand("inv.giveall \"stones\" 3000") --player:SendConsoleCommand("inv.giveall \"metal_ore\" 1000") --player:SendConsoleCommand("inv.giveall \"sulfur_ore\" 1000") --player:SendConsoleCommand("inv.giveall \"wolfmeat_raw\" 5") self.Config.Settings.giveAwayAvailable = false self:SaveConfig() else print("not time to hh. start "..hhStart) print("not time to hh. end "..hhEnd) print("not time to hh. cur "..curH) end end---------------------------------------------- --Give away random resources on manual command --ITEMS ARE HARDCODED, no cfg function PLUGIN:GiveAwayManual( player ) --TODO chk for admin --rust.BroadcastChat(self.Config.Settings.ChatPrefix, self.Config.Messages.hhrnd ) print("Пришло время случайных подарков всем игрокам_TEST") local index = math.random(0,4) if index == 1 then print("syringe_medical 1, gunpowder 10, lock.code 1") --syringe_medical 1 --gunpowder 10 --lock.code 1 elseif index == 2 then print("ammo_rifle 10, wolfmeat_cooked 2, jacket_snow3 1") --ammo_rifle 10 --wolfmeat_cooked 2 --jacket_snow3 1 else print("largemedkit 1,lantern 1,trap_bear 1") --largemedkit 1 --lantern 1 --trap_bear 1 end --rust.BroadcastChat("AZbuka SERVER", "На сервере время случайных подарков ;)" ) --player:SendConsoleCommand("inv.giveall \"metal_fragments\" 100") --player:SendConsoleCommand("inv.giveall \"sulfur\" 500") --player:SendConsoleCommand("inv.giveall \"charcoal\" 500") --player:SendConsoleCommand("inv.giveall \"wolfmeat_cooked\" 4") end -- -------------------------------------- -- reset status of giveaway. for debug only function PLUGIN:GiveOn( player ) if (player.net.connection.authLevel == 0) then rust.SendChatMessage(player, self.Config.Settings.ChatPrefix, self.Config.Messages.forbidden) return end self.Config.Settings.giveAwayAvailable = true self:SaveConfig() end-- ------------------------------------------------- function PLUGIN:FormatString(Text, Parameter, Value) return string.gsub(Text, Parameter, Value) end -- -------------------------------- -- admin permission check -- -------------------------------- local function IsAdmin(player) return player:GetComponent("BaseNetworkable").net.connection.authLevel > 0 end
Last edited by a moderator: Feb 5, 2015 -
Wulf Community Admin