Author Topic: Need help with this script:  (Read 1009 times)

Mmmmmkay, this is really the first script I've made from scratch on my own, so yeah... I can't get my message script to work. It should be /msg [ID here] [message here], but it won't work. So here is the script:
Code: [Select]
//Utility_Message.cs
function servercmdmsg(%client, %target, %message)
{
%target = getclientbyid(%target);
if(%target = -1) return;

messageclient(%target, "", "\c5%message")

}

function getClientByID(%idnum) {
for(%i = 0; %i < clientgroup.getcount(); %i++) {
%plyrcheck = clientgroup.getobject(%i);

if(%plyrcheck.bl_id == %idnum) return %plyrcheck;
}
}

I do get an Unkown serverCmdmsg thing in the console, and when I exec the file I get an error, so if you want me to post that I can.

Quote
//Utility_Message.cs
function servercmdmsg(%client, %target, %message)
{
%target = getclientbyid(%target);
if(%target = -1) return;

messageclient(%target, "", "\c5" @ %message);
messageclient(%client,"","\c5Sent \c3" @ %target.name @ "\c5 a message saying \"" @ %message @ "\"");

}

function getClientByID(%idnum) {
      for(%i = 0; %i < clientgroup.getcount(); %i++) {
      %plyrcheck = clientgroup.getobject(%i);
      
      if(%plyrcheck.bl_id == %idnum) return %plyrcheck;
   }
return -1;
}
So, you want to type /msg 130 Hello and me (BLID 130) would get a message saying "Hello"?
(That's what this does)

I also made it say "Sent Space Guy a message saying "Hello"".
« Last Edit: November 18, 2007, 12:32:25 PM by Space Guy »

Quote
//Utility_Message.cs
function servercmdmsg(%client, %target, %message)
{
%target = getclientbyid(%target);
if(%target = -1) return;

messageclient(%target, "", "\c5" @ %message);

}

function getClientByID(%idnum) {
      for(%i = 0; %i < clientgroup.getcount(); %i++) {
      %plyrcheck = clientgroup.getobject(%i);
      
      if(%plyrcheck.bl_id == %idnum) return %plyrcheck;
   }
return -1;
}
So, you want to type /msg 130 Hello and me (BLID 130) would get a message saying "Hello"?
That there is correct.

Update in my last post to confirm that it was sent correctly. That code will only work with the first word of your message...

/msg 130 Hello
[My screen]
Hello
[Your screen]
Sent Space Guy a message saying "Hello"

/msg 130 Long Message With Spaces
[My screen]
Long
[Your screen]
Sent Space Guy a message saying "Long"

So how would I make it say more that one word? The only thing I can think of is make like 50 local variables in the command (%word1, %word2, etc.).

You can do that, which makes coding a hassle, or if you don't expect it to be used very often, you can make input a hassle instead:

Pick a character, say, underscore ( _ ), and make that your "space". Then, the player can input "This_is_my_long_message_with_ spaces", and it'll go through as a single variable. Then you can use:

%message = strReplace(%message, "_", " ");

and that'll switch out the underscores for spaces.

Quote
//Utility_Message.cs
function servercmdmsg(%client, %target, %message)
{
%target = getclientbyid(%target);
if(%target == -1) return;

messageclient(%target, "", "\c5" @ %message);

}

function getClientByID(%idnum) {
      for(%i = 0; %i < clientgroup.getcount(); %i++) {
      %plyrcheck = clientgroup.getobject(%i);
      
      if(%plyrcheck.bl_id == %idnum) return %plyrcheck;
   }
return -1;
}
« Last Edit: November 18, 2007, 01:11:04 PM by Mr. Wallet »

I'm not just spamming replies, these are by personal request of legoeggo.

Code: [Select]
messageclient(%target, "", "\c5From " @ %client.name @ ": " @ %message);

Code: [Select]
messageClient(%target, '', '\c5From %1: %2', %client.name, %message);

For readability.