player play sound - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: player play sound (
/showthread.php?tid=557261)
player play sound -
AgusZ - 13.01.2015
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;
}
Re: player play sound -
JonathanFeitosa - 13.01.2015
Foreach/Loop?
Re: player play sound -
CalvinC - 13.01.2015
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.
You can also use "foreach" to do it if you have that include.
Re: player play sound -
JonathanFeitosa - 13.01.2015
Using MAX_PLAYERS(instead of GetMaxPlayers) by setting the number of slots, the code becomes more optimized.
Re: player play sound -
AgusZ - 13.01.2015
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;
}
Re: player play sound -
CalvinC - 13.01.2015
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);