/givecash is not working
#1

When I type /givecash [id] leaving the second parameter blank it says 'USAGE: givecash [id][ammount]' but when I type an ammount it says 'ERROR: is not an active player !'

pawn Код:
if(strcmp(cmd, "/givecash", true) == 0)
    {
        new playermoney;
        new sendername[MAX_PLAYER_NAME];
        new giveplayer[MAX_PLAYER_NAME];
        new giveplayerid, moneys, string[128];
       
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /givecash [playerid] [amount]");
        giveplayerid = ReturnUser(tmp);
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /givecash [playerid] [amount]");
        moneys = strval(tmp);

        if (IsPlayerConnected(giveplayerid))
        {
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            playermoney = GetPlayerMoney(playerid);
            if (moneys > 0 && playermoney >= moneys)
            {
                PlayerInfo[playerid][pMoney] -= moneys;
                PlayerInfo[giveplayerid][pMoney] += moneys;
                format(string, sizeof(string), "You have sent %s [ID: %d], $%d$", giveplayer,giveplayerid, moneys);
                SendClientMessage(playerid, COLOR_GREEN, string);
                format(string, sizeof(string), "You have recieved %d$ from %s [ID: %d].", moneys, sendername, playerid);
                SendClientMessage(giveplayerid, COLOR_GREEN, string);
                printf("LOGS: %s [ID: %d] has transfered %d$ to %s [ID: %d]",sendername, playerid, moneys, giveplayer, giveplayerid);
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: You don't have that much!");
            }
        }
        else
        {
            format(string, sizeof(string), "ERROR: %s is not an active player !", giveplayer);
            SendClientMessage(playerid, COLOR_GRAY, string);
        }
        return 1;
    }

ReturnUser(string[])
{
    new IsNumerical=1;
    new tmpstring[MAX_PLAYER_NAME];
    for(new cell; cell < strlen(string); cell++) if((string[cell]<='0') || (string[cell]>='9'))IsNumerical=0;
    if(IsNumerical)return strval(string);
    else
    {
        for(new players; players < MAX_PLAYERS; players++)
        {
            GetPlayerName(players,tmpstring,sizeof(tmpstring));
            if(strfind(tmpstring,string,true)>-1)return players;
        }
    }
    return INVALID_PLAYER_ID;
}
Please don't tell me to move to sscanf.
Reply


Messages In This Thread
/givecash is not working - by admantis - 04.01.2011, 19:59

Forum Jump:


Users browsing this thread: 1 Guest(s)