Author Topic: My script wont work for some reason!  (Read 1905 times)

I am having problems.

  • When I whisper to someone, they recieve the message with a bunch of spaces after it.
  • If someone does not exist, it sends it anyway.
  • If I say /whisper without anything after it, it tells me I have no benefit whispering to yourself.
Code: [Select]
package whisperinfo
{
function gameconnection::oncliententergame(%client)
{
if($whisenabled == 1)
{
messageclient(%client, '',"<color:FFFFFF>This server is running Deriboy's Whisper script. It is currently <color:00FF00>enabled.<color:FFFFFF> Type /whisperhelp for help using it.");
Parent::onClientEnterGame(%client);
}

else
{
messageclient(%client, '',"<color:FFFFFF>This server is running Deriboy's Whisper script. It is currently \c0disabled.<color:FFFFFF> Type /whisperhelp for help using it.");
Parent::onClientEnterGame(%client);
}
}
};
activatepackage(whisperinfo);

function servercmdwhisperhelp(%client)
{
messageclient(%client, '',"Type /whisper [target] [message] to whisper to someone in the server.");
messageclient(%client, '',"Admins can type /enablewhisper to enable whispering, or /disablewhisper to disable whispering.");
}

function servercmddisablewhisper(%client)
{
if(%client.isAdmin)
{
if($whisenabled == 0)
{
messageclient(%client, '',"\c0Whispering is already disabled!");
}

else
{
messageall('',"\c0Whispering is now disabled.");
$whisenabled = 0;
}
}

else
{
messageclient(%client, '',"You must be an admin to disable whispering.");
}
}

function servercmdenablewhisper(%client)
{
if(%client.isAdmin)
{
if($whisenabled == 1)
{
messageclient(%client, '',"\c0Whispering is already enabled!");
}

else
{
messageall('',"<color:00FF00>Whispering is now enabled.");
$whisenabled = 1;
}
}

else
{
messageclient(%client, '',"You must be an admin to enable whispering.");
}
}

function servercmdwhisper(%client, %name, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25)
{
if($whisenabled == 1)
{
%i = 0;
%found = 0;
while(%i < Clientgroup.getcount())
{
%investigate = clientgroup.getobject(%i);
%searchname = findclientbyname(%name);
if(striPos(%investigate.name, %searchname.name) != -1)
{
%found++;
}
%i++;

}
echo(%searchname.name);
echo(%found);
if(%found != 0)
{
if(%found == 1)
{
if(%client != %searchname)
{
if(%name != -1)
{
%msg = %a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25;
messageclient(%searchname, '',"<color:FFFFFF>From " @ %client.name @ ": " @ %msg);
messageclient(%client, '', "<color:00FF00>" @ %msg @ "<color:FFFFFF> was sent to " @ %searchname.name);
}

else
{
messageclient(%client, '',"Please enter a name to whisper to");
}
}

else
{
messageclient(%client, '',"Whispering to yourself has no benefit.");
}
}

else
{
messageclient(%client, '',"More than one people in this server have <color:FFFFFF>" @ %name @ " \c0in their name. Try being more specific.");
}
}

else
{
messageclient(%client, '',"There are no players in this server with <color:FFFFFF>" @ %name @ " \c0in their name.");
}
}

else
{
messageclient(%client, '',"Whispering is currently disabled.");
}
}
« Last Edit: January 03, 2010, 10:14:15 PM by Deriboy »

