Range of this cmd
#1

Hello
I want to set the range of the players on this whisper cmd

pawn Код:
CMD:whisper(playerid,params[]) {
    new string[256];
    new filestring[75];
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pname,sizeof(pname));
    for(new i=0;i<MAX_PLAYERS;i++) {
        if(IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < 10) {
        format(string, sizeof(string), "[WHISPER] %s[%d]: %s",pname,playerid,params);
        SendClientMessage(i,red,string);
        format(filestring, sizeof filestring, "[WHISPER] %s[%d]: %s", pname,playerid,params);}}
    return 1;}
as you could see it is set to be GetDistanceBetweenPlayers(playerid,i) < 10 but i want the players to set their range, how could it be done?
Reply
#2

You'd have to allow the player to set their own distance variable (i.e. PlayerData[playerid][playerWhisperDistance]).
Reply
#3

Try that

PHP код:
CMD:whisper(playerid,params[]) {
          new 
string[256];
          new 
filestring[75];
          new 
pname[MAX_PLAYER_NAME];
          new 
targetid;
          
GetPlayerName(playerid,pname,sizeof(pname));
          for(new 
i=0;i<MAX_PLAYERS;i++) {
          if(
IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < 10) {
          new 
Float:xFloat:yFloat:z;
          
GetPlayerPos(playeridx,y,z);
          if(
IsPlayerInRangeOfPoint(targetid5.0xyz))
          
format(stringsizeof(string), "[WHISPER] %s[%d]: %s",pname,playerid,params);
          
SendClientMessage(i,red,string);
          
format(filestringsizeof filestring"[WHISPER] %s[%d]: %s"pname,playerid,params);}}
          return 
1;} 
Reply
#4

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Try that

PHP код:
CMD:whisper(playerid,params[]) {
          new 
string[256];
          new 
filestring[75];
          new 
pname[MAX_PLAYER_NAME];
          new 
targetid;
          
GetPlayerName(playerid,pname,sizeof(pname));
          for(new 
i=0;i<MAX_PLAYERS;i++) {
          if(
IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < 10) {
          new 
Float:xFloat:yFloat:z;
          
GetPlayerPos(playeridx,y,z);
          if(
IsPlayerInRangeOfPoint(targetid5.0xyz))
          
format(stringsizeof(string), "[WHISPER] %s[%d]: %s",pname,playerid,params);
          
SendClientMessage(i,red,string);
          
format(filestringsizeof filestring"[WHISPER] %s[%d]: %s"pname,playerid,params);}}
          return 
1;} 
no..
Reply
#5

pawn Код:
CMD:w(playerid, params[]) return cmd_whisper(playerid, params);
CMD:whisper(playerid, params[])
{
    new string[128], message[128], targetid;
    if(sscanf(params, "us[128]", targetid, message)) return SendClientMessageEx(playerid, COLOR_GREY, "Usage: /w(hisper) [playerid] [message]");
    else if(!IsPlayerConnectedEx(targetid)) return SendClientMessageEx(playerid, COLOR_GREY, "Invalid player specified.");
    else if(!IsPlayerInRangeOfPlayer(playerid, targetid) && PlayerInfo[playerid][pAdminLevel] < 2) return SendClientMessageEx(playerid, COLOR_GREY, "You must be near the specified player to use this command!");
    else if(playerid == targetid) return SendClientMessageEx(playerid, COLOR_GREY, "You cannot use this command on yourself!");
    format(string, sizeof(string), "(ID %d) %s whispers to you: %s", playerid, GetPlayerNameEx(playerid), message);
    SendClientMessageEx(targetid, COLOR_YELLOW, string);
    format(string, sizeof(string), "You whispered to (ID %d) %s: %s", targetid, GetPlayerNameEx(targetid), message);
    SendClientMessageEx(playerid, COLOR_YELLOW, string);
    return 1;
Rep if I helped.
Reply
#6

How do you do your player saving & variable setting system, is it through an ENUM? If so, please post the ENUM here so I can further assist you.
Reply
#7

You'd have to save their setting using a variable. For example,

pawn Код:
CMD:setwdistance(playerid, params[])
{
    if(sscanf(params, "f", distance)) return SendClientMessage(playerid, -1, "USAGE: /setwdistance [Float: distance]");
    if(distance >= MAX_DISTANCE) return SendClientMessage(playerid, -1, "Distance too high!");
    Distance[playerid] = distance;
    new string[64];
    format(string, sizeof(string), "Whisper distance set to %f.", distance);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply
#8

Quote:
Originally Posted by Abagail
Посмотреть сообщение
You'd have to save their setting using a variable. For example,

pawn Код:
CMD:setwdistance(playerid, params[])
{
    if(sscanf(params, "f", distance)) return SendClientMessage(playerid, -1, "USAGE: /setwdistance [Float: distance]");
    if(distance >= MAX_DISTANCE) return SendClientMessage(playerid, -1, "Distance too high!");
    Distance[playerid] = distance;
    new string[64];
    format(string, sizeof(string), "Whisper distance set to %f.", distance);
    SendClientMessage(playerid, -1, string);
    return 1;
}
There it should be new MAX_DISTANCE[MAX_PLAYERS] ?
Reply
#9

Quote:
Originally Posted by Bondage
Посмотреть сообщение
There it should be new MAX_DISTANCE[MAX_PLAYERS] ?
Yes, but it would be ideal if you saved it onto your accounts system as if you use a global variable to do this it resets after the player logs off or the server restarts.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)