• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent [TFS 1.0] Simple event tracker + channel

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,694
Location
Poland
This simple script allows you to configure all server events in one script and let people know what events will be running soon.

qp5q14.png


Do not post that script on other forums without my permission

Firstly: This isn't made for newbies. If you can't configure server events yourself, this script may only make it even harder.

Secondly: I don't have time to improve this script so it's up to you.


Globalevents.xml:
Code:
<globalevent name="event calendar" interval="60000" script="event_calendar.lua"/>

event_calendar.lua:
Code:
events_calendar = {
   channel_id = 32, -- channel to post event news. Use broadcastMessage function if you want this stuff to be posted on local chat or server log
   [1] = { -- mon
   
   },
   [2] = { -- tue
     [7] = {{8, true}}, -- 7 am
     [14] = {{1, arg}, {3, arg}} -- 2 pm -- [hour] = {{event1, function arguments(to do)}}
   },
   [3] = { -- wed
 
   },
   [4] = { -- thu
 
   },
   [5] = { -- fri
 
   },
   [6] = { -- sat
 
   },
   [0] = { -- sun
 
   }
}

events_calendar_list = {
   [1] = "extra exp",
   [2] = "extra loot",
   [3] = "random gift",
   [4] = "sheep",
   [5] = "raining fire",
   [6] = "hardcore dungeon",
   [7] = "zombie survival",
   [8] = "pvp-party",
   [9] = "castle war(region 1)",
   [10] = "castle war(region 2)",
   [11] = "castle war(region 3)"
}

function doExecuteScheduledEvent(day, hour, id)
   if id == 8 then
     sendChannelMessage(events_calendar.channel_id, TALKTYPE_CHANNEL_O, "[Notice]: Pvp party arena is open!")
     -- open arena or whatever
     return true
   end
end

function onThink(interval)
   if events_calendar[tonumber(os.date("%w"))] ~= nil then
     if tonumber(os.date("%M")) == 59 then
       if tonumber(os.date("%S")) >= 30 then
         if events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H")) + 1] ~= nil then
           for i = 1, #events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H")) + 1] do
             doExecuteScheduledEvent(events_calendar[tonumber(os.date("%w"))], tonumber(os.date("%H")) + 1, i)
           end
         end
       end
       return true
     elseif tonumber(os.date("%M")) == 0 then
       if tonumber(os.date("%S")) < 30 then
         if events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H"))] ~= nil then
           for i = 1, #events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H"))] do
             doExecuteScheduledEvent(events_calendar[tonumber(os.date("%w"))], tonumber(os.date("%H")), i)
           end
         end
       end
       return true
     else
       -- if tonumber(os.date("%S")) == 30 then -- message only 30 minutes before event
         if events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H")) + 1] ~= nil then
           if #events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H")) + 1] > 0 then
             s_events_list = {}
             for i = 1, #events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H")) + 1] do
               table.insert(s_events_list, events_calendar_list[events_calendar[tonumber(os.date("%w"))][tonumber(os.date("%H")) + 1][i][1]])
             end
             local m = 60 - tonumber(os.date("%M"))
             sendChannelMessage(events_calendar.channel_id, TALKTYPE_CHANNEL_O, "[Notice]: Upcoming events: " .. table.concat(s_events_list, ", ") .. " (" .. m .. " minute" .. (m > 1 and "s" or "") .. " left).")
           end
         end
       -- end
       return true
     end
   end
end

chatchannels.xml:
Code:
<channel id="32" name="Events" public="1" script="events.lua" />

events.lua:
Code:
local muted = createConditionObject(CONDITION_CHANNELMUTEDTICKS)
setConditionParam(muted, CONDITION_PARAM_SUBID, 32)
setConditionParam(muted, CONDITION_PARAM_TICKS, 1000)

function send_d_motd(cid)
   return Creature(cid):sendChannelMessage("", "[Channel]: Welcome to the event channel. Here you may talk about in-game events and receive news about their status.", TALKTYPE_CHANNEL_O, 32)
end

function onJoin(cid)
   addEvent(send_d_motd, 100, cid)
   return true
end

function onSpeak(cid, type, message)
   if getCreatureCondition(cid, CONDITION_CHANNELMUTEDTICKS, 32) then
     Creature(cid):sendChannelMessage("", "Please do not spam.", TALKTYPE_CHANNEL_O, 32)
     return false
   end
   doAddCondition(cid, muted)
   if getPlayerAccountType(cid) > 2 then
     if getPlayerGroupId(cid) > 2 then
       local groupnames = {[2] = "Mod", [3] = "Admin"}
       sendChannelMessage(32, TALKTYPE_CHANNEL_R1, getCreatureName(cid) .. " [" .. (groupnames[getPlayerGroupId(cid)] or "GM") .. "]: ".. message)
       return false
     end
   end
   return TALKTYPE_CHANNEL_Y
end
 
Last edited:
I will be creating some interesting things with this, hopefully. ;)

Kind Regards,
Eldin
.
 
Can you help me to set an specific hour to a event cast channel ?

Sorry sorry for disturb...
 
Getting this error on tfs 1.2
c4b21c8e1ec07afa03743a735b813175.png
 
Getting this error on tfs 1.2
c4b21c8e1ec07afa03743a735b813175.png

Try changing:
Code:
function onJoin(cid)
   addEvent(send_d_motd, 100, cid)
   return true
end
to:
Code:
function onJoin(cid)
   local player = Player(cid)
   addEvent(send_d_motd, 100, player:getId())
   return true
end
 
Try changing:
Code:
function onJoin(cid)
   addEvent(send_d_motd, 100, cid)
   return true
end
to:
Code:
function onJoin(cid)
   local player = Player(cid)
   addEvent(send_d_motd, 100, player:getId())
   return true
end

Thank you kind sir. I will write songs about your bravery.
 
Does anyone knows how to fix this script? I'm just hopeless about it, it always return a wrong event id >_<
 
When I get into work I'll help you out my love ;)
 
Back
Top