Code: [Select]
messageclient(%client, '', "<color:FFFFFF>Please type in a name to whisper to."
=
Code: [Select]
messageclient(%client, '', "<color:FFFFFF>Please type in a name to whisper to.");
?
I dont know if thats correct, But thats what it looks like.


Wow. how did I not notice that. D:

I guess its because I'm a new scripter and I don't know to look for these types of things.
« Last Edit: November 04, 2009, 08:31:54 AM by Deriboy »

How do you get the number of clients with certain letters in their name?
This code will do it.
Code: [Select]
for(%i = 0; %i < clientGroup.getCount(); %i++) // Loop through all clients
{
   %client = clientGroup.getObject(%i); // Sets the client we are currently investigating
   %name = %client.getPlayerName();
   if(strPos(%name, "SEARCHCHARACTERS") != -1) // SEARCHCHARACTERS is within the name
   {
      %found++; // Add 1 to %found
   }
}
echo(%found); // Echo final number of clients with SEARCHCHARACTERS in their name

Please post your whole script so we can check it for syntax errors. The syntax error you currently have is being caused by a missing bracket after the else.

In Amade's code, you could use striPos instead of strPos to check case-insensitively.

Here it is.

Code: [Select]
function servercmddisablewhisper(%client)
{
if(%client.isAdmin)
{
if($whisenabled == 0)
{
messageclient(%client, '',"<color:000000>Whispering is already disabled!");
}

else
{
messageall('',"<color:FF0000>Whispering is now disabled.");
$whisenabled = 0;
}
}

else
{
messageclient(%client, '',"You must be an admin to disable whispering.");
}
}

function servercmdenablewhisper(%client)
{
if(%client.isAdmin)
{
if($whisenabled == 1)
{
messageclient(%client, '',"<color:000000>Whispering is already enabled!");
}

else
{
messageall('',"<color:00FF00>Whispering is now enabled.");
$whisenabled = 1;
}
}

else
{
messageclient(%client, '',"You must be an admin to enable whispering.");
}

function servercmdwhisper(%client, %name, %message)
{
if($whisenabled == 1)
{
if(!%name == "")
{
%reciever = findclientbyname(%name);
if(!%reciever == %reciever)
{
%message = %message.getrestwords();
messageclient(%reciever, '',"From" @ %client.getname(); @ ": /c6" @%message);
messageclient(%client, '', "You sent this message to" @ %reciever.name @ ":" @ %message);
}

else
{
messageclient(%client, '',"Whispering to yourself is pointless.");
}

else
{
messageclient(%client, '',"Please enter a name to whisper to.");
}
}

else
{
messageclient(%client, '',"Whispering is currently disabled.");
}
}

This code will do it.
Code: [Select]
for(%i = 0; %i < clientGroup.getCount(); %i++) // Loop through all clients
{
   %client = clientGroup.getObject(%i); // Sets the client we are currently investigating
   %name = %client.getPlayerName();
   if(strPos(%name, "SEARCHCHARACTERS") != -1) // SEARCHCHARACTERS is within the name
   {
      %found++; // Add 1 to %found
   }
}
echo(%found); // Echo final number of clients with SEARCHCHARACTERS in their name

Please post your whole script so we can check it for syntax errors. The syntax error you currently have is being caused by a missing bracket after the else.

Does this apply directly to my script? or do I need to edit variables?

Does this apply directly to my script? or do I need to edit variables?
Sure, provided everyone is sending messages to SEARCHCHARACTERS.

function servercmdenablewhisper(%client)
{
   if(%client.isAdmin)
   {
      if($whisenabled == 1)
      {
         messageclient(%client, '',"<color:000000>Whispering is already enabled!");
      }
      else
      {
         messageall('',"<color:00FF00>Whispering is now enabled.");
         $whisenabled = 1;
      }
   }
   else
   {
      messageclient(%client, '',"You must be an admin to enable whispering.");
   }  //Forgot your closing bracket
}

function servercmdwhisper(%client, %name, %message)
{
   if($whisenabled == 1)
   {
      if(!%name == "")
      {
         %reciever = findclientbyname(%name);
         if(!%reciever == %reciever)
         {
            %message = %message.getrestwords();
            messageclient(%reciever, '',"From" @ %client.getname(); @ ": /c6" @%message);
            messageclient(%client, '', "You sent this message to" @ %reciever.name @ ":" @ %message);
         }
         else
         {
            messageclient(%client, '',"Whispering to yourself is pointless.");
         }
      }  //You forgot another closing bracket
      else
      {
         messageclient(%client, '',"Please enter a name to whisper to.");
      }   
   }
   else
   {
      messageclient(%client, '',"Whispering is currently disabled.");
   }
}


« Last Edit: November 08, 2009, 06:36:27 PM by Deriboy »

Still need help! I fear that if I dont finish soon, it will be failed on RTB.

Hold up... It was broken, and you uploaded it to RtB anyway? Did you test it?

It was working. I just forgot to add in where it tells you if no players are found and such.