How to make this little feature?
#1

Hello, i've made this /inventory command

How to make that, if the inventory it will just say in the dialog box "Your inventory is empty"?

pawn Code:
stock ShowInventory(playerid,targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
    {
        // format stats and send to playerPlayerInfo[targetid][pLottoNr]
        new string[1200];
        new string2[1200];
        new phonebook[20],lottonumber[20],screwdriver[20],fish[20],briefcase[20],seeds[20],blindfold[20],crack[30],pot[30],adrenaline[30],a[30],b[30],c[30],d[30],products[30],dice[30],cards[30];
        if(PlayerInfo[targetid][pPhoneBook] == 0) phonebook = ""; else format(phonebook, sizeof(phonebook), "a phone book, ");
        if(PlayerInfo[targetid][pLottoNr] == 0) lottonumber = ""; else format(lottonumber, sizeof(lottonumber), "a Lotto Cupon %d, ", PlayerInfo[targetid][pLottoNr]);
        if(PlayerInfo[targetid][pScrew] == 0) screwdriver = ""; else format(screwdriver, sizeof(screwdriver), "a screwdriver, ", PlayerInfo[targetid][pLottoNr]);
        if(PlayerInfo[targetid][pFishes] == 0) fish = ""; else format(fish, sizeof(fish), "a %s, ", PlayerInfo[targetid][pFishes]);
        if(PlayerInfo[targetid][pBriefCase] == 0) briefcase = ""; else format(briefcase, sizeof(briefcase), "a briefcase, ");
        if(PlayerInfo[targetid][pWSeeds] == 0) seeds = ""; else format(seeds, sizeof(seeds), "%d seeds, ", PlayerInfo[targetid][pWSeeds]);
        if(PlayerInfo[targetid][pBlindfolds] == 0) blindfold = ""; else format(blindfold, sizeof(blindfold), "a blindfold, ");
        if(PlayerInfo[targetid][pCrack] == 0) crack = ""; else format(crack, sizeof(crack), "%d grams of crack, ", PlayerInfo[targetid][pCrack]);
        if(PlayerInfo[targetid][pPot] == 0) pot = ""; else format(pot, sizeof(pot), "%d grams of pot, ", PlayerInfo[targetid][pPot]);
        if(PlayerInfo[targetid][pAdrenaline] == 0) adrenaline = ""; else format(adrenaline, sizeof(adrenaline), "%d adrenaline syringes, ", PlayerInfo[targetid][pAdrenaline]);
        if(PlayerInfo[targetid][pMats] == 0) a = ""; else format(a, sizeof(a), "%d A materials, ", PlayerInfo[targetid][pMats]);
        if(PlayerInfo[targetid][pMats] == 0) b = ""; else format(b, sizeof(b), "%d B materials, ", PlayerInfo[targetid][pMatsb]);
        if(PlayerInfo[targetid][pMatsc] == 0) c = ""; else format(c, sizeof(c), "%d C materials, ", PlayerInfo[targetid][pMatsc]);
        if(PlayerInfo[targetid][pMatsd] == 0) d = ""; else format(d, sizeof(d), "%d D materials, ", PlayerInfo[targetid][pMatsd]);
        if(PlayerInfo[targetid][pProducts] == 0) products = ""; else format(products, sizeof(products), "%d products, ", PlayerInfo[targetid][pProducts]);
        if(PlayerInfo[targetid][pDice] == 0) dice = ""; else format(dice, sizeof(dice), "a dice, ");
        if(PlayerInfo[targetid][pDeck] == 0) cards = ""; else format(cards, sizeof(cards), "a deck of cards, ");
        format(string, sizeof(string), ""COL_GREEN"Mats & Drugs - "COL_WHITE"%s%s%s%s%s%s%s%s%s%s\n",crack,pot,adrenaline,a,b,c,d,products,dice,cards);
        strcat(string2,string);
        format(string, sizeof(string), ""COL_GREEN"Odds & Ends - "COL_WHITE"%s%s%s%s%s%s%s\n",blindfold,seeds,briefcase,screwdriver,fish,lottonumber,phonebook);
        strcat(string2,string);
        format(string, sizeof string, ""COL_WHITE"Your Inventory:");
        ShowPlayerDialog(playerid,DIALOG_INVENTORY,DIALOG_STYLE_MSGBOX, string, string2,"Done","Print");
    }
}
Reply
#2

- delete -
Reply
#3

