strcmp - How would I do this?
#1

Hello. I'm in the process of creating a trunk system for my server (it's already made, I'm actually just making changes).
I'm putting it all into one command so that the player will be prompted to input

Quote:

/vtrunk [withdraw/deposit] [item] [amount]

At the moment, I have it working so that players can withdraw and deposit money, and weapon parts, however, how would I make it so that they could do:

Quote:

/vtrunk balance

and not be required to input an item or amount?

Here is the script.

pawn Код:
CMD:vtrunk(playerid, params[]) {
    new
        type[12],
        amount,
        item[12],
        vid = GetClosestVehicle(playerid);

    if(sscanf(params, "s[12]s[12]d", type, item, amount)) {
        SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/vtrunk [deposit/withdraw] [item] [amount]");
        return SendClientMessage(playerid, COLOR_GREY, "Items: Money, Parts, Weapon");
    }
    else {
        if(IsPlayerInRangeOfVehicle(playerid, vid, 5.0)) {
            if(vehicleVariables[vid][vVehicleGroup] == playerVariables[playerid][pGroup] || IsPlayerVehicleOwner(playerid, vid) || DoesPlayerHaveKey(playerid, vid)) {
                if(strcmp(type, "deposit", true) == 0) {
                    if(strcmp(item, "money", true) == 0) {
                        if(playerVariables[playerid][pMoney] >= amount) {
                            if(amount < 1)
                                return SendClientMessage(playerid, COLOR_GREY, "Invalid amount.");
                            playerVariables[playerid][pMoney] -= amount;
                            vehicleVariables[vid][vVehicleMoney] += amount;
                            format(szMessage, sizeof(szMessage), "* %s opens the trunk of the %s, and stores some money in it.", playerVariables[playerid][pNormalName], VehicleNames[GetVehicleModel(vid) - 400]);
                            nearByMessage(playerid, COLOR_PURPLE, szMessage);
                            saveVehicle(vid);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "You do not have that much money!");
                    }
                    else if(strcmp(item, "parts", true) == 0) {
                        if(playerVariables[playerid][pMaterials] >= amount) {
                            if(amount < 1)
                                return SendClientMessage(playerid, COLOR_GREY, "Invalid amount.");
                            playerVariables[playerid][pMaterials] -= amount;
                            vehicleVariables[vid][vVehicleParts] += amount;
                            format(szMessage, sizeof(szMessage), "* %s opens the trunk of the %s, and stores some parts in it.", playerVariables[playerid][pNormalName], VehicleNames[GetVehicleModel(vid) - 400]);
                            nearByMessage(playerid, COLOR_PURPLE, szMessage);
                            saveVehicle(vid);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "You do not have that many parts!");
                    }
                }
                else if(strcmp(type, "withdraw", true) == 0) {
                    if(strcmp(item, "money", true) == 0) {
                        if(vehicleVariables[vid][vVehicleMoney] >= amount) {
                            if(amount < 1)
                                return SendClientMessage(playerid, COLOR_GREY, "Invalid amount.");
                            playerVariables[playerid][pMoney] += amount;
                            vehicleVariables[vid][vVehicleMoney] -= amount;
                            format(szMessage, sizeof(szMessage), "* %s opens the trunk of the %s, and takes some money from it.", playerVariables[playerid][pNormalName], VehicleNames[GetVehicleModel(vid) - 400]);
                            nearByMessage(playerid, COLOR_PURPLE, szMessage);
                            saveVehicle(vid);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "There is not that much money in the trunk!");
                    }
                    else if(strcmp(item, "parts", true) == 0) {
                        if(vehicleVariables[vid][vVehicleParts] >= amount) {
                            if(amount < 1)
                                return SendClientMessage(playerid, COLOR_GREY, "Invalid amount.");
                            playerVariables[playerid][pMaterials] += amount;
                            vehicleVariables[vid][vVehicleParts] -= amount;
                            format(szMessage, sizeof(szMessage), "* %s opens the trunk of the %s, and takes some parts from it.", playerVariables[playerid][pNormalName], VehicleNames[GetVehicleModel(vid) - 400]);
                            nearByMessage(playerid, COLOR_PURPLE, szMessage);
                            saveVehicle(vid);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "There are not that many parts in the trunk!");
                    }
                }
            }
            else SendClientMessage(playerid, COLOR_GREY, "You do not have a key to this vehicle!");
        }
        else SendClientMessage(playerid, COLOR_GREY, "You are not near any vehicles!");
    }
    return 1;
}
Thank-you in advance for any help given!
Reply
#2

Make the two final parameters optional, so like this:

pawn Код:
if(sscanf(params, "s[12]S[12]D", type, item, amount))
Capitalised means it's optional, therefore they do not have to be entered.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)