-- motd - Main data and logic of MOTD -- (component of MOTD) -- Template attachment: none -- Created by: Patrick Ferland -- Created on: 08/01/2008 -- Revision History -- 08/01/2008 P.Ferland - New script -- 08/11/2008 P.Ferland - Added timestamp-update conditions -- 08/19/2008 P.Ferland - Included Brooke/chooseareality's BR tag support -- 11/13/2008 P.Ferland - Converted labels to TextBox to allow link support and added OX friendliness -- Constants LAYOUT = { W = 300, H = 200, MESSAGE = { X = 8, Y = 30, W = 284, }, LINK = { X = 8, W = 284, H = 36 } } -- Estimated characters per line LINE_LENGTH_APPROX = 45 LINE_HEIGHT = 15 -- Script properties Define Properties() script_description = 'Message of the Day' script_long_description = 'Configure a message and optional web link to display to users when they log in to your world.' motd_enabled = 1 ExposeProperty('motd_enabled', 'Display MOTD on login?', 'checkbox') PersistProperty('motd_enabled') motd_message = 'Welcome to the world!' ExposeProperty('motd_message', 'Message of the Day') PersistProperty('motd_message') motd_link_display = 1 ExposeProperty('motd_link_display', 'Display link on MOTD?', 'checkbox') PersistProperty('motd_link_display') motd_link_title = 'Visit Metaplace today!' ExposeProperty('motd_link_title', 'MOTD link title') PersistProperty('motd_link_title') motd_link_url = 'http://www.metaplace.com/' ExposeProperty('motd_link_url', 'MOTD link location') PersistProperty('motd_link_url') motd_display_always = 0 ExposeProperty('motd_display_always', 'Always display MOTD? (If no, displays only when changed)', 'checkbox') PersistProperty('motd_display_always') motd_message_timestamp = 1 PersistProperty('motd_message_timestamp') IncludeScript('13197:21') -- ui_library end -- Triggers Trigger param_changed(caller, user_id, script_id, name, value) if ( script_id == '13321:25') then if ( (name == 'motd_message') or (name == 'motd_link_display') or (name == 'motd_link_title') or (name == 'motd_link_url') ) then self.motd_message_timestamp = os.time() SaveToDb(self) end end end Trigger motd_display(user) local display_motd = 1 if (self.motd_enabled == 0) then display_motd = 0 end if (self.motd_display_always ~= 1) then if (user.motd_last_viewed == self.motd_message_timestamp) then display_motd = 0 end end if (display_motd == 1) then local text_height = (math.ceil(string.len(self.motd_message) / LINE_LENGTH_APPROX) + 1) * LINE_HEIGHT + 2 if (text_height < 24) then text_height = 24 end local break_count = get_break_count(self.motd_message) if break_count > 1 then text_height = text_height + ((break_count - 1) * LINE_HEIGHT ) end local link_height = 0 local link_padding = 0 if (self.motd_link_display == 1) then link_height = 24 link_padding = 6 end -- title + padding + text + padding + link + link_padding + bottom local motd_height = 24 + 6 + text_height + 6 + link_height + link_padding + 2 local motd = ui_default_window(0, 'motd', 0, 0, LAYOUT.W, motd_height) UiAlign(motd, 0, 0, 'center', 'scale_none') UiAttachUser(user, motd) local motd_title = UiTextBox(motd, 'motd_title', 8, 0, LAYOUT.W - 30, 24, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0) UiText(motd_title, 'Message of the Day') local motd_text = UiTextBox(motd, 'motd_text', LAYOUT.MESSAGE.X, LAYOUT.MESSAGE.Y, LAYOUT.MESSAGE.W, text_height, 96, 96, 96, 255, 255, 255, 0, 0, 0, 0) UiText(motd_text, '' .. self.motd_message .. '') if (self.motd_link_display == 1) then local link_y = 24 + 6 + text_height + 6 local motd_link= UiTextBox(motd, 'motd_link', LAYOUT.LINK.X, link_y, LAYOUT.LINK.W, LAYOUT.LINK.H, 96, 96, 96, 255, 255, 255, 0, 0, 0, 0) UiText(motd_link, '' .. self.motd_link_title .. '') -- NOTE: This is a weird hack. The link won't be clickable unless I add a second line (even if blank) to the text box. UiAddText(motd_link, '') end UiVisible(motd, 1) UiSort(motd, 'front') user.motd_last_viewed = self.motd_message_timestamp end end -- Local functions function get_break_count(message) local break_count = 0 if message then for match in string.gmatch(message,'<[bB][rR]%s*/?>') do break_count = break_count + 1 end end return break_count end