Code:
stock ShowInventory(playerid,targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
	{
		// format stats and send to playerPlayerInfo[targetid][pLottoNr]
		new string[1200];
		new string2[1200];
		new phonebook[20],lottonumber[20],screwdriver[20],fish[20],briefcase[20],seeds[20],blindfold[20],crack[30],pot[30],adrenaline[30],a[30],b[30],c[30],d[30],products[30],dice[30],cards[30];
                if(PlayerInfo[targetid][pPhoneBook] == 0 && PlayerInfo[targetid][pLottoNr] == 0 && PlayerInfo[targetid][pScrew] == 0 && PlayerInfo[targetid][pFishes] == 0 && PlayerInfo[targetid][pBriefCase] == 0 && PlayerInfo[targetid][pWSeeds] == 0 && PlayerInfo[targetid][pBlindfolds] == 0 && PlayerInfo[targetid][pCrack] == 0 && PlayerInfo[targetid][pPot] == 0 && PlayerInfo[targetid][pAdrenaline] == 0 && PlayerInfo[targetid][pMats] == 0 && PlayerInfo[targetid][pMats] == 0 && PlayerInfo[targetid][pMatsc] == 0 && PlayerInfo[targetid][pProducts] == 0 && PlayerInfo[targetid][pDice] == 0 && PlayerInfo[targetid][pDeck] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "* Your inventory is empty");
		if(PlayerInfo[targetid][pPhoneBook] == 0) phonebook = ""; else format(phonebook, sizeof(phonebook), "a phone book, ");
		if(PlayerInfo[targetid][pLottoNr] == 0) lottonumber = ""; else format(lottonumber, sizeof(lottonumber), "a Lotto Cupon %d, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pScrew] == 0) screwdriver = ""; else format(screwdriver, sizeof(screwdriver), "a screwdriver, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pFishes] == 0) fish = ""; else format(fish, sizeof(fish), "a %s, ", PlayerInfo[targetid][pFishes]);
		if(PlayerInfo[targetid][pBriefCase] == 0) briefcase = ""; else format(briefcase, sizeof(briefcase), "a briefcase, ");
		if(PlayerInfo[targetid][pWSeeds] == 0) seeds = ""; else format(seeds, sizeof(seeds), "%d seeds, ", PlayerInfo[targetid][pWSeeds]);
		if(PlayerInfo[targetid][pBlindfolds] == 0) blindfold = ""; else format(blindfold, sizeof(blindfold), "a blindfold, ");
		if(PlayerInfo[targetid][pCrack] == 0) crack = ""; else format(crack, sizeof(crack), "%d grams of crack, ", PlayerInfo[targetid][pCrack]);
		if(PlayerInfo[targetid][pPot] == 0) pot = ""; else format(pot, sizeof(pot), "%d grams of pot, ", PlayerInfo[targetid][pPot]);
		if(PlayerInfo[targetid][pAdrenaline] == 0) adrenaline = ""; else format(adrenaline, sizeof(adrenaline), "%d adrenaline syringes, ", PlayerInfo[targetid][pAdrenaline]);
		if(PlayerInfo[targetid][pMats] == 0) a = ""; else format(a, sizeof(a), "%d A materials, ", PlayerInfo[targetid][pMats]);
		if(PlayerInfo[targetid][pMats] == 0) b = ""; else format(b, sizeof(b), "%d B materials, ", PlayerInfo[targetid][pMatsb]);
		if(PlayerInfo[targetid][pMatsc] == 0) c = ""; else format(c, sizeof©, "%d C materials, ", PlayerInfo[targetid][pMatsc]);
		if(PlayerInfo[targetid][pMatsd] == 0) d = ""; else format(d, sizeof(d), "%d D materials, ", PlayerInfo[targetid][pMatsd]);
		if(PlayerInfo[targetid][pProducts] == 0) products = ""; else format(products, sizeof(products), "%d products, ", PlayerInfo[targetid][pProducts]);
		if(PlayerInfo[targetid][pDice] == 0) dice = ""; else format(dice, sizeof(dice), "a dice, ");
		if(PlayerInfo[targetid][pDeck] == 0) cards = ""; else format(cards, sizeof(cards), "a deck of cards, ");
		format(string, sizeof(string), ""COL_GREEN"Mats & Drugs - "COL_WHITE"%s%s%s%s%s%s%s%s%s%s\n",crack,pot,adrenaline,a,b,c,d,products,dice,cards);
		strcat(string2,string);
		format(string, sizeof(string), ""COL_GREEN"Odds & Ends - "COL_WHITE"%s%s%s%s%s%s%s\n",blindfold,seeds,briefcase,screwdriver,fish,lottonumber,phonebook);
		strcat(string2,string);
        format(string, sizeof string, ""COL_WHITE"Your Inventory:");
		ShowPlayerDialog(playerid,DIALOG_INVENTORY,DIALOG_STYLE_MSGBOX, string, string2,"Done","Print");
	}
}
Reply
#4

Make a 'flag' variable (1/0) which is initially a zero. Once something in the inventory is not 0, change the 'flag' variable's value to 1.

At the end, before formatting all check if the flag is 0 and if so print 'Inventory is empty'.
Reply
#5

