Thread: Level-Mute
View Single Post
  #3  
Old 07-30-2011, 08:31 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You can use ChatBar.onAction to prevent the player from chatting at all. I've re-factored your code:

PHP Code:
function onCreated() {
  
// Disable Muting
  
muteOff();
}

// Turns Mute Off
function muteOff() {
  
this.attr[2] = 0;
}

// Turns Mute On
function muteOn() {
  
this.attr[2] = 1;
  for (
temp.plplayers) {
    
temp.pl.chat "...";
  }
}

function 
isMuted() {
  
// Check if they're in a guild that can talk.
  
if (player.guild in {"Judge""Preformer"}) {
    
// Return false to indicate they aren't muted.
    
return false;
  } else {
    
// If attr[2] is equal to 1, the level is currently muted.
    
return (this.attr[2] == 1);
  }
}

// Silence people entering the level.
function onPlayerEnters() {
  if (
this.attr[2] == 1) {
    
player.chat " ";
  }
}

// Your original code moved to the server-side
// Restyled to my liking.
function onPlayerChats() {
  if (
player.guild == "Judge") {
    if (
player.chat == ":muteon") {
      
muteOn();
      
player.chat "Level-Mute Enabled";
    }
    else if ( 
player.chat == ":muteoff" ) {
      
muteOff();
      
player.chat "Level-Mute Disabled";
    }
  }
  else if (
isMuted()) {
    
player.chat "...";
  }
}

//#CLIENTSIDE

// This is called when the ChatBar's text is submitted.
// Called before onPlayerChats, so you can completely silence them before they chat.
// Compared to the server-side where you might see a flicker of chat.
function ChatBar.onAction() {
  
// Check if muted.
  
if (isMuted()) {
    
// Clear ChatBar text if they're muted.
    
ChatBar.text "";
  }
}

function 
isMuted() {
  
// Check if they're in a guild that can talk.
  
if (player.guild in {"Judge""Preformer"}) {
    
// Return false to indicate they aren't muted.
    
return false;
  } else {
    
// If attr[2] is equal to 1, the level is currently muted.
    
return (this.attr[2] == 1);
  }

__________________
Quote:

Last edited by fowlplay4; 07-30-2011 at 08:49 PM.. Reason: Updated to add server-side check too.
Reply With Quote