CatchEvent OnConnect( $userName ) # Player event OnConnect_Teamchat(); EndCatchEvent CatchEvent OnLapperStart() OnLapperStart_Teamchat(); 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 "!teamchat": IF( UserInGroup( "tofus",$userName ) == 1 ) THEN open_chat_panel ( 0,0 ); ELSE privmsg("Only for members!"); ENDIF BREAK; ENDSWITCH EndCatchEvent Sub OnLapperStart_Teamchat() ### Set GlobalVar's to be used for the message array ### GlobalVar $message_array; GlobalVar $count_message_array; EndSub Sub OnConnect_Teamchat() # Player event ### Load usernames from file tofus.txt ### UserGroupFromFile( "tofus", "/tofus.txt" ); ### Check if username is found in group tofus ### IF ( UserInGroup( "tofus",GetCurrentPlayerVar( "UserName" ) ) == 1 ) THEN openPrivButton( "open_chat_panel",1,148,8,4,3,-1,ISB_NONE,"^7Team%nl%^7Chat",open_chat_panel ); ENDIF EndSub Sub open_chat_panel ( $KeyFlags, $id ) closePrivButton ("open_chat_panel"); IF ( UserInGroup( "tofus",GetCurrentPlayerVar( "UserName" ) ) == 1 ) THEN $count_message_array = arrayCount( $message_array ); openPrivButton( "refresh_chat_panel",10,156,180,8,8,30,ISB_DARK,"^7Refresh (%cpt%)",open_chat_panel ); openPrivButton( "close_chat_panel",10,164,180,8,8,-1,ISB_DARK,"^3Close",close_chat_panel ); ### Set initial values for top/bottom coordinates , Set $counter to 1 ### $top_bottom_messages = 140; $counter=1; ### End ### openPrivTextButton( "sendmessage",10,148,180,8,8,32+64,"Team Chat","^3Write message...",120,teammessage ); ### Start displaying the latest 10 messages found in the message array ### FOR ($i=$count_message_array;$i>=1;$i=$i-1) IF ($counter <= 10) THEN openPrivButton( "chat_history_".$i,10,$top_bottom_messages,180,8,8,-1,ISB_DARK+64,$message_array[1,$i],"" ); $top_bottom_messages=$top_bottom_messages-8; $counter=$counter+1; ENDIF ENDFOR ENDIF EndSub Sub close_chat_panel ( $KeyFlags, $id ) $count_message_array = arrayCount( $message_array ); FOR ($i=$count_message_array;$i>=1;$i=$i-1) closePrivButton("chat_history_".$i); ENDFOR closePrivButton ("close_chat_panel&sendmessage&refresh_chat_panel"); openPrivButton( "open_chat_panel",1,148,8,4,3,-1,ISB_NONE,"^7Team%nl%^7Chat",open_chat_panel ); EndSub Sub teammessage ( $username,$teammsg ) $NickName = GetCurrentPlayerVar("NickName"); # closePrivButton("sendmessage"); openPrivButton( "open_chat_panel",1,158,8,4,3,-1,ISB_NONE,"^7Team%nl%^7Chat",open_chat_panel ); ### Count the number of messages in the message array ### $count_message_array = arrayCount( $message_array ); ### If message array is empty, set value to 1, so message is stored in the first field of the array ### ### If message array isn't empty, raise value by 1, so message is stored in the next empty field of the array ### IF ($count_message_array == 0) THEN $count_message_array=1; $message_array[1,$count_message_array] = $NickName . "^7: " . $teammsg; ELSE $count_message_array=$count_message_array+1; $message_array[1,$count_message_array] = $NickName . "^7: " . $teammsg; ENDIF $lop = GetListOfPlayers("N"); $NickName = GetCurrentPlayerVar("NickName"); FOREACH ( $de in $lop ) $tofuName = $de["value"]; privMsg ( $tofuName, "^7[^1•^7] Team Chat - " . $NickName); privMsg ( $tofuName, " ^6" . $teammsg); ENDFOREACH open_chat_panel( 0, 0 ); EndSub