Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-30-2011, 08:19 PM
Supaman771 Supaman771 is offline
Posting The Truth
Supaman771's Avatar
Join Date: Feb 2008
Posts: 1,694
Supaman771 is a glorious beacon of lightSupaman771 is a glorious beacon of lightSupaman771 is a glorious beacon of light
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 );

__________________
Reply With Quote
  #2  
Old 07-30-2011, 08:27 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #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
  #4  
Old 07-30-2011, 08:32 PM
Supaman771 Supaman771 is offline
Posting The Truth
Supaman771's Avatar
Join Date: Feb 2008
Posts: 1,694
Supaman771 is a glorious beacon of lightSupaman771 is a glorious beacon of lightSupaman771 is a glorious beacon of light
Quote:
Originally Posted by cbk1994 View Post
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).
__________________
Reply With Quote
  #5  
Old 07-30-2011, 08:33 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Supaman771 View Post
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.
__________________
Reply With Quote
  #6  
Old 07-30-2011, 08:50 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
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.
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:44 PM.


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