26.02.2013, 22:11
Na maioria dos cуdigos que eu vejo com o fim dessa funзгo, usam uma coisa enorme para fazer algo que й, relativamente, tгo simples. Espero que seja ъtil para alguйm.
pawn Код:
new targetId=INVALID_PLAYER_ID, targetName[MAX_PLAYER_NAME];
if(sscanf(params, "d", targetId) && sscanf(params, "s", targetName)) return SendClientMessage(playerid, COLOR_GRAD3, "Utilize: /comando [id/nome]");
if(targetId == INVALID_PLAYER_ID && !strlen(targetName)) return SendClientMessage(playerid, COLOR_GREY, "Utilize: /comando [id/nome]");
if(strlen(targetName) > 0) targetId = GetPlayerID(targetName, 1);
pawn Код:
// by ******
stock GetPlayerID(const playername[], partofname=0)
{
new i;
new playername1[255];
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,playername1,sizeof(playername1));
if (strcmp(playername1,playername,true)==0)
{
return i;
}
}
}
new correctsigns_userid=-1;
new tmpuname[255];
new hasmultiple=-1;
if(partofname)
{
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,tmpuname,sizeof(tmpuname));
if (strfind(tmpuname,playername,true)==0)
{
hasmultiple++;
correctsigns_userid=i;
}
if (hasmultiple>0)
{
return -2;
}
}
}
}
return correctsigns_userid;
}