/w command - 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: /w command (
/showthread.php?tid=503501)
/w command -
DarkLored - 29.03.2014
okay so i made my first whisper command
and when i use it, it sends the message to all players and not those who are near them
here is my code
pawn Код:
CMD:w(playerid,params[])
{
new string[128];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(sscanf(params,"s[128]",params))
{
SendClientMessage(playerid,COLOR_ERROR,"USAGE: /w (Message)");
return 1;
}
if(PlayerToPlayer(playerid, i, 10))
{
format(string,sizeof(string),"%s(%d) whispered : %s",GetName(playerid),playerid,params);
SendClientMessageToAll(COLOR_PURPLE,string);
return 1;
}
}
return 1;
}
Re: /w command -
Matess - 29.03.2014
Of course it sends it to all if you are using
pawn Код:
SendClientMessageToAll(COLOR_PURPLE,string);
Try
pawn Код:
SendClientMessage(i,COLOR_PURPLE,string);
Re: /w command -
Brandon_More - 29.03.2014
pawn Код:
CMD:w(playerid,params[])
{
new string[128];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(sscanf(params,"s[128]",params)) return SendClientMessage(playerid,COLOR_ERROR,"USAGE: /w (Message)");
if(PlayerToPlayer(playerid, i, < 10))
{
format(string,sizeof(string),"%s(%d) whispered : %s",GetName(playerid),playerid,params);
SendClientMessage(i,COLOR_PURPLE,string);
return 1;
}
}
return 1;
}
Try this. Not familiar with your functions.
Re: /w command -
Calgon - 29.03.2014
pawn Код:
CMD:w(playerid, params[]) {
new
szMessage[128];
if(isnull(params) || strlen(params) > 128) // No need to use sscanf, it's just 1 value
return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /w [message]");
for(new i = 0; i < MAX_PLAYERS; i++) {
if(IsPlayerConnected(i) && PlayerToPlayer(playerid, i, < 10)) { // Check if they're connected & close enough
format(szMessage, sizeof(szMessage), "%s(%d) whispered : %s", GetName(playerid), playerid, params);
SendClientMessage(i, COLOR_PURPLE, szMessage); // Send the message only to the player who's close enough
}
}
return 1;
}
Is this what you wanted? A message 'whispered' to all players within 10 distance units?
Re: /w command -
Konstantinos - 29.03.2014
Why do you use sscanf line inside the loop? If you type "/w", then it will send the usage message many times (as many as MAX_PLAYERS is defined). You don't even need sscanf for it.
pawn Код:
CMD:w(playerid, params[])
{
if (isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /w (Message)");
new
string[128],
Float: px,
Float: py,
Float: pz;
format(string, sizeof (string), "%s(%d) whispered : %s", GetName(playerid), playerid, params);
GetPlayerPos(playerid, px, py, pz);
for (new i; i != MAX_PLAYERS; ++i) // foreach(new i : Player)
{
if (IsPlayerInRangeOfPoint(i, 10.0, px, py, pz)) SendClientMessage(i, COLOR_PURPLE, string);
}
return 1;
}