04.12.2011, 12:31
(
Последний раз редактировалось godoy32; 04.12.2011 в 13:03.
)
Hi, I'm testing the function 'ReturnUser'... but isn't working good
But if I put, for example (My name is godoy32) '/transfer doy32 5000' says the players isn't connected(1) (doy32 is a part of name)
Suppose there are two players in my server ID:0 godoy32 - ID:1 godoy320 and I want to transfer to godoy320 and I put '/transfer godoy 5000' they transfer to godoy32 but they have to say 'Multiple users found, please narrow search.'(2)
Code:
ps: sorry for my bad english, i'm learning
But if I put, for example (My name is godoy32) '/transfer doy32 5000' says the players isn't connected(1) (doy32 is a part of name)
Suppose there are two players in my server ID:0 godoy32 - ID:1 godoy320 and I want to transfer to godoy320 and I put '/transfer godoy 5000' they transfer to godoy32 but they have to say 'Multiple users found, please narrow search.'(2)
Code:
pawn Код:
dcmd_transferir(playerid,params[])
{
new Index;
new tmp[256]; tmp = strtok(params,Index);
new tmp2[256]; tmp2 = strtok(params,Index);
new player1 = ReturnUser(tmp);
if(IsPlayerConnected(player1))
{
new cash = strval(tmp2);
if(player1 == playerid) return SendClientMessage(playerid,COLOR_RED,"No te puedes transferir a ti mismo");
if(!IsRangeToBank(playerid)) return SendClientMessage(playerid,COLOR_RED,"No estas en un banco");
if(pInfo[playerid][Balance] < cash) return SendClientMessage(playerid,COLOR_RED,"No tienes esa cantidad en el banco");
if(!strlen(tmp) || !strlen(tmp2) || !IsNumeric(tmp2)) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Cantidad]");
pInfo[playerid][Balance] -= cash;
pInfo[player1][Balance] += cash;
new string[128];
format(string,sizeof(string),"Transferiste %d$ a %s ",cash, pName(player1));
SendClientMessage(playerid,COLOR_YELLOW,string);
new file[100];
dini_IntSet(file,"Deposit",pInfo[playerid][Balance]);
new string2[128]; format(string2,128,"Tu nuevo balance es %d$",pInfo[playerid][Balance]);
SendClientMessage(playerid,color,string2);
new string3[128]; format(string3,128,"%s (%d) te transfiriу $%d a tu cuenta",pName(playerid),playerid,cash);
SendClientMessage(player1,COLOR_YELLOW,string3);
new string4[128]; format(string4,128,"Tu nuevo balance es: %d$",pInfo[chosenpid][Balance]);
SendClientMessage(player1,color,string4);
}
else return SendClientMessage(playerid,COLOR_RED,"Jugador no conectado o nombre no encontrado.");
return 1;
}
pawn Код:
stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21) // Strip out leading spaces
{
if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos])) // Check whole passed string
{
// If they have a numeric name you have a problem (although names are checked on id failure)
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
userid = INVALID_PLAYER_ID;
}
else
{
return userid; // A player was found
}
}
}
// They entered [part of] a name or the id search failed (check names just incase)
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
{
if (len == strlen(name)) // Exact match
{
return i; // Return the exact player on an exact match
}
else // Partial match
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
}
}
userid = INVALID_PLAYER_ID;
}
return userid; // INVALID_PLAYER_ID for bad return
}
