[Tutorial] [Tutorial] Simple Group Chat
#1



So for over the past couple weeks of me being back, I have been hounded with a few people asking me constantly to release some of my small codes for chats etc. This will be a very short tutorial in how to explain how to make a small group chat system.

Remember you can edit this to use with whatever group you want

Step One:
Your first step may be quite easy but it is where alot of people, especially new coders get stuck. So what you want to do, is start by making a basically a public function that revolves around a string format.
Code:
forward AdminMessage(color, const string, level);
public AdminMessage(color, const string, level)
{
You then want to get all the players that are within the server by using this line next
Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
You then want to check if the player is connected who will be using the command at that time and also check if they are an Admin or whatever Variable you want them to be apart of

Code:
          if(IsPlayerConnected(i))
          {
	       if(IsPlayerAdmin(playerid))
	       {
		          SendClientMessage(i, color, string);
So your whole public and forward function will look like this
Code:
forward AdminMessage(color, const string, level);
public AdminMessage(color, const string, level)
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
			if(IsPlayerAdmin(playerid))
			{
				SendClientMessage(i, color, string);
			}
		}
	}
	return 1;
}
Now you have done Step one, you will now be able to put Step two into your code to be able to format the text or message you want everyone in that variable to see.
Code:
new string1[256];
format(string1,sizeof(string1),"{FF0033}((Adminstrator %s: %s))", //YourRoleplayNameFunctionHere//, params);
AdminMessage(-1, string1,1);
So this is a little code line from my script, that uses and admin chat system for this feature. Very nice and simple. Plus very fast processing aswell.
Code:
CMD:a(playerid, params[])
{
	if(IsPlayerConnected(playerid))
	{
	    new string20[256];
	    if(PlayerInfo[playerid][pAdmin] >= 1)
	    {
	        if(isnull(params))
	        {
	            SendClientMessage(playerid,-1,"{FFA500}[Server]: {FFFFFF}/a [admin chat text]");
	        }
	        else
	        {
	            format(string20,sizeof(string20),"{FF0033}((Adminstrator %s: %s))", RPName(playerid), params);
				AMSG(-1, string20,1);
	        }
	    }
	    else
		{
		    SendClientMessage(playerid,-1,"{CC3399}[Error]: {FFFFFF}You do not have a high enough admin rank");
	    }
	}
	return 1;
}
Reply
#2

Why a public function, is it called by timer or CallLocalFunction/CallRemoteFunction?
The second parameter in the function (string) is missing brackets to indicate it is an array.
There is GetPlayerPoolSize function instead of a constant MAX_PLAYERS in your loops.
Your loop uses "i" as variable iteration but you use "playerid" in IsPlayerAdmin function which is undefined symbol.
You are having a third parameter called "level" yet you check if the player is logged in as RCON.
Why the size of string1 is 256 when max characters for client messages is 144?
Why do you check if the player who typed the command /a is connected?
You created a function called "AdminMessage" but you used one called "AMSG".
"PlayerInfo[playerid][pAdmin]" variable and "RPName" function? Even if it is obvious by its name, people will request what is their code.

Sorry to say this, but it is not a tutorial. In tutorials, you need to explain what each line or at least most of the code does so your audience will understand otherwise they will just copy and paste.
Reply
#3

I love how you make a comment on which you make no sense at all. For a few points, unless someone cannot code at all cannot understand what was written. Also before you comment next time read what was said. My /a cms was only a display to show how to implement it.
Reply
#4

Quote:
Originally Posted by Ciandlah
View Post
I love how you make a comment on which you make no sense at all. For a few points, unless someone cannot code at all cannot understand what was written. Also before you comment next time read what was said. My /a cms was only a display to show how to implement it.
He was being helpful by pointing out those few slip-ups, you shouldn't ignore his advice as he was making valid points. It's the people who are first exposed to scripting through your tutorial that are in danger, they are going to learn bad code practice, and that will all fall under you, and trust me, you don't want that. Coding tips like string sizes and the use of public functions are what tell a good scripter and a bad one apart, yes, there are hundreds of methods to achieve the same thing in scripting, but choosing the shortest, most readable, and most optimized one are always a must to follow rules of thumb.
Reply
#5

Quote:
Originally Posted by Calisthenics
View Post
Why a public function, is it called by timer or CallLocalFunction/CallRemoteFunction?
The second parameter in the function (string) is missing brackets to indicate it is an array.
There is GetPlayerPoolSize function instead of a constant MAX_PLAYERS in your loops.
Your loop uses "i" as variable iteration but you use "playerid" in IsPlayerAdmin function which is undefined symbol.
You are having a third parameter called "level" yet you check if the player is logged in as RCON.
Why the size of string1 is 256 when max characters for client messages is 144?
Why do you check if the player who typed the command /a is connected?
You created a function called "AdminMessage" but you used one called "AMSG".
"PlayerInfo[playerid][pAdmin]" variable and "RPName" function? Even if it is obvious by its name, people will request what is their code.

Sorry to say this, but it is not a tutorial. In tutorials, you need to explain what each line or at least most of the code does so your audience will understand otherwise they will just copy and paste.
This summed up how much of a shit 'tutorial' this is, what a joke.
Reply
#6

you must explain it correctly also why using forward admin message things
you can use them by making stocks
Reply
#7

Quote:
Originally Posted by CaptainBoi
View Post
you must explain it correctly also why using forward admin message things
you can use them by making stocks
Stocks aren't needed.
Reply
#8

well he said group chat but he is showing tutorial to make /adminchat lol
Reply
#9

Quote:
Originally Posted by CaptainBoi
View Post
well he said group chat but he is showing tutorial to make /adminchat lol
Making an admin chat is the same as making a faction chat, both are groups.
Reply
#10

Quote:
Originally Posted by CaptainBoi
View Post
well he said group chat but he is showing tutorial to make /adminchat lol
stock is not needed!

You can do that:

PHP Code:
AdminMessage(color, const string[])
{
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(
PlayerInfo[i][pAdmin] < 1) continue;
        
SendClientMessage(icolorstring);
    }
    return 
1;

stock just hides warnings if the function is not being used thats why includes use stock otherwise i dont see any reason using stock
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)