Author Topic: Code help  (Read 2239 times)

1. Please indent.
2. Use kalphiter's code and make a extra arguement on the mute function for time, then make it schedule(%time*1000,"unmute"); etc to unmute them in those times.

Also kalphiter, you can use %1, etc, it just needs to be in single quote tags ('d').

Well, it doesn't syntax, but it doesn't stop them from talking either. I'm working on it...

« Last Edit: March 20, 2009, 11:51:51 AM by AGlass0fMilk »

Your format sucks. Use mine and tell me the syntax error your got.

Code: (Torque) [Select]
package mutePackage
{
    function servercmdMessageSent(%client, %text)
    {
if($mute::mute[%victim.player])
{
    messageClient(%client, '', '\c6You cannot talk while muted.');
    return;
}


else
    Parent::ServercmdmessageSent(%client, %text);
    }
};

The package should be that instead.

The mute part works, but now when I try to use the unmute command, it doesnt say anything, my format does not suck =( Ill put in the time thing and try to fix the unmute command.

-edit- The time thing sorta works, but when it says you are unmuted, you still cannot talk =/ Don't know why that is...
« Last Edit: March 19, 2009, 08:34:14 PM by AGlass0fMilk »

Here is the new code with time and stuff:
Code: [Select]
function servercmdMute(%client, %user, %time)
{
if(!%client.isSuperAdmin)
{
messageClient(%client, '', '\c6You must be a Super Admin to use this command');

return;
}
if(%user !$= "")
{
%victim = FindClientByName(%user);
$Mute[%victim] = true;
messageAll("", "\c3"@ %victim.name @"\c6 Has been muted by \c3"@ %client.name @"\c6 for "@ %time @" Seconds");
messageClient(%victim, '', "\c6You have been muted by \c3"@ %victim.name @"\c6 for "@ %time @" Seconds");
schedule(%time*1000,0,"unmute", %victim);
}}

function unmute(%victim)
{
$Mute[%victim] = false;
MessageClient(%victim, '', "\c6You are now unmuted");
}

function servercmdunmute(%client, %user)
{
if(!%client.isSuperAdmin)
{
messageClient(%client, '', '\c6You must be a super admin to use that command');

return;
}
if(%user !$= "")
{
%victim = FindClientByName(%user);
$Mute[%victim] = false;
messageClient(%victim, '', "\c6You have been unmuted by \c3"@ %client.name);
messageAll("\c3"@ %victim.name @" \c6has been unmuted by \c3"@ %client.name);
}}

package mute
{
function servercmdMessageSent(%client, %text)
{
if($mute::mute[%victim] = true)
{
messageClient(%client, '', '\c6You cannot talk while muted.');
}
else
{
Parent::ServercmdmessageSent(%client, %text);
}
}
};
ActivatePackage(mute);
Now for some reason, When it says you are unmuted, you aren't. And The un mute command doesn't work. I also had a question, how could I make it so when you don't type in a time, it doesn't say "Blah has been muted by blah for seconds." And you are permanently muted until you un mute them?

great, I'm muted on my own server forever until this is solved, its a global variable....

Quote
function servercmdMute(%client, %user, %time)
{
   if(!%client.isSuperAdmin)
   {
      messageClient(%client, '', '\c6You must be a Super Admin to use this command');  I'm still thinking you need a " mark in the message arguement. It may work with the single ones, though.
      return;
   }
   if(%user !$= "")
   {
      %victim = FindClientByName(%user); 
      $Mute[%victim] = true;  You should probably make this store on BLID so you can store it to a global variable and have it work how you want.
      messageAll("", "\c3"@ %victim.name @"\c6 Has been muted by \c3"@ %client.name @"\c6 for "@ %time @" Seconds");
      messageClient(%victim, '', "\c6You have been muted by \c3"@ %victim.name @"\c6 for "@ %time @" Seconds");
      You should cancel any previous unmute schedule before making a new one so you can change the mute time if you want.
      schedule(%time*1000,0,"unmute", %victim);

   }
}

function unmute(%victim)
{
   $Mute[%victim] = false;
   MessageClient(%victim, '', "\c6You are now unmuted");
}

function servercmdunmute(%client, %user)
{
   if(!%client.isSuperAdmin)
   {
      messageClient(%client, '', '\c6You must be a super admin to use that command');
   return;
   }
   if(%user !$= "")
   {
      %victim = FindClientByName(%user);
      $Mute[%victim] = false;
      messageClient(%victim, '', "\c6You have been unmuted by \c3"@ %client.name);
      messageAll("\c3"@ %victim.name @" \c6has been unmuted by \c3"@ %client.name);
   You should add a cancel for the unmute schedule here.
   }
}

package mute
{
   function servercmdMessageSent(%client, %text)
   {
      if($mute::mute[%victim] = true)  You used $mute[%victim] for storage, meaning trying to recall it like this would return an undefined value. You need to use == for if statements.
      {
         messageClient(%client, '', '\c6You cannot talk while muted.');
      }
      else
      {
          Parent::ServercmdmessageSent(%client, %text);
      }
   }
};
ActivatePackage(mute);

Thank you, I like the way you point out errors.

Well, here's the code, its still not working:
Code: [Select]
function servercmdMute(%client, %user, %time)
{
if(!%client.isSuperAdmin)
{
messageClient(%client, '', '\c6You must be a Super Admin to use this command');

return;
}
if(%user !$= "")
{
%victim = FindClientByName(%user);
$Mute[%victim.BLID] = true;
messageAll("", "\c3"@ %victim.name @"\c6 Has been muted by \c3"@ %client.name @"\c6 for "@ %time @"

Seconds");
messageClient(%victim, '', "\c6You have been muted by \c3"@ %victim.name @"\c6 for "@ %time @" Seconds");
schedule(%time*1000,0,"unmute", %victim);
}}

function unmute(%victim)
{
$Mute[%victim.BLID] = false;
MessageClient(%victim, '', "\c6You are now unmuted");
}

function servercmdunmute(%client, %user)
{
if(!%client.isSuperAdmin)
{
messageClient(%client, '', "\c6You must be a super admin to use that command");

return;
}
if($mute::mute[%victim.BLID] == false)
{
messageClient(%client, '', "\c6That player is not muted!");
return;
}
else
{
%victim = FindClientByName(%user);
$Mute[%victim.BLID] = false;
messageClient(%victim, '', "\c6You have been unmuted by \c3"@ %client.name);
messageAll("\c3"@ %victim.name @" \c6has been unmuted by \c3"@ %client.name);
cancel(unmute);
}}

package mute
{
function servercmdMessageSent(%client, %text)
{
if($mute::mute[%victim.BLID] == true)
{
messageClient(%client, '', "\c6You cannot talk while muted.");
}
else
{
Parent::ServercmdmessageSent(%client, %text);
}
}
};
ActivatePackage(mute);
The un mute command sorta works, but it only says the message to the person, and the mute part itself doesn't work anymore. When I put in the == it doesn't work, and when I only put in =, it mutes me forever and doesn't stop. WHAT IS WRONG WITH THE CODE.

Quote
function servercmdMute(%client, %user, %time)
{
   if(!%client.isSuperAdmin)
   {
      messageClient(%client, '', '\c6You must be a Super Admin to use this command');
      return;
   }
   if(%user !$= "")
   {
      %victim = FindClientByName(%user);
      $Mute[%victim.BLID] = true;
      messageAll("", "\c3"@ %victim.name @"\c6 Has been muted by \c3"@ %client.name @"\c6 for "@ %time @" Seconds");
      messageClient(%victim, '', "\c6You have been muted by \c3"@ %victim.name @"\c6 for "@ %time @" Seconds");
      schedule(%time*1000,0,"unmute", %victim);  Use something like $mute::Schedule[%victim.BLID] = schedule(arguements) to define a timed schedule.
   }
}

function unmute(%victim)
{
   $Mute[%victim.BLID] = false;
   MessageClient(%victim, '', "\c6You are now unmuted");
}

function servercmdunmute(%client, %user)
{
   if(!%client.isSuperAdmin)
   {
      messageClient(%client, '', "\c6You must be a super admin to use that command");
      return;
   }
   if($mute::mute[%victim.BLID] == false)  You are storing it to $mute[%victim], and recalling it with $mute::mute[%victim]. Ditch the ::mute.
   {
      messageClient(%client, '', "\c6That player is not muted!");
      return;
   }
   else
   {
      %victim = FindClientByName(%user);
      $Mute[%victim.BLID] = false;
      messageClient(%victim, '', "\c6You have been unmuted by \c3"@ %client.name);
      messageAll("\c3"@ %victim.name @" \c6has been unmuted by \c3"@ %client.name);
      cancel(unmute); If you followed my earlier advice, this would be cancel($mute::Schedule[%Victim.BLID]);
   }
}

package mute
{
   function servercmdMessageSent(%client, %text)
   {
      if($mute::mute[%victim.BLID] == true)  Same as above. Ditch the ::mute. The reason you end up muted if you set it to = is that it always returns true from the definition.
      {
         messageClient(%client, '', "\c6You cannot talk while muted.");
      }
      else
      {
          Parent::ServercmdmessageSent(%client, %text);
      }
   }
};
ActivatePackage(mute);

Conversation over
"Help with muting script"
Or even better, "Muting Script"

You declared two different vars.

$Mute::mute

Or

$mute



A package will not affect names of variables.

Well, I tested it, and it mutes who ever uses it with the target, here is the code:
Code: [Select]
if(isFile("Add-Ons/System_ReturnToBlockland/server.cs"))
{
if(!$RTB::RTBR_ServerControl_Hook)

exec("Add-Ons/System_ReturnToBlockland/RTBR_ServerControl_Hook.cs");
RTB_registerPref("Mute Command","Server Commands","Mute::Users","list SuperAdmin 1 Admins 2 Host 3", "Mute Command","1", 0, 1);
}
else
{
$Mute::Users = "1";
}
function servercmdMute(%client, %user, %time)
{

if($Mute::Users == 1 && !%client.isSuperAdmin)
{

messageClient(%client, '', '\c6You must be a super admin to use this command.');

return;
}
if($Mute::Users == 2 && !%client.isAdmin)
{

messageClient(%client, '', '\c6You must be an Admin to use this command.');

return;
}
if($Mute::Users == 3 && !((isObject(localclientconnection) && %client.getID() == localclientconnection.getID())) || !%client.bl_id == getNumKeyID())
{

messageClient(%client, '', '\c6You must be the Host to use this command.');

return;
}
if(%time =="")
{
%victim = FindClientByName(%user);
$Mute[%victim.BLID] = true;
messageAll("", "\c3"@ %victim.name @"\c6 has been muted by \c3"@ %client.name);
messageClient(%victim, '', "\c6You have been muted by \c3"@ %client.name);
cancel($mute::schedule[%victim.BLID]);
}
else
{
%victim = FindClientByName(%user);
$Mute[%victim.BLID] = true;
messageAll("", "\c3"@ %victim.name @"\c6 Has been muted by \c3"@ %client.name @"\c6 for "@ %time @" Seconds");
messageClient(%victim, '', "\c6You have been muted by \c3"@ %Client.name @"\c6 for "@ %time @" Seconds");
Cancel($mute::Schedule[%victim.BLID]);
$mute::Schedule[%victim.BLID] = schedule(%time*1000,0,"unmute", %victim);
}}

function unmute(%victim)
{
$Mute[%victim.BLID] = false;
MessageClient(%victim, '', "\c6You are now unmuted");
}

function servercmdunmute(%client, %user)
{

if($Mute::Users == 1 && !%client.isSuperAdmin)
{

messageClient(%client, '', '\c6You must be a super admin to use this command.');

return;
}
if($Mute::Users == 2 && !%client.isAdmin)
{

messageClient(%client, '', '\c6You must be an Admin to use this command.');

return;
}
if($Mute::Users == 3 && !((isObject(localclientconnection) && %client.getID() == localclientconnection.getID())) || !%client.bl_id == getNumKeyID())
{

messageClient(%client, '', '\c6You must be the Host to use this command.');

return;
}
if($mute[%victim.BLID] == false)
{
messageClient(%client, '', "\c6That player is not muted!");
return;
}
else
{
%victim = FindClientByName(%user);
$Mute[%victim.BLID] = false;
messageClient(%victim, '', "\c6You have been unmuted by \c3"@ %client.name);
messageAll("", "\c3"@ %victim.name @" \c6has been unmuted by \c3"@ %client.name);
cancel($mute::Schedule[%victim.BLID]);
}}

package mute
{
function servercmdMessageSent(%client, %text)
{
if($mute[%victim.BLID] == true)
{
messageClient(%client, '', "\c6You cannot talk while muted.");
}
else
{
Parent::ServercmdmessageSent(%client, %text);
}
}
};
ActivatePackage(mute);
Now I don't know why this is, but I would like to know how to fix this, is it a problem with storing it on the BLID?
-edit-
It doesn't mute just those people, it mutes everyone in the server!
« Last Edit: March 21, 2009, 11:07:51 PM by AGlass0fMilk »