How to send a message to near players -
bustern - 16.11.2013
pawn Код:
new RandomMSG[][] =
{
"1",
"2",
"3",
"4",
"5",
"6"
};
forward SendMSG();
CMD:dice(mycommand, playerid, params[]) // or cmd(mycommand, playerid, params[])
{
new randMSG = random(sizeof(RandomMSG)); //calculates the size of RandomMSG (which is 3)
SendClientMessageToAll(COLOR_PURPLE, RandomMSG[randMSG]); // Replace the "color" with your defined color.
return 1;
}
I want the dice message to show only for near players, and why dont show the name of player who typed it ?
Ex:Bustern:6
Re: How to send a message to near players -
Voxel - 16.11.2013
Use a prox detector to send messages to near players,
****** it.
Re: How to send a message to near players -
bustern - 16.11.2013
i searched, but that didnt help me
Re: How to send a message to near players - Patrick - 16.11.2013
I created a simple function for you
pawn Код:
stock SendNearMessage(playerid, color, string[], Float:radius)
{
new Float:Position[3];
GetPlayerPos(playerid,Position[0],Position[1],Position[2]);
for(new i; i <= MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(playerid)) continue;
if(IsPlayerInRangeOfPoint(i,radius, Position[0],Position[1],Position[2]))
return SendClientMessage(i, color, string);
}
return 1;
}
Replace
pawn Код:
SendClientMessageToAll(COLOR_PURPLE, RandomMSG[randMSG]);
To
pawn Код:
SendNearMessage(playerid, COLOR_PURPLE, RandomMSG[randMSG], 15.0);
Re: How to send a message to near players -
bustern - 16.11.2013
Dont work :@
Re: How to send a message to near players -
Voxel - 16.11.2013
allright here,
put this at the bottom of your script
pawn Код:
stock ProxDetector(Float:radi, playerid, string[],color)
{
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
foreach(Player,i)
{
if(IsPlayerInRangeOfPoint(i,radi,x,y,z))
{
SendClientMessage(i,color,string);
}
}
}
and heres the command, 30 is the range from the player, so if ure 30 close to the player typing /dice you will recieve the message.
pawn Код:
CMD:dice(playerid, params[])
{
new randMSG = random(sizeof(RandomMSG)); //calculates the size of RandomMSG (which is 3)
SendClientMessageToAll(COLOR_PURPLE, RandomMSG[randMSG]); // Replace the "color" with your defined color.
ProxDetector(30, playerid, string, COLOR_GREY);
return 1;
}
Re: How to send a message to near players -
bustern - 16.11.2013
Thanks, but i want to show the name of player who did it
Example:bustern:6
Re: How to send a message to near players -
Voxel - 16.11.2013
Try something like this
pawn Код:
CMD:dice(playerid, params[])
{
new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME];
new randMSG = random(sizeof(RandomMSG));
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s: %s", pname,RandomMSG[randMSG]);
SendClientMessageToAll(-1, string);
ProxDetector(30, playerid, string, COLOR_GREY);
return 1;
}
Re: How to send a message to near players - Patrick - 16.11.2013
Quote:
Originally Posted by Voxel
Try something like this
pawn Код:
CMD:dice(playerid, params[]) { new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME]; new randMSG = random(sizeof(RandomMSG)); GetPlayerName(playerid, pname, sizeof(pname)); format(string, sizeof(string), "%s: %s", pname,RandomMSG[randMSG]); SendClientMessageToAll(-1, string); ProxDetector(30, playerid, string, COLOR_GREY); return 1; }
|
You could do this, or you could do my version, it's easier, no need to use an array
pawn Код:
stock SendNearMessage(playerid, color, string[], Float:radius)
{
new Float:Position[3];
GetPlayerPos(playerid,Position[0],Position[1],Position[2]);
for(new i; i <= MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(playerid)) continue;
if(IsPlayerInRangeOfPoint(i,radius, Position[0],Position[1],Position[2])) SendClientMessage(i, color, string);
}
return 1;
}
CMD:dice(mycommand, playerid, params[])
{
new string[ 128 ], PlayerName[ 24 ], diceresult = random( 6+1 ); //0-6
GetPlayerName( playerid, PlayerName, sizeof( PlayerName ) )
format( string, sizeof( string) ), "%s rolls the dice and gets %i", PlayerName, diceresult);
SendNearMessage( playerid, COLOR_PURPLE, string, 15.0 );
return true;;
}
Re: How to send a message to near players -
bustern - 16.11.2013
Couldnt fix that:
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : error 001: expected token: ";", but found "-identifier-"
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : warning 202: number of arguments does not match definition
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : warning 215: expression has no effect
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : warning 215: expression has no effect
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : warning 215: expression has no effect
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : error 001: expected token: ";", but found ")"
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : error 029: invalid expression, assumed zero
C:\Users\Andrew\Desktop\samp server\filterscripts\dice.pwn(22) : fatal error 107: too many error messages on one line
i tried many ways but cant fix it