SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 04/07/2018, 02:52 PM   #1
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 206
Reputation: 16
Default asay command doubled message

I've made a simple asay command that should be sent globally to everyone and have a color depending on the admin level.Level 1 admin has a blue colors, level 2 has red and level 3 has green.The problem is when i do /asay with multiple admins ingame, for example 2 it sends the message twice with different colors since he was lvl 2 and i was lvl 3.
CMD:
Code:
CMD:asay(playerid,params[])
{
	if(PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid,COLOR_ERROR,"Error: {FFFFFF}Unknown command, type /cmds for the list of commands.");
	else
	{
		new text[200];
		if(sscanf(params,"s[200]",text)) return SendClientMessage(playerid,COLOR_GRAY,"Syntax: /asay [message]");
		format(text,sizeof(text),"Admin: %s",text);
		SendMessageToPlayers(text);
	}
	return 1;
}
Stock:
Code:
stock SendMessageToPlayers(text[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(PlayerInfo[i][pAdmin] == 1)
	{
		SendClientMessageToAll(COLOR_LEVEL1,text);
	}
	else if(PlayerInfo[i][pAdmin] == 2)
	{
  		SendClientMessageToAll(COLOR_LEVEL2,text);
	}
	else if(PlayerInfo[i][pAdmin] == 3)
	{
		SendClientMessageToAll(COLOR_LEVEL3,text);
	}
	}
	return 1;
}
Mike861 is offline   Reply With Quote
Old 04/07/2018, 02:57 PM   #2
Exhibit
Big Clucker
 
Join Date: Dec 2015
Location: Pakistan
Posts: 180
Reputation: 22
Default Re: asay command doubled message

ofc that will happen because you are looping all the online players and checking who are admin lol. Remove the loop/break; it after sending the message.
Exhibit is offline   Reply With Quote
Old 04/07/2018, 03:07 PM   #3
Slawi
Little Clucker
 
Join Date: Dec 2013
Posts: 47
Reputation: 1
Default Re: asay command doubled message

try this maybe will help
Code:
stock SendMessageToPlayers(text[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(PlayerInfo[i][pAdmin] == 1)
	{
		SendClientMessage(i, COLOR_LEVEL1,text);
	}
	else if(PlayerInfo[i][pAdmin] == 2)
	{
  		SendClientMessage(i, COLOR_LEVEL2,text);
	}
	else if(PlayerInfo[i][pAdmin] == 3)
	{
		SendClientMessage(i, COLOR_LEVEL3,text);
	}
	}
	return 1;
}
Slawi is offline   Reply With Quote
Old 04/07/2018, 03:08 PM   #4
Banditul18
Huge Clucker
 
Join Date: Nov 2014
Location: Brasov,Romania
Posts: 402
Reputation: 32
Default Re: asay command doubled message

Why do you need a loop? Is a single message sented by a single person. Check his admin level and send it as it should be. I dont see the point checking all the players admin level to send a message from one single person

Edit: Dont use the code from the person above, it will only send to admins
Banditul18 is offline   Reply With Quote
Old 04/07/2018, 03:09 PM   #5
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 206
Reputation: 16
Default Re: asay command doubled message

Quote:
Originally Posted by Slawi View Post
try this maybe will help
Code:
stock SendMessageToPlayers(text[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(PlayerInfo[i][pAdmin] == 1)
	{
		SendClientMessage(i, COLOR_LEVEL1,text);
	}
	else if(PlayerInfo[i][pAdmin] == 2)
	{
  		SendClientMessage(i, COLOR_LEVEL2,text);
	}
	else if(PlayerInfo[i][pAdmin] == 3)
	{
		SendClientMessage(i, COLOR_LEVEL3,text);
	}
	}
	return 1;
}
I assume its only gonna send messages to admins, this should send the message to everyone.
Mike861 is offline   Reply With Quote
Old 04/07/2018, 03:32 PM   #6
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 91
Default Re: asay command doubled message

Quote:
Originally Posted by Mike861 View Post
I assume its only gonna send messages to admins, this should send the message to everyone.
PHP Code:
SendMessageToPlayers(text[])
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
PlayerInfo[i][pAdmin] < 1//if not admin
        
{
            
SendClientMessage(i, -1,text); //send message in white (-1) change the color to you'rs
        
}
        if(
PlayerInfo[i][pAdmin] == 1)
        {
            
SendClientMessage(iCOLOR_LEVEL1,text);
        }
        else if(
PlayerInfo[i][pAdmin] == 2)
        {
              
SendClientMessage(iCOLOR_LEVEL2,text);
        }
        else if(
PlayerInfo[i][pAdmin] == 3)
        {
            
SendClientMessage(iCOLOR_LEVEL3,text);
        }
    }
    return 
1;

__________________
Lokii is offline   Reply With Quote
Old 04/07/2018, 03:46 PM   #7
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 953
Reputation: 167
Default Re: asay command doubled message

The color will depend on the level of the admin who executes the command? If yes, it is true that you do not need a loop. For only 1 parameter that is string, use isnull macro- no need for sscanf.
Max client message is 144 characters.
pawn Code:
CMD:asay(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error: {FFFFFF}Unknown command, type /cmds for the list of commands.");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_GRAY, "Syntax: /asay [message]");

    new text[145], color_of_text;

    switch (PlayerInfo[playerid][pAdmin])
    {
        case 1: color_of_text = COLOR_LEVEL1;
        case 2: color_of_text = COLOR_LEVEL2;
        case 3: color_of_text = COLOR_LEVEL3;
    }

    format(text, sizeof (text), "Admin: %s", params);
    SendClientMessageToAll(color_of_text, text);
    return 1;
}
Calisthenics is offline   Reply With Quote
Old 04/07/2018, 03:49 PM   #8
Slawi
Little Clucker
 
Join Date: Dec 2013
Posts: 47
Reputation: 1
Default Re: asay command doubled message

Quote:
Originally Posted by Mike861 View Post
I assume its only gonna send messages to admins, this should send the message to everyone.
yes you right
i was think that he want the message show only for admins
Slawi is offline   Reply With Quote
Old 04/07/2018, 03:52 PM   #9
Mike861
Huge Clucker
 
Join Date: Feb 2018
Posts: 206
Reputation: 16
Default Re: asay command doubled message

Quote:
Originally Posted by Calisthenics View Post
The color will depend on the level of the admin who executes the command? If yes, it is true that you do not need a loop. For only 1 parameter that is string, use isnull macro- no need for sscanf.
Max client message is 144 characters.
pawn Code:
CMD:asay(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error: {FFFFFF}Unknown command, type /cmds for the list of commands.");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_GRAY, "Syntax: /asay [message]");

    new text[145], color_of_text;

    switch (PlayerInfo[playerid][pAdmin])
    {
        case 1: color_of_text = COLOR_LEVEL1;
        case 2: color_of_text = COLOR_LEVEL2;
        case 3: color_of_text = COLOR_LEVEL3;
    }

    format(text, sizeof (text), "Admin: %s", params);
    SendClientMessageToAll(color_of_text, text);
    return 1;
}
Thanks, + rep.
Mike861 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command /asay help me please SapMan Scripting Help 17 30/03/2018 03:35 PM
/asay command help? Tass007 Scripting Help 4 03/02/2016 06:31 AM
/asay command [REP+] [FoR]EveR Scripting Help 48 31/12/2014 02:00 PM
Doubled message SsHady Scripting Help 8 24/10/2013 02:13 PM
Command /asay [REP+] [FoR]EveR Scripting Help 5 22/03/2012 06:12 PM


All times are GMT. The time now is 04:58 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.