/givecash [playername] [money]
#1

Please someone give me working and tested code to make command like this: /givecash [playername] [amount], /givexp [playername] [amount]... I will be very grateful
Reply
#2

pawn Код:
if(strcmp(cmd, "/money", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "/money [playerid/PartOfName] [money] - give a player a specific money value.");
                return 1;
            }
            new playa;
            new money;
            playa = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            money = strval(tmp);               
            if(IsPlayerConnected(playa))
                {
                    new pname[MAX_PLAYER_NAME];
                    if(playa != INVALID_PLAYER_ID)
                    {
                        GivePlayerMoney(playa, money);
                        GetPlayerName(playa, pname, sizeof(pname));
                        format(string, sizeof(string), "You gave %s %d money", pname,money);
                        SendClientMessage(playerid, COLOR_ORANGE, string);
                    }
                }
            }
        return 1;
    }
Reply
#3

You will need sscanf and zcmd

pawn Код:
CMD:givecash(playerid, params[])
{
        new
            pMsg[74],
            pID,
            Money;
           
    if(sscanf(params, "ui", pID, Money)) return SendClientMessage(playerid, 0xFFFFFFAA, "{FF6600}Use: {FFFFFF}/givecash [playerid/Name-ID] [Money]");
    {
        GivePlayerMoney(pID, Money);
        format(pMsg, 74, "{8B8989}INFO: {FFFFFF}%s has gave you $%i.", GetName(playerid), Money);
        SendClientMessage(pID, 0xFFFFFFAA, pMsg);
        format(pMsg, 74, "{8B8989}INFO: {FFFFFF}You gave $%i to player %s.", Money, GetName(pID));
        SendClientMessage(playerid, 0xFFFFFFAA, pMsg);
    }
    return true;
}

stock GetName(playerid)
{
    new
        pName[24];
       
    GetPlayerName(playerid, pName, 24);
    return pName;
}
Reply
#4

Quote:
Originally Posted by black_dota
Посмотреть сообщение
You will need sscanf and zcmd

pawn Код:
CMD:givecash(playerid, params[])
{
        new
            pMsg[74],
            pID,
            Money;
           
    if(sscanf(params, "ui", pID, Money)) return SendClientMessage(playerid, 0xFFFFFFAA, "{FF6600}Use: {FFFFFF}/givecash [playerid/Name-ID] [Money]");
    {
        GivePlayerMoney(pID, Money);
        format(pMsg, 74, "{8B8989}INFO: {FFFFFF}%s has gave you $%i.", GetName(playerid), Money);
        SendClientMessage(pID, 0xFFFFFFAA, pMsg);
        format(pMsg, 74, "{8B8989}INFO: {FFFFFF}You gave $%i to player %s.", Money, GetName(pID));
        SendClientMessage(playerid, 0xFFFFFFAA, pMsg);
    }
    return true;
}

stock GetName(playerid)
{
    new
        pName[24];
       
    GetPlayerName(playerid, pName, 24);
    return pName;
}
Or he could just use strcmp ...xD
Reply
#5

Strcmp is slower than zcmd, it is more complicated, and there is much more reasons why to use zcmd and sscanf
It is more optimized and faster, and it is easy to create a commands with zcmd and sscanf.
Reply
#6

Quote:
Originally Posted by black_dota
Посмотреть сообщение
You will need sscanf and zcmd

pawn Код:
CMD:givecash(playerid, params[])
{
        new
            pMsg[74],
            pID,
            Money;
           
    if(sscanf(params, "ui", pID, Money)) return SendClientMessage(playerid, 0xFFFFFFAA, "{FF6600}Use: {FFFFFF}/givecash [playerid/Name-ID] [Money]");
    {
        GivePlayerMoney(pID, Money);
        format(pMsg, 74, "{8B8989}INFO: {FFFFFF}%s has gave you $%i.", GetName(playerid), Money);
        SendClientMessage(pID, 0xFFFFFFAA, pMsg);
        format(pMsg, 74, "{8B8989}INFO: {FFFFFF}You gave $%i to player %s.", Money, GetName(pID));
        SendClientMessage(playerid, 0xFFFFFFAA, pMsg);
    }
    return true;
}

stock GetName(playerid)
{
    new
        pName[24];
       
    GetPlayerName(playerid, pName, 24);
    return pName;
}
This bugged...
This dont leave a money at player
Reply
#7

pawn Код:
//sscanf and zcmd, download links in my signature

COMMAND:givecash(playerid, params[])
{
    new targetid, amount;
    if(sscanf(params, "ui", targetid, amount)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /givecash [playerid | name] [amount]");
    else if(IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "That player is not connected");
    {
        new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME];
        new string[45];
        GetPlayerName(playerid, playername, sizeof(playername));
        GetPlayerName(targetid, targetname, sizeof(targetname));
       
        GivePlayerMoney(playerid, -amount);
        GivePlayerMoney(targetid, amount);
       
        format(string, sizeof(string), "%s gave you $%i.", playername, amount);
        SendClientMessage(targetid, 0xFFFFFFAA, string);
       
        format(string, sizeof(string), "You gave %s $%i.", targetname, amount);
        SendClientMessage(playerid, 0xFFFFFFAA, string);
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by SkizzoTrick
Посмотреть сообщение
Or he could just use strcmp ...xD
WHAT DID YOU JUST SAY?!?
It's slow, it's complicated, it's outdated, there is no reason to use it anymore for commands. In short: it sux.
I'd never expect you to say that o_O...
Reply
#9

Quote:
Originally Posted by Mean
Посмотреть сообщение
WHAT DID YOU JUST SAY?!?
It's slow, it's complicated, it's outdated, there is no reason to use it anymore for commands. In short: it sux.
I'd never expect you to say that o_O...
lol i use it. and its really easy. and for me its not slow. and i only use strcmp and dcmd. the sad thing is that i can't have zcmd and dcmd on the same gamemode D:
Reply
#10

Sorry but I need /givecash [playername (ONLY playername)] [amount]. Please someone give me this fucking code, because I need it and I will be very grateful to you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)