/Accept a command
#1

Hello! How can I /accept if someone is offering me something? For example, /givemoney [id/name] [money].I want this command to send an offer and if the offer is accepted,to take my money and give them to player "x".

I found an example,but can anyone explain me better? THX!

Код:
new
    Apples[MAX_PLAYERS], // A new variable for the apples
    bool:IsRecievingApples[MAX_PLAYERS]; // A bool that will be used in the /accept command
CMD:giveapple(playerid,params[])
{
    new
        target,
        string[128],
        name[24]
    ;
    if(sscanf(params,"d",target))
    {
        return SendClientMessage(playerid, -1, "USAGE: /giveapple [playerid]");
    }
    else
    {
        IsRecievingApples[target] = true; // Set the bool to true
        GetPlayerName(playerid,name,sizeof(name));
        format(string,sizeof(string),"%s has offered you an apple. Type /accept apple to accept it.",name);
        SendClientMessage(target,-1,string);
    }
    return 1;
}
CMD:accept(playerid,params[])
{
    new
        option[11]
    ;
    if(isnull(params))
    {
        return SendClientMessage(playerid,-1,"USAGE: /accept [name]");
    }
    if(!strcmp(option,"apple",true)) // If they type "apple"
    {
        // Then it'll check if someone has offered them apples
        if(IsRecievingApples[playerid] == true)
        {
            Apples[playerid]++; // Gives them an apple
            SendClientMessage(playerid,-1,"You have recieved an apple!");
            return 1;
        }
        else
        {
            SendClientMessage(playerid, -1, "No one has offered you apples.");
            return 1;
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)