Problem with ID 0
#1

Ey guys !
So i've been working on a code for OnPlayerText :


public OnPlayerText(playerid, text[])
{
new string[256];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = 0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{

if(IsPlayerNearPlayer(i, playerid, 20.0))
{
format(string,sizeof(string),"%s : %s",name,text);
ProxDetector(20.0,playerid,string,GetPlayerColor(p layerid),GetPlayerColor(playerid),GetPlayerColor(p layerid),GetPlayerColor(playerid),GetPlayerColor(p layerid));
return 0;
} else {
SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");
return 0;
}

}
}
return 0;
}

So basically, when the player is around other players, they will hear what he said, otherwise, if he's too far, no one will get what he said, and he will receive a msg '[INFO] You are too far, no one hear you !'
That works with a player ( ID : 1 ) who tested it with me !
but for me ( ID : 0 ), I always can send the msg, no matter if i'm near or far other players !

Would be cool to get some help, and thanks
Reply
#2

Could you explain again hat you want ? I didn't understand everything o.o'
Reply
#3

Try this one:
pawn Код:
public OnPlayerText(playerid, text[])
{
new string[256];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = 0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(playerid == i) continue;   // I have added this line
if(IsPlayerNearPlayer(i, playerid, 20.0))
{
format(string,sizeof(string),"%s : %s",name,text);
ProxDetector(20.0,playerid,string,GetPlayerColor(p layerid),GetPlayerColor(playerid),GetPlayerColor(p layerid),GetPlayerColor(playerid),GetPlayerColor(p layerid));
return 0;
} else {
SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");
return 0;
}

}
}
return 0;
}
Reply
#4

Try to make your own "ProxDetector".

Like this :

pawn Код:
#define LOCAL_MESSAGE_RANGE 50

stock SendLocalMessage(sender, receiver = -1, string[], color)
{
     new Float:Pos[3], Around = -1;
     GetPlayerPos(sender, Pos[0], Pos[1], Pos[2]);
     for(new i; i < MAX_PLAYERS; i++)
     {
          if(!IsPlayerConnected(i) || i == sender) continue; // Remove  || i == sender if you want the message also to be sent to "sender"
          if(IsPlayerInRange(i, LOCAL_MESSAGE_RANGE, LOCAL_MESSAGE_RANGE, Pos[0], Pos[1], Pos[2]))
          {
               Around++;
               SendClientMessage(i, color, string);
          }
     }
     if(!Around) { return 0; }
     else  { return Around; }
}
Might not be so efficient, read ******'s post about making scriptings more efficient.
Reply
#5

Quote:
Originally Posted by Norck
Посмотреть сообщение
Try this one:
pawn Код:
public OnPlayerText(playerid, text[])
{
new string[256];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = 0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(playerid == i) continue;   // I have added this line
if(IsPlayerNearPlayer(i, playerid, 20.0))
{
format(string,sizeof(string),"%s : %s",name,text);
ProxDetector(20.0,playerid,string,GetPlayerColor(p layerid),GetPlayerColor(playerid),GetPlayerColor(p layerid),GetPlayerColor(playerid),GetPlayerColor(p layerid));
return 0;
} else {
SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");
return 0;
}

}
}
return 0;
}
Still the same problem, now when I'm near no one and i talk, I don't get any msg !
And for ID : 1, it works always fine !

@Cameltoe Didn't get that code ;o !
Reply
#6

pawn Код:
#define LOCAL_MESSAGE_RANGE 50

stock SendLocalMessage(sender, receiver = -1, string[], color)
{
     new Float:Pos[3], Around = -1;
     GetPlayerPos(sender, Pos[0], Pos[1], Pos[2]);
     for(new i; i < MAX_PLAYERS; i++)
     {
          if(!IsPlayerConnected(i) || i == sender) continue; // Remove  || i == sender if you want the message also to be sent to "sender"
          if(IsPlayerInRange(i, LOCAL_MESSAGE_RANGE, LOCAL_MESSAGE_RANGE, Pos[0], Pos[1], Pos[2]))
          {
               Around++;
               SendClientMessage(i, color, string);
          }
     }
     if(!Around) { return 0; }
     else  { return Around; }
}
Quote:
Originally Posted by Takumi.WS
Посмотреть сообщение
Still the same problem, now when I'm near no one and i talk, I don't get any msg !
And for ID : 1, it works always fine !

