player play sound
#1

its true for play sound to all player ?

Код:
CMD:ads( playerid, params[ ] )
{
    new pName[MAX_PLAYER_NAME], text[128], string[156];
    GetPlayerName(playerid, pName,sizeof(pName));
    if(sscanf(params, "s[128]",text)) return SendClientMessage(playerid, -1,"{F300FF}***AdmMsg  {0049FF}: {FFFFFF}Usage: /ads [text]");
    format(string,sizeof(string),"{F81414}[SERVER]  {0049FF}: {F300FF}[Advertise] %s. Contact: %s(%i)",text,pName,playerid);
    printf(string);
    SendClientMessageToAll(COLOR_WHITE,string);
    PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
	return 1;
}
Reply
#2

Foreach/Loop?
Reply
#3

You need to loop through all players.
pawn Код:
for(new i; i < GetMaxPlayers(); i++)
This is an example loop, use that, and replace "playerid" with "i".

Currently your script sends the message to "playerid", which is defined in the command. Which means it will only send it to the playerid that uses the command.
pawn Код:
foreach(Player, i)
You can also use "foreach" to do it if you have that include.
Reply
#4

Using MAX_PLAYERS(instead of GetMaxPlayers) by setting the number of slots, the code becomes more optimized.
Reply
#5

this ??

Код:
CMD:ads( playerid, params[ ] )
{
	for(new i; i<GetMaxPlayers(); i++)
	{
	    if(IsPlayerConnected(i))
	    {
		    new pName[MAX_PLAYER_NAME], text[128], string[156];
		    GetPlayerName(playerid, pName,sizeof(pName));
		    if(sscanf(params, "s[128]",text)) return SendClientMessage(playerid, -1,"{F300FF}***AdmMsg  {0049FF}: {FFFFFF}Usage: /ads [text]");
		    format(string,sizeof(string),"{0049FF}[ADVERTISE]  {0049FF}: {F300FF}%s.  Contact: %s [%i]",text,pName,playerid);
		    printf(string);
		    SendClientMessageToAll(COLOR_WHITE,string);
		    PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
	    }
 	}
	 return 1;
 }
Reply
#6

As Jonathan just said above, it would be better using this:
pawn Код:
for(new i; i < MAX_PLAYERS; i++)
And you forgot to replace the "playerid" in your PlayerPlaySound into "i".
pawn Код:
PlayerPlaySound(i, 1058, 0.0, 0.0, 0.0);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)