PDA

View Full Version : Bug with PM


Join7
09/12/2011, 03:34 PM
When someone sent me a PM, I sent him 3 times, not as they should, 1. This happened after I put JunkBuster 11 and 0.3d

Edit: and I remove AllowAdminTeleport(1);

if(strcmp(cmd, "/pm", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "Type: /pmtoplayer [ID] [text]");
return 1;
}
giveplayerid = strval(tmp);
if (IsPlayerConnected(giveplayerid))
{
if(giveplayerid!= INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[256];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /pm [playerid/PartOfName] [text]");
return 1;
}
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(PlayerInfo[i][aigm] == 1)
{
format(string, sizeof(string), "* Pm from %s(ID: %d): %s", PlayerName(playerid), playerid, (result));
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
}
}
}
format(string, sizeof(string), "* Pm for %s(ID: %d): %s", giveplayer, giveplayerid, (result));
SendClientMessage(playerid, COLOR_YELLOW, string);
return 1;
}
}
}
return 1;
}

MoroDan
09/12/2011, 05:09 PM
When someone sent me a PM, I sent him 3 times, not as they should, 1. This happened after I put JunkBuster 11 and 0.3d

Edit: and I remove AllowAdminTeleport(1);

if(strcmp(cmd, "/pm", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "Type: /pmtoplayer [ID] [text]");
return 1;
}
giveplayerid = strval(tmp);
if (IsPlayerConnected(giveplayerid))
{
if(giveplayerid!= INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[256];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /pm [playerid/PartOfName] [text]");
return 1;
}
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(PlayerInfo[i][aigm] == 1)
{
format(string, sizeof(string), "* Pm from %s(ID: %d): %s", PlayerName(playerid), playerid, (result));
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
}
}
}
format(string, sizeof(string), "* Pm for %s(ID: %d): %s", giveplayer, giveplayerid, (result));
SendClientMessage(playerid, COLOR_YELLOW, string);
return 1;
}
}
}
return 1;
}

The problem come from the for loop. You don't need a for loop, because you must send the PM only for the giveplayerid player :).


if(strcmp(cmd, "/pm", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "Type: /pmtoplayer [ID] [text]");
return 1;
}
giveplayerid = strval(tmp);
if (IsPlayerConnected(giveplayerid))
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[256];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /pm [playerid] [text]");
return 1;
}
if(PlayerInfo[giveplayerid][aigm] == 1)
{
format(string, sizeof(string), "* Pm from %s(ID: %d): %s", PlayerName(playerid), playerid, (result));
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
}
format(string, sizeof(string), "* Pm for %s(ID: %d): %s", giveplayer, giveplayerid, (result));
SendClientMessage(playerid, COLOR_YELLOW, string);
return 1;
}
}
return 1;
}


*NOTE: Take attention at sintax 2nd parameter ( you use strval, not ReturnUser ; so you must give the parameter as an integer ).

Join7
09/12/2011, 05:34 PM
same