# Author: Yisc[NL] # # Lapper version needed: 7.0.4.8 or above # # # # Announcement messages V1.01 14-10-17 -Initial release # ################################################################################################################################################################################# CatchEvent OnLapperStart() OnLapperStart_Announcement_messages(); EndCatchEvent CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirtsSpace = indexOf( $text, " "); IF( $idxOfFirtsSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirtsSpace ); $argv = trim( subStr( $text,$idxOfFirtsSpace ) ); ENDIF SWITCH( $command ) CASE "!msgint": Message_interval( $KeyFlags ); BREAK; ENDSWITCH EndCatchEvent Sub OnLapperStart_Announcement_messages() ### Declare GlobalVar(s) ### GlobalVar $msg_int_version; GlobalVar $interval; GlobalVar $array_message_interval; GlobalVar $array_nbr; GlobalVar $count_array_message_interval; GlobalVar $line_number; $msg_int_version="V1.01"; $array_nbr=0; $line_number=0; ### End ### EndSub Sub Message_interval ( $KeyFlags ) ### Set initial values for left/right and top/bottom coordinates ### $left_right_handicap = 70; $top_bottom_handicap = 84; ### End ### openPrivButton( "message_interval_gui_bg",$left_right_handicap,$top_bottom_handicap,60,32,5,-1,16,""); openPrivButton( "message_interval_title",$left_right_handicap+1,$top_bottom_handicap+1,58,5,5,-1,32,"^7Message interval GUI - " . $msg_int_version ); openPrivButton( "message_interval",$left_right_handicap+1,$top_bottom_handicap+11,37,5,5,-1,32,"^7Message interval in seconds:" ); IF ( $interval == "" ) THEN openPrivTextButton( "set_message_interval",$left_right_handicap+38,$top_bottom_handicap+11,20,5,5,32,"^3Set interval in seconds (a value above 60, will be rounded to minutes)","^3Set interval",4,config_message_interval ); ELSE openPrivTextButton( "set_message_interval",$left_right_handicap+38,$top_bottom_handicap+11,20,5,5,32,"^3Set interval in seconds (a value above 60, will be rounded to minutes)","^3".$interval,4,config_message_interval ); ENDIF openPrivButton( "cancel_announcements",$left_right_handicap+1,$top_bottom_handicap+21,58,5,5,-1,32,"^1Cancel message announcements",cancel_message_announcements ); openPrivButton( "close_message_interval_gui",$left_right_handicap+1,$top_bottom_handicap+26,58,5,5,-1,32,"^3Close message interval GUI",close_message_interval_gui ); EndSub Sub config_message_interval ( $id,$text ) ### Check if a value is entered AND if entered value is a numeric value ### IF ( $text != "" && IsNum ( $text ) == 1 ) THEN $interval = ToNum ( $text ); ### Code to be executed when $interval is set to a value equal to or above 60 ### IF ( $interval >= 60 ) THEN ### Count number of values in array $array_message_interval ### ### If amount of numbers is above 0, loop through array $array_message_interval to remove scheduled actions and clear values from array $array_message_interval ### ### Set $array_nbr back to 0 ### $count_array_message_interval = arrayCount( $array_message_interval ); IF ( ToNum ( $count_array_message_interval ) > 0 ) THEN FOR ( $i=0;$i<$count_array_message_interval;$i=$i+1 ) RemoveScheduleAction( "announce_message_" . $i ); unSet( $array_message_interval[1,$i] ); ENDFOR $array_nbr=0; ENDIF ### End ### ### Find the number of minutes by deviding $interval by 60 and round that value to a number without decimals ### $minutes = round ( $interval / 60 , 0 ); ### End ### ### Start $minute at 0, check if it's below or equal to 59 and if so, raise $minute with the value set in $minutes ### ### Put $minute into array $array_message_interval ### ### Register a scheduled action for $minute ### ### Raise $array_nbr by 1 ### FOR ( $minute=0;$minute<=59;$minute=$minute+$minutes ) $array_message_interval[1,$array_nbr] = "".$minute; ### Syntax: ss mm hh dayofweek dd MM YYYY ### RegisterScheduleAction( "announce_message_" . $array_nbr,"* " . $minute . " * * * * *", announce_message ); $array_nbr = $array_nbr + 1; ENDFOR ### End ### ### End ### ### Code to be executed when $interval is set to a value below 60 ### ELSE ### Count number of values in array $array_message_interval ### ### If amount of numbers is above 0, loop through array $array_message_interval to remove scheduled actions and clear values from array $array_message_interval ### ### Set $array_nbr back to 0 ### $count_array_message_interval = arrayCount( $array_message_interval ); IF ( ToNum ( $count_array_message_interval ) > 0 ) THEN FOR ( $i=0;$i<$count_array_message_interval;$i=$i+1 ) RemoveScheduleAction( "announce_message_" . $i ); unSet( $array_message_interval[1,$i] ); ENDFOR $array_nbr=0; ENDIF ### End ### ### Start $seconds at 0, check if it's below or equal to 59 and if so, raise $seconds with the value set in $interval ### ### Put $seconds into array $array_message_interval ### ### Register a scheduled action for $seconds ### ### Raise $array_nbr by 1 ### FOR ( $seconds=0;$seconds<=59;$seconds=$seconds+$interval ) $array_message_interval[1,$array_nbr] = "".$seconds; ### Syntax: ss mm hh dayofweek dd MM YYYY ### RegisterScheduleAction( "announce_message_" . $array_nbr,"".$seconds . " * * * * * *", announce_message ); $array_nbr = $array_nbr + 1; ENDFOR ### End ### ENDIF ### End ### ### Go back to Sub Message_interval ### Message_interval ( $KeyFlags ); ### End ### ELSE ### Notify user that no value has been entered or that the value isn't numeric ### PrivMsg ( "^1WARNING: ^7No value is entered or value isn't numeric" ); ### End ### ENDIF EndSub Sub announce_message() $Filename = "announcements"; $Folder = "D:\LFSLapper V7.0.4.8\bin\includes"; $Extension = ".txt"; $LinesofFile = Readfile($Filename,$Folder,$Extension); $NrOfLines = ToNum($LinesofFile["NumberOfLines"]); IF ( $line_number < $NrOfLines ) THEN $linenr = $LinesofFile[$line_number,"LineNumber"]; $line = $LinesofFile[$line_number,"Line"]; GlobalMsg ( "" . $line ); $line_number = $line_number + 1; IF ( $line_number == $NrOfLines ) THEN $line_number=0; ENDIF ENDIF EndSub Sub cancel_message_announcements ( $KeyFlags,$id ) $count_array_message_interval = arrayCount( $array_message_interval ); IF ( ToNum ( $count_array_message_interval ) > 0 ) THEN FOR ( $i=0;$i<$count_array_message_interval;$i=$i+1 ) RemoveScheduleAction( "announce_message_" . $i ); unSet( $array_message_interval[1,$i] ); ENDFOR $array_nbr=0; ENDIF $interval=""; $line_number=0; PrivMsg ( "^7INFO: Announcement of messages has been canceled" ); Message_interval ( $KeyFlags ); EndSub Sub close_message_interval_gui ( $KeyFlags,$id ) closePrivButton ( "message_interval_gui_bg" ); closePrivButton ( "message_interval_title" ); closePrivButton ( "message_interval" ); closePrivButton ( "set_message_interval" ); closePrivButton ( "cancel_announcements" ); closePrivButton ( "close_message_interval_gui" ); EndSub