How to make this shorter?
#1

How to make this line shorter?

pawn Код:
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");
Reply
#2

Код:
 if(.. \
    .. == 1337)
Reply
#3

Quote:
Originally Posted by d1git
Посмотреть сообщение
Код:
 if(.. \
    .. == 1337)
Huh?
Reply
#4

PHP код:
if(PlayerInfo[targetid][pPhoneBook] == PlayerInfo[targetid][pLottoNr] == PlayerInfo[targetid][pScrew] == PlayerInfo[targetid][pFishes] == PlayerInfo[targetid][pBriefCase] == PlayerInfo[targetid][pWSeeds] == PlayerInfo[targetid][pBlindfolds] == PlayerInfo[targetid][pCrack] == PlayerInfo[targetid][pPot] == PlayerInfo[targetid][pAdrenaline] == PlayerInfo[targetid][pMats] == PlayerInfo[targetid][pMats] == PlayerInfo[targetid][pMatsc] == PlayerInfo[targetid][pProducts] == PlayerInfo[targetid][pDice] == PlayerInfo[targetid][pDeck] == 0) return SendClientMessage(playerid0xFFFFFFFF"* Your inventory is empty"); 
Try this. This is faster and shorter, faster is meant by the speed of executing this code.

EDIT: Try this, i have did some edits in this.

PHP код:
if(PlayerInfo[targetid][pPhoneBook] == PlayerInfo[targetid][pLottoNr] == PlayerInfo[targetid][pScrew] == \
PlayerInfo[targetid][pFishes] == PlayerInfo[targetid][pBriefCase] == PlayerInfo[targetid][pWSeeds] == \
PlayerInfo[targetid][pBlindfolds] == PlayerInfo[targetid][pCrack] == PlayerInfo[targetid][pPot] ==\
PlayerInfo[targetid][pAdrenaline] == PlayerInfo[targetid][pMats] == PlayerInfo[targetid][pMats] ==\
PlayerInfo[targetid][pMatsc] == PlayerInfo[targetid][pProducts] == PlayerInfo[targetid][pDice] ==\
PlayerInfo[targetid][pDeck] == 0) return SendClientMessage(playerid0xFFFFFFFF"* Your inventory is empty"); 
Reply
#5

Oh wait, what do you mean by 'shorter'?

EDIT: Yeah, the reply above this one is what I meant, sorry if it confused you.
Reply
#6

Quote:
Originally Posted by d1git
Посмотреть сообщение
Oh wait, what do you mean by 'shorter'?

EDIT: Yeah, the reply above this one is what I meant, sorry if it confused you.
Shorter means shorter code that it fits in a line in Pawno and is easier to write.
Reply
#7

Код:
stock ShowInventory(playerid,targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
	{
		// format stats and send to playerPlayerInfo[targetid][pLottoNr]
		new string[1200];
		new string2[1200];
		
		new check[18];
		new count;
		
		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) check[0] = 0; phonebook = ""; else format(phonebook, sizeof(phonebook), "a phone book, ");
		if(PlayerInfo[targetid][pLottoNr] == 0) check[1] = 0; lottonumber = ""; else format(lottonumber, sizeof(lottonumber), "a Lotto Cupon %d, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pScrew] == 0) check[2] = 0; screwdriver = ""; else format(screwdriver, sizeof(screwdriver), "a screwdriver, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pFishes] == 0) check[3] = 0; fish = ""; else format(fish, sizeof(fish), "a %s, ", PlayerInfo[targetid][pFishes]);
		if(PlayerInfo[targetid][pBriefCase] == 0) check[4] = 0; briefcase = ""; else format(briefcase, sizeof(briefcase), "a briefcase, ");
		if(PlayerInfo[targetid][pWSeeds] == 0) check[5] = 0; seeds = ""; else format(seeds, sizeof(seeds), "%d seeds, ", PlayerInfo[targetid][pWSeeds]);
		if(PlayerInfo[targetid][pBlindfolds] == 0) check[6] = 0; blindfold = ""; else format(blindfold, sizeof(blindfold), "a blindfold, ");
		if(PlayerInfo[targetid][pCrack] == 0) check[7] = 0; crack = ""; else format(crack, sizeof(crack), "%d grams of crack, ", PlayerInfo[targetid][pCrack]);
		if(PlayerInfo[targetid][pPot] == 0) check[8] = 0; pot = ""; else format(pot, sizeof(pot), "%d grams of pot, ", PlayerInfo[targetid][pPot]);
		if(PlayerInfo[targetid][pAdrenaline] == 0) check[9] = 0; adrenaline = ""; else format(adrenaline, sizeof(adrenaline), "%d adrenaline syringes, ", PlayerInfo[targetid][pAdrenaline]);
		if(PlayerInfo[targetid][pMats] == 0) check[10] = 0; a = ""; else format(a, sizeof(a), "%d A materials, ", PlayerInfo[targetid][pMats]);
		if(PlayerInfo[targetid][pMats] == 0) check[11] = 0; b = ""; else format(b, sizeof(b), "%d B materials, ", PlayerInfo[targetid][pMatsb]);
		if(PlayerInfo[targetid][pMatsc] == 0) check[12] = 0; c = ""; else format(c, sizeof©, "%d C materials, ", PlayerInfo[targetid][pMatsc]);
		if(PlayerInfo[targetid][pMatsd] == 0) check[13] = 0; d = ""; else format(d, sizeof(d), "%d D materials, ", PlayerInfo[targetid][pMatsd]);
		if(PlayerInfo[targetid][pProducts] == 0) check[14] = 0; products = ""; else format(products, sizeof(products), "%d products, ", PlayerInfo[targetid][pProducts]);
		if(PlayerInfo[targetid][pDice] == 0) check[15] = 0; dice = ""; else format(dice, sizeof(dice), "a dice, ");
		if(PlayerInfo[targetid][pDeck] == 0) check[16] = 0; cards = ""; else format(cards, sizeof(cards), "a deck of cards, ");

        for(new i = 0; i < sizeof(check); i++)
        {
			if(check[i] == 0)
			{
				count++;
			}
        }
        
        if(count >= 17) return SendClientMessage(playerid, 0xFFFFFFFF, "* Your inventory is empty");

		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
