Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Level-Mute (https://forums.graalonline.com/forums/showthread.php?t=134264038)

Supaman771 07-30-2011 08:19 PM

Level-Mute
 
Well, Era's Battle of the Bands is today and we were discussing that spamming could disrupt the event, or lag the level more (since there's going to be a bunch of people there).
So I made this simple toggle-able level mute NPC to throw down and solve the problem.
He said he wouldn't use it because the Timeout would "Lag the server".
I don't understand how? So if anyone could explain... as well as comment on how I could possibly code this better?
Thanks:
PHP Code:

function onCreated()
{
  
setTimer0.05 );
  
this.on 0;
}

//#CLIENTSIDE
functon onPlayerEnters()
{
  if ( 
this.on == )
  {
    if ( 
player.guild != "Judge" || player.guild != "Preformer" )
    {
      
player.chat "...";
    }
  }
 
setTimer0.05 );
}

function 
onPlayerChats()
{
  if ( 
player.guild == "Judge" )
  {
    if ( 
player.chat == ":muteon" )
    {
      
this.on 1;
      
player.chat "Level-Mute Enabled";
    }
    elseif ( 
player.chat == ":muteoff" )
    {
      
this.on 0;
      
player.chat "Level-Mute Disabled"
    
}
  }
  if ( 
this.on == )
  {
    if ( 
player.guild != "Judge" || player.guild != "Preformer" )
    {
      if ( 
player.chat != "..." )
      {
        
player.chat "...";
      }
    }
  }
 
setTimer0.05 );
}

function 
onTimeout()
{
  if ( 
this.on == )
  {
    if ( 
player.guild != "Judge" || player.guild != "Preformer" )
    {
      
player.chat "...";
    }
  }
 
setTimer0.05 );



cbk1994 07-30-2011 08:27 PM

The first step to making it better is to lose that terrible styling.

PHP Code:

function onCreated() {
  
setTimer(0.05);
  
this.on 0;
}

//#CLIENTSIDE
functon onPlayerEnters() {
  if (
this.on == 1) {
    if (
player.guild != "Judge" || player.guild != "Preformer") {
      
player.chat "...";
    }
  }
  
setTimer(0.05);
}

function 
onPlayerChats() {
  if (
player.guild == "Judge") {
    if (
player.chat == ":muteon") {
      
this.on 1;
      
player.chat "Level-Mute Enabled";
    }
    elseif(
player.chat == ":muteoff") {
      
this.on 0;
      
player.chat "Level-Mute Disabled"
    
}
  }
  if (
this.on == 1) {
    if (
player.guild != "Judge" || player.guild != "Preformer") {
      if (
player.chat != "...") {
        
player.chat "...";
      }
    }
  }
  
setTimer(0.05);
}

function 
onTimeout() {
  if (
this.on == 1) {
    if (
player.guild != "Judge" || player.guild != "Preformer") {
      
player.chat "...";
    }
  }
  
setTimer(0.05);


You misspelled function in "onPlayerEnters". In addition, there's no need for a timeout anywhere. You also misspelled "Performer" twice.

You can't have the toggle bit on clientside, as then it only applies for the specific player.

PHP Code:

function onPlayerChats() { // player chats
  
if (player.guild == "Judge") { // can control the level
    
if (player.chat == ":muteon") {
      
this.muteOn true;
      
player.chat "Mute On";
    } else if (
player.chat == ":muteoff") {
      
this.muteOn false;
      
player.chat "Mute Off";
    }
  } else if (
this.muteOn && player.guild != "Performer") {
    
// it's on and player is not a judge or performer
    
player.chat "...";
  }
}

function 
onPlayerEnters() {
  
this.onPlayerChats(); // call this in case people enter with chat


Does that make sense? All taken care of serverside, with events.

fowlplay4 07-30-2011 08:31 PM

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);
  }



Supaman771 07-30-2011 08:32 PM

Quote:

Originally Posted by cbk1994 (Post 1660911)
Does that make sense?

And that's why you're a scripter and I'm not.
Makes enough sense I suppose :3.. Thanks.

@fp4: Thank you too, its always good to see it done multiple ways. (I didn't like Chris' anyway).

cbk1994 07-30-2011 08:33 PM

Quote:

Originally Posted by Supaman771 (Post 1660913)
And that's why you're a scripter and I'm not.
Makes enough sense I suppose :3

Use Jer's, his will work better since it's handling the no chat bit clientside (but still storing the toggle variable serverside). Make sure to add something for onPlayerEnters, though.

fowlplay4 07-30-2011 08:50 PM

I've updated it to include the best of both worlds, for those relentless hackers who would spend the time to try and get around a mute filter.


All times are GMT +2. The time now is 10:37 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.