Command cash
#9

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
Try this, i made it in few minutes. Not sure if it works:
pawn Код:
stock GetIdFromName(playername[]) //Use this stock to use names instead of ids.
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            new pname[MAX_PLAYER_NAME];
            GetPlayerName(i,pname,MAX_PLAYER_NAME);
            if(strfind(pname,playername,true) != -1 && strlen(playername) != 0)
            {
                return i;
            }
        }
    }
    return -1;
}
So, for Example you are going to give cash to someone:

pawn Код:
dcmd_givecash( playerid, params[ ] )
{
        if(IsPlayerAdmin(playerid))
        {
            new string[26], mny;
            if(!sscanf(params,"s[26]i",string,mny))
            {
                if(IsPlayerConnected(rplayer))
                {
                new giveplayerid;
                giveplayerid = GetIdFromName(string);

                new pname[MAX_PLAYER_NAME], tomsg[60];
                GetPlayerName(playerid, pname, sizeof(pname));

                format(tomsg,sizeof(tomsg),"Admin %s gave you %i $!",pname,mny);

                GivePlayerMoney(giveplayerid , mny);

                SendClientMessage(giveplayerid, COLOR_GREEN, tomsg);

                } else return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
            } else return SendClientMessage(playerid, COLOR_RED, "Usage: /givecash [ part of name ] [ amount ]");
        }
        else SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
        return true;
}
This should work. but UNTESTED. xD
I tryed the command that you gave me, and it works perfectly. But, to find myself in all my commands, I little changed it, and the copilation works.

It's that :

pawn Код:
dcmd_cash(playerid, params[])
{
    new id, string[26], ammount;
    if (sscanf(params, "s[26]i", string, ammount))
    return SendClientMessage(playerid, 0xFF9900, "Utilisation: \"/Cash <player name> <ammount>\"");
        if (!IsPlayerAdmin(playerid))
    return SendClientMessage(playerid, 0xFF0000AA, "You are not admin");
   
    id = GetPlayerID(string);
   
    if (!IsPlayerConnected(id))
    {
                new pname[MAX_PLAYER_NAME], tomsg[100], adminmsg[100];
                GetPlayerName(playerid, pname, sizeof(pname));

                format(tomsg, sizeof(tomsg), "Admin %s gave you %i $ !", pname, ammount);
                GivePlayerMoney(id , ammount);
                SendClientMessage(id, 0xFFFF00AA, tomsg);
               
                format(adminmsg, sizeof(adminmsg), "You gave %i $ to %s !", ammount, id);
                SendClientMessage(playerid, 0xFFFF00AA, adminmsg);

    }
    else return SendClientMessage(playerid, 0xFF0000AA, "Player not found");

    return true;
}
But, if I enter a part of name or a complete name, the command returns "player not found".

How to fix that please ?

Thx =)
Reply


Messages In This Thread
Command cash - by ludesert - 27.06.2011, 07:55
Re: Command cash - by iPLEOMAX - 27.06.2011, 08:06
Re : Command cash - by ludesert - 27.06.2011, 08:17
Re: Command cash - by Basicz - 27.06.2011, 08:39
Re : Command cash - by ludesert - 27.06.2011, 09:14
Re : Re: Command cash - by ludesert - 27.06.2011, 10:15
Re : Re: Command cash - by ludesert - 27.06.2011, 10:21
Re: Command cash - by iPLEOMAX - 27.06.2011, 11:41
Re : Re: Command cash - by ludesert - 27.06.2011, 19:49
Re: Command cash - by iPLEOMAX - 27.06.2011, 19:53

Forum Jump:


Users browsing this thread: 1 Guest(s)