@Cameltoe Didn't get that code ;o !
Use it like this :

pawn Код:
public OnPlayerText(playerid, text[])
{
     new string[ 128 ];
     format(string, sizeof(string), "");
     if(!SendLocalMessage(playerid, receiver = -1, string, GetPlayerColor(playerid))) SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");
     return 0;
}
Reply
#7

Still not working
I got some errors but tried to fix 'em like :
- InPlayerInRange ( I changed it to InPlayerInRangeOfPoint )
- undefined symbol "receiver" ( removed it and kept -1 )
but when i go in, it's not working, when i talk i get nothing :/ !
Reply
#8

Quote:
Originally Posted by Takumi.WS
Посмотреть сообщение
Still not working
I got some errors but tried to fix 'em like :
- InPlayerInRange ( I changed it to InPlayerInRangeOfPoint )
- undefined symbol "receiver" ( removed it and kept -1 )
but when i go in, it's not working, when i talk i get nothing :/ !
pawn Код:
if(!IsPlayerConnected(i) || i == sender) continue; // Remove  || i == sender if you want the message also to be sent to "sender"

stock IsPlayerInRange(playerid, Float: Range, Float: Z_Range, Float:tar_x, Float:tar_y, Float:tar_z) //By Simon
{
new Float:player_x, Float:player_y, Float:player_z;
GetPlayerPos(playerid, player_x, player_y, player_z);
 if(player_x - tar_x <= Range && player_x - tar_x >= (0.0 - Range) && player_y - tar_y <= Range && player_y - tar_y >= (0.0 - Range) && player_z - tar_z <= Z_Range && player_z - tar_z >= (0.0 - Z_Range))
 {
  return 1;
 }
 return 0;
}
Reply
#9

I get errors in this line :
if(!SendLocalMessage(playerid, receiver = -1, string, GetPlayerColor(playerid))) SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");

receiver = -1 causes problems :
C:\Users\Ilyesse H\Desktop\RPG\gamemodes\WS.pwn(278 : warning 203: symbol is never used: "receiver"
C:\Users\Ilyesse H\Desktop\RPG\gamemodes\WS.pwn(2809) : error 017: undefined symbol "receiver"
C:\Users\Ilyesse H\Desktop\RPG\gamemodes\WS.pwn(2809) : error 029: invalid expression, assumed zero
Reply
#10

Quote:
Originally Posted by Takumi.WS
Посмотреть сообщение
I get errors in this line :
if(!SendLocalMessage(playerid, receiver = -1, string, GetPlayerColor(playerid))) SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");

receiver = -1 causes problems :
C:\Users\Ilyesse H\Desktop\RPG\gamemodes\WS.pwn(278 : warning 203: symbol is never used: "receiver"
C:\Users\Ilyesse H\Desktop\RPG\gamemodes\WS.pwn(2809) : error 017: undefined symbol "receiver"
C:\Users\Ilyesse H\Desktop\RPG\gamemodes\WS.pwn(2809) : error 029: invalid expression, assumed zero
Sorry my bad, been along time since i last scripted.

pawn Код:
public OnPlayerText(playerid, text[])
{
     new string[ 128 ];
     format(string, sizeof(string), "");
     if(!SendLocalMessage(playerid, -1, string, GetPlayerColor(playerid))) SendClientMessage(playerid, COLOR_WHITE, "[INFO] You are too far, no one hear you ! ");
     return 0;
}

stock SendLocalMessage(sender, receiver = -1, string[], color)
{
     new Float:Pos[3], Around = -1;
     GetPlayerPos(sender, Pos[0], Pos[1], Pos[2]);
     for(new i; i < MAX_PLAYERS; i++)
     {
          if(!IsPlayerConnected(i) || i == sender) continue; // Remove  || i == sender if you want the message also to be sent to "sender"
          if(IsPlayerInRange(i, LOCAL_MESSAGE_RANGE, LOCAL_MESSAGE_RANGE, Pos[0], Pos[1], Pos[2]))
          {
               Around++;
               SendClientMessage(i, color, string);
          }
     }
     if(!Around) { return 0; }
     else  { return Around; }
}
You could just remove "receiver" if you wish, it were only smthn i experimented with along time ago.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)