ReturnUser
#1

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:
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
}
ps: sorry for my bad english, i'm learning
Reply
#2

Get sscanf, much easier.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Get sscanf, much easier.
EDIT: I agree.
Reply
#4

Quote:
Originally Posted by Threshold
Посмотреть сообщение
EDIT: I agree.
Is the same...
pawn Код:
dcmd_transferir(playerid,params[])
{
        if(sscanf(params,"u[10]i",params[0],params[1])) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Dinero]");
        if(IsPlayerConnected(params[0]) || params[0] != INVALID_PLAYER_ID)
        {

        if(params[0] == 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] < params[1]) return SendClientMessage(playerid,COLOR_RED,"No tienes esa cantidad en el banco");
        pInfo[playerid][Balance] -= params[1];
        pInfo[params[0]][Balance] += params[1];
        new string[128];
        format(string,sizeof(string),"Transferiste %d$ a %s ",params[1], pName(params[0]));
        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,params[1]);
        SendClientMessage(params[0],COLOR_YELLOW,string3);
        new string4[128]; format(string4,128,"Tu nuevo balance es: %d$",pInfo[params[0]][Balance]);
        SendClientMessage(params[0],color,string4);
        }
        else return SendClientMessage(playerid,COLOR_RED,"Jugador no conectado o nombre no encontrado.");
        return 1;
}
The same problems...
Reply
#5

What errors are you getting? Please post.
Reply
#6

Quote:
Originally Posted by Threshold
Посмотреть сообщение
EDIT: I agree.
Quote:
Originally Posted by Threshold
Посмотреть сообщение
What errors are you getting? Please post.
I have the command '/transfer [ID/NAME] [MONEY]'
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)
Reply
#7

Nobody can help me?
Reply
#8

pawn Код:
if(sscanf(params,"u[10]i",params[0],params[1])) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Dinero]");
i think the "u" parameter doesn't require a length.. try with:

pawn Код:
if(sscanf(params,"ui",params[0],params[1])) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Dinero]");
not tested, and someone correct me if i'm wrong.
Reply
#9

If he says it doesn't work... then I will surely tell you that you are wrong I don't have any experience in this kind of scripting so I won't be able to help you. You'll need a more advanced scripter's help.
Reply
#10

Quote:
Originally Posted by [Diablo]
Посмотреть сообщение
pawn Код:
if(sscanf(params,"u[10]i",params[0],params[1])) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Dinero]");
i think the "u" parameter doesn't require a length.. try with:

pawn Код:
if(sscanf(params,"ui",params[0],params[1])) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Dinero]");
not tested, and someone correct me if i'm wrong.
I tested it and i have the same problems
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)