Quote:
Originally Posted by K0P
View Post
Code:
stock ShowInventory(playerid,targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
	{
		// format stats and send to playerPlayerInfo[targetid][pLottoNr]
		new string[1200];
		new string2[1200];
		new phonebook[20],lottonumber[20],screwdriver[20],fish[20],briefcase[20],seeds[20],blindfold[20],crack[30],pot[30],adrenaline[30],a[30],b[30],c[30],d[30],products[30],dice[30],cards[30];
                if(PlayerInfo[targetid][pPhoneBook] == 0 && PlayerInfo[targetid][pLottoNr] == 0 && PlayerInfo[targetid][pScrew] == 0 && PlayerInfo[targetid][pFishes] == 0 && PlayerInfo[targetid][pBriefCase] == 0 && PlayerInfo[targetid][pWSeeds] == 0 && PlayerInfo[targetid][pBlindfolds] == 0 && PlayerInfo[targetid][pCrack] == 0 && PlayerInfo[targetid][pPot] == 0 && PlayerInfo[targetid][pAdrenaline] == 0 && PlayerInfo[targetid][pMats] == 0 && PlayerInfo[targetid][pMats] == 0 && PlayerInfo[targetid][pMatsc] == 0 && PlayerInfo[targetid][pProducts] == 0 && PlayerInfo[targetid][pDice] == 0 && PlayerInfo[targetid][pDeck] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "* Your inventory is empty");
		if(PlayerInfo[targetid][pPhoneBook] == 0) phonebook = ""; else format(phonebook, sizeof(phonebook), "a phone book, ");
		if(PlayerInfo[targetid][pLottoNr] == 0) lottonumber = ""; else format(lottonumber, sizeof(lottonumber), "a Lotto Cupon %d, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pScrew] == 0) screwdriver = ""; else format(screwdriver, sizeof(screwdriver), "a screwdriver, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pFishes] == 0) fish = ""; else format(fish, sizeof(fish), "a %s, ", PlayerInfo[targetid][pFishes]);
		if(PlayerInfo[targetid][pBriefCase] == 0) briefcase = ""; else format(briefcase, sizeof(briefcase), "a briefcase, ");
		if(PlayerInfo[targetid][pWSeeds] == 0) seeds = ""; else format(seeds, sizeof(seeds), "%d seeds, ", PlayerInfo[targetid][pWSeeds]);
		if(PlayerInfo[targetid][pBlindfolds] == 0) blindfold = ""; else format(blindfold, sizeof(blindfold), "a blindfold, ");
		if(PlayerInfo[targetid][pCrack] == 0) crack = ""; else format(crack, sizeof(crack), "%d grams of crack, ", PlayerInfo[targetid][pCrack]);
		if(PlayerInfo[targetid][pPot] == 0) pot = ""; else format(pot, sizeof(pot), "%d grams of pot, ", PlayerInfo[targetid][pPot]);
		if(PlayerInfo[targetid][pAdrenaline] == 0) adrenaline = ""; else format(adrenaline, sizeof(adrenaline), "%d adrenaline syringes, ", PlayerInfo[targetid][pAdrenaline]);
		if(PlayerInfo[targetid][pMats] == 0) a = ""; else format(a, sizeof(a), "%d A materials, ", PlayerInfo[targetid][pMats]);
		if(PlayerInfo[targetid][pMats] == 0) b = ""; else format(b, sizeof(b), "%d B materials, ", PlayerInfo[targetid][pMatsb]);
		if(PlayerInfo[targetid][pMatsc] == 0) c = ""; else format(c, sizeof©, "%d C materials, ", PlayerInfo[targetid][pMatsc]);
		if(PlayerInfo[targetid][pMatsd] == 0) d = ""; else format(d, sizeof(d), "%d D materials, ", PlayerInfo[targetid][pMatsd]);
		if(PlayerInfo[targetid][pProducts] == 0) products = ""; else format(products, sizeof(products), "%d products, ", PlayerInfo[targetid][pProducts]);
		if(PlayerInfo[targetid][pDice] == 0) dice = ""; else format(dice, sizeof(dice), "a dice, ");
		if(PlayerInfo[targetid][pDeck] == 0) cards = ""; else format(cards, sizeof(cards), "a deck of cards, ");
		format(string, sizeof(string), ""COL_GREEN"Mats & Drugs - "COL_WHITE"%s%s%s%s%s%s%s%s%s%s\n",crack,pot,adrenaline,a,b,c,d,products,dice,cards);
		strcat(string2,string);
		format(string, sizeof(string), ""COL_GREEN"Odds & Ends - "COL_WHITE"%s%s%s%s%s%s%s\n",blindfold,seeds,briefcase,screwdriver,fish,lottonumber,phonebook);
		strcat(string2,string);
        format(string, sizeof string, ""COL_WHITE"Your Inventory:");
		ShowPlayerDialog(playerid,DIALOG_INVENTORY,DIALOG_STYLE_MSGBOX, string, string2,"Done","Print");
	}
}
How to make that long Line shorter?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)