#8

Quote:
Originally Posted by K0P
Посмотреть сообщение
Код:
stock ShowInventory(playerid,targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
	{
		// format stats and send to playerPlayerInfo[targetid][pLottoNr]
		new string[1200];
		new string2[1200];
		
		new check[18];
		new count;
		
		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) check[0] = 0; phonebook = ""; else format(phonebook, sizeof(phonebook), "a phone book, ");
		if(PlayerInfo[targetid][pLottoNr] == 0) check[1] = 0; lottonumber = ""; else format(lottonumber, sizeof(lottonumber), "a Lotto Cupon %d, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pScrew] == 0) check[2] = 0; screwdriver = ""; else format(screwdriver, sizeof(screwdriver), "a screwdriver, ", PlayerInfo[targetid][pLottoNr]);
		if(PlayerInfo[targetid][pFishes] == 0) check[3] = 0; fish = ""; else format(fish, sizeof(fish), "a %s, ", PlayerInfo[targetid][pFishes]);
		if(PlayerInfo[targetid][pBriefCase] == 0) check[4] = 0; briefcase = ""; else format(briefcase, sizeof(briefcase), "a briefcase, ");
		if(PlayerInfo[targetid][pWSeeds] == 0) check[5] = 0; seeds = ""; else format(seeds, sizeof(seeds), "%d seeds, ", PlayerInfo[targetid][pWSeeds]);
		if(PlayerInfo[targetid][pBlindfolds] == 0) check[6] = 0; blindfold = ""; else format(blindfold, sizeof(blindfold), "a blindfold, ");
		if(PlayerInfo[targetid][pCrack] == 0) check[7] = 0; crack = ""; else format(crack, sizeof(crack), "%d grams of crack, ", PlayerInfo[targetid][pCrack]);
		if(PlayerInfo[targetid][pPot] == 0) check[8] = 0; pot = ""; else format(pot, sizeof(pot), "%d grams of pot, ", PlayerInfo[targetid][pPot]);
		if(PlayerInfo[targetid][pAdrenaline] == 0) check[9] = 0; adrenaline = ""; else format(adrenaline, sizeof(adrenaline), "%d adrenaline syringes, ", PlayerInfo[targetid][pAdrenaline]);
		if(PlayerInfo[targetid][pMats] == 0) check[10] = 0; a = ""; else format(a, sizeof(a), "%d A materials, ", PlayerInfo[targetid][pMats]);
		if(PlayerInfo[targetid][pMats] == 0) check[11] = 0; b = ""; else format(b, sizeof(b), "%d B materials, ", PlayerInfo[targetid][pMatsb]);
		if(PlayerInfo[targetid][pMatsc] == 0) check[12] = 0; c = ""; else format(c, sizeof©, "%d C materials, ", PlayerInfo[targetid][pMatsc]);
		if(PlayerInfo[targetid][pMatsd] == 0) check[13] = 0; d = ""; else format(d, sizeof(d), "%d D materials, ", PlayerInfo[targetid][pMatsd]);
		if(PlayerInfo[targetid][pProducts] == 0) check[14] = 0; products = ""; else format(products, sizeof(products), "%d products, ", PlayerInfo[targetid][pProducts]);
		if(PlayerInfo[targetid][pDice] == 0) check[15] = 0; dice = ""; else format(dice, sizeof(dice), "a dice, ");
		if(PlayerInfo[targetid][pDeck] == 0) check[16] = 0; cards = ""; else format(cards, sizeof(cards), "a deck of cards, ");

        for(new i = 0; i < sizeof(check); i++)
        {
			if(check[i] == 0)
			{
				count++;
			}
        }
        
        if(count >= 17) return SendClientMessage(playerid, 0xFFFFFFFF, "* Your inventory is empty");

		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");
	}
}
You have copied the whole code from a gamemode, don't be so over smart.

Quote:

This forum requires that you wait 120 seconds between posts. Please try again in 43 seconds.

Dayum... SA-MP forum's anti spam.
Reply
#9

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
You have copied the whole code from a gamemode, don't be so over smart.


Dayum... SA-MP forum's anti spam.


lol noob.Why are you so dumb.

Its from his previous post. https://sampforum.blast.hk/showthread.php?tid=612575

I helped him to show the message instead of showing the inventory if the inventory is empty,but the line was too long,so i posted another fix for that in this thread instead of that old.
Reply
#10

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
Shorter means shorter code that it fits in a line in Pawno and is easier to write.
Or he wanted to make his code 'more compact', as in less characters.

EDIT: That's why I started wondering.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)