Author Topic: messageclient(); does not work?  (Read 3219 times)

Use gameConnection::onClientEnterGame.
But parent it, and package it.
how do you know these is there like a list?

i think it needs to be ' as /c6 is a command if i have read right from other scrips this one i learnt from cell phone mod

It isn't a command, its just a text modifier.

A command would be something like:

commandtoclient(%client, 'bottomprint', "<font:impact:18>\c2text goes here", 5);

the bottomprint here is a command, and then the string goes in regular quotes.  It is called tagging a string, and using apostrophes can have weird results like it sending the player numbers representing the command instead of words that the client can understand.

It isn't a command, its just a text modifier.

A command would be something like:

commandtoclient(%client, 'bottomprint', "<font:impact:18>\c2text goes here", 5);

the bottomprint here is a command, and then the string goes in regular quotes.  It is called tagging a string, and using apostrophes can have weird results like it sending the player numbers representing the command instead of words that the client can understand.
ok,

i need someone to show me how to use the if thing like if(%client.isadmin) and have an exsample thats how i learn exsample and looking at differences heres my new one i dont know if the if things are right


Code: [Select]
package AutoMessage
{
  function GameConnection::onconnect(%client)
  {
  %name = findclientbyname(%client);
  %random = getrandom(0, 4);
 
  if(%random == "1")
  {
  commandtoserver('messagesent',"Hey " @ %name @ " how ya going.);
  return;
  }
 
  if(%random == "2")
  {
  commandtoserver('messagesent',"Whats up" @ %name @ ".");
  return;
  }
 
  if(%random == "3")
  {
  commandtoserver('messagesent',"Welcome to my server" @ %name @ ".");
  return;
  }
 
  if(%random == "4")
  {
  commandtoserver('messagesent'."Yay more people are joining");
  return;
  }
 
  parent::onconnect(%client)
}
activatepackage (AutoMessage);

ok,

i need someone to show me how to use the if thing like if(%client.isadmin) and have an exsample thats how i learn exsample and looking at differences heres my new one i dont know if the if things are right


Code: [Select]
package AutoMessage
{
  function GameConnection::onconnect(%client)
  {
  %name = findclientbyname(%client);
  %random = getrandom(0, 4);
 
  if(%random == "1")
  {
  commandtoserver('messagesent',"Hey " @ %name @ " how ya going.);
  return;
  }
 
  if(%random == "2")
  {
  commandtoserver('messagesent',"Whats up" @ %name @ ".");
  return;
  }
 
  if(%random == "3")
  {
  commandtoserver('messagesent',"Welcome to my server" @ %name @ ".");
  return;
  }
 
  if(%random == "4")
  {
  commandtoserver('messagesent'."Yay more people are joining");
  return;
  }
 
  parent::onconnect(%client)
}
activatepackage (AutoMessage);

There are a couple of problems with this.  You are getting your client side code and your server side code mixed up.  This will only work if you are hosting a non-dedicated server.  Also just stacking if statements for essentially the same test isn't the best way to do it.  Other than that this should work fine.

edit: oh also don't have a return before the parent::onconnect
The parent should be the very first thing in this kind of function anyway.
« Last Edit: April 08, 2012, 11:11:36 AM by Nexus »

you should use regular "quotes" instead of 'apostrophes' around the words you want people to read, because apostrophes work differently.  Honestly I myself don't really understand it entirely, but generally:
If you are sending a command, it goes in apostrophes.
If you are sending a string for the player to read, it goes in quotes.

If someone could clarify it better that would be nice.

Over the network, a string typed in quote marks is sent by first specifying the length of the string followed by the raw string itself.
This can be quite slow, which is bad for things that need to run quickly, such as notifications of events, kill messages or other things.

When you type a string in apostrophes, it means that it's a tagged string. A tagged string is not sent as the string itself, rather as a number identifying it. The first time you send a tagged string over the network, it is given a unique ID and sent in full length, however all future transmissions only contain the ID. This allows for much faster transmission of strings that may be repeated often, such as command names or kill messages. In TorqueScript, typing echo( 'hello' ); will display the ID of the tagged string. If you want to see the actual string itself, use echo( getTaggedString( 'hello' ) );

getTaggedString( index ) converts a tagged string ID to the string itself. If you're going to do a loop on this which ends once you reach an empty string, note that index 0 is always taken up by an empty string (length 0).

getTag( string ) converts a string to a tagged string ID representing it.

Here's some things that you have to (bolded), really should (italics) or it could be a good idea to send as tagged strings:
Network commands (clientCmd, serverCmd, secureClientCmd)
Kill messages
Player names (as arguments to messageClient, use getTag for this)
Repeating messages, generally fixed messages with changing arguments (e.g. round win notifications.).


Here's some things that you shouldn't use tagged strings for:
Chat messages
Large streams of data
« Last Edit: April 08, 2012, 12:16:21 PM by Port »

There are a couple of problems with this.  You are getting your client side code and your server side code mixed up.  This will only work if you are hosting a non-dedicated server.  Also just stacking if statements for essentially the same test isn't the best way to do it.  Other than that this should work fine.

edit: oh also don't have a return before the parent::onconnect
The parent should be the very first thing in this kind of function anyway.
but i have done the if statements right? alos how will it only work on a non dedi

-snip-
First, work on indenting, one tab for each pair of brackets the line is between. Many text editors made for programming will do it for you automatically.
Second, if your checking the value of a number, you don't enclose the number in quotes:
if(%random == 1)
not
if(%random == "1")
In this case it will work just fine, but it's a good idea to get in the habit of doing it properly

First, work on indenting, one tab for each pair of brackets the line is between. Many text editors made for programming will do it for you automatically.
Second, if your checking the value of a number, you don't enclose the number in quotes:
if(%random == 1)
not
if(%random == "1")
In this case it will work just fine, but it's a good idea to get in the habit of doing it properly
im using notepad 2 but what about this not working on a dedicated server

found the error
Code: [Select]
commandtoserver('messagesent',"Hey " @ %name @ " how ya going.);see the end does not have an "

edit: still says errors down at the parent
« Last Edit: April 08, 2012, 08:57:08 PM by deathrider »

found the error
Code: [Select]
commandtoserver('messagesent',"Hey " @ %name @ " how ya going.);see the end does not have an "

edit: still says errors down at the parent

parent::onConnect(%client);

and get rid of every return;

You do not need them and they will cause issues with other functions if you return before the parent

ok
Code: [Select]
package AutoMessage
{
  function GameConnection::onconnect(%client)
  {
  %name = findclientbyname(%client);
  %random = getrandom(0, 4);
 
  if(%random == 1)
  {
  commandtoserver('messagesent',"Hey " @ %name @ " how ya going.");
  }
 
  if(%random == 2)
  {
  commandtoserver('messagesent',"Whats up" @ %name @ ".");
  }
 
  if(%random == 3)
  {
  commandtoserver('messagesent',"Welcome to my server" SPC %name);
  }
 
  if(%random == 4)
  {
  commandtoserver('messagesent',"Yay more people are joining");
  }
 
  parent::onconnect(%client);
}

activatepackage(AutoMessage);

the last line it says errors THERE ARE NONE

this is from console
Code: [Select]
Loading Add-On: Script_AutoMessage
Add-Ons/Script_AutoMessage/server.cs Line: 31 - Syntax error.
>>> Some error context, with ## on sides of error halt:
 

  if(%random == 3)

  {

  commandtoserver('messagesent',"Welcome to my server" SPC %name);

  }

 

  if(%random == 4)

  {

  commandtoserver('messagesent',"Yay more people are joining");

  }

 

  parent::onconnect(%client);

}



activatepackage(##A##utoMessage);
>>> Error report complete.
« Last Edit: April 09, 2012, 04:03:06 AM by deathrider »

the last line it says errors THERE ARE NONE

this is from console
Code: [Select]
Loading Add-On: Script_AutoMessage
Add-Ons/Script_AutoMessage/server.cs Line: 31 - Syntax error.
>>> Some error context, with ## on sides of error halt:
 

  if(%random == 3)

  {

  commandtoserver('messagesent',"Welcome to my server" SPC %name);

  }

 

  if(%random == 4)

  {

  commandtoserver('messagesent',"Yay more people are joining");

  }

 

  parent::onconnect(%client);

}



activatepackage(##A##utoMessage);
>>> Error report complete.

You have:

}
activatePackage(autoMessage);


It should be:

};
activatePackage(autoMessage);