How to short this?
#1

I made a simple /buy command, it's working but anyone can help me to sort up the code a bit. It's kinda noobish and i want it to be looking better and easier to use

Код:
if (strcmp(cmd, "/buy", true) == 0)
	{
	    if(IsPlayerInRangeOfPoint(playerid, 5.0, 1566.8317, -1691.0072, 5.8906)) //PD
	    {
	        ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST,"Weapons","1. Deagle (250$)\n2.MP5 (500$)\n3.m4 (1000$)\n4. AK-47 (1000$)\n5. SD Pistol (150$)\n6. 9mm (150$)\n7. Shotgun (300$)\n8. Micro SMG (500$)\n9. Sawnoff Shotgun (700$)\n10.Combat Shotgun (1000$)\n11. Tec-9 (500$)\n12.Country Rifle (1000$)\n13. Sniper Rifle (2000$)\n14. RPG (5000$)\n14. Flame Thrower (4000$)", "Buy", "Close");
     	}
     	else if(IsPlayerInRangeOfPoint(playerid, 5.0, 2175.8867,-2259.5242,14.7734)) //bratva
     	{
     	    ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST,"Weapons","1. Deagle (250$)\n2.MP5 (500$)\n3.m4 (1000$)\n4. AK-47 (1000$)\n5. SD Pistol (150$)\n6. 9mm (150$)\n7. Shotgun (300$)\n8. Micro SMG (500$)\n9. Sawnoff Shotgun (700$)\n10.Combat Shotgun (1000$)\n11. Tec-9 (500$)\n12.Country Rifle (1000$)\n13. Sniper Rifle (2000$)\n14. RPG (5000$)\n14. Flame Thrower (4000$)", "Buy", "Close");
		}
		else if(IsPlayerInRangeOfPoint(playerid, 5.0, 2497.3757, -1687.8939, 13.5221)) //Grove Street
		{
		    ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST,"Weapons","1. Deagle (250$)\n2.MP5 (500$)\n3.m4 (1000$)\n4. AK-47 (1000$)\n5. SD Pistol (150$)\n6. 9mm (150$)\n7. Shotgun (300$)\n8. Micro SMG (500$)\n9. Sawnoff Shotgun (700$)\n10.Combat Shotgun (1000$)\n11. Tec-9 (500$)\n12.Country Rifle (1000$)\n13. Sniper Rifle (2000$)\n14. RPG (5000$)\n14. Flame Thrower (4000$)", "Buy", "Close");
		}
	    return 1;
	}
Is there any for example stock to be made for ex:
Код:
buyplaces
{
   coords
   coords
   coords
};
So I can use
Код:
If(IsPlayerInRangeOfPoint(5.0, buyplaces))
Reply
#2

pawn Код:
if (strcmp(cmd, "/buy", true) == 0)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, 1566.8317, -1691.0072, 5.8906) || IsPlayerInRangeOfPoint(playerid, 5.0, 2175.8867,-2259.5242,14.7734) || IsPlayerInRangeOfPoint(playerid, 5.0, 2497.3757, -1687.8939, 13.5221))
        {
            ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST,"Weapons","1. Deagle (250$)\n2.MP5 (500$)\n3.m4 (1000$)\n4. AK-47 (1000$)\n5. SD Pistol (150$)\n6. 9mm (150$)\n7. Shotgun (300$)\n8. Micro SMG (500$)\n9. Sawnoff Shotgun (700$)\n10.Combat Shotgun (1000$)\n11. Tec-9 (500$)\n12.Country Rifle (1000$)\n13. Sniper Rifle (2000$)\n14. RPG (5000$)\n14. Flame Thrower (4000$)", "Buy", "Close");
        }
        return 1;
    }
Reply
#3

#define MAX_BUY_PLACES 2
new Float:buyPlaces[MAX_BUY_PLACES][3] =
{
{x, y, z},
{x, y, z}// etc
};

In the command:

for (new i = 0; i < MAX_BUY_PLACES; i++)
{
if (IsPlayerInRangeOfPoint(playerid, 5.0, buyPlaces[i][0], buyPlaces[i][1], buyPlaces[i][2]))
{
// is near the point
break;
}
}
Reply
#4

Thanks guys


EDIT: I get it as undefined


Код:
new Float:buyPlaces[MAX_BUY_PLACES][3] =
{
	{1566.8317, -1691.0072, 5.8906},
	{2175.8867,-2259.5242,14.7734},
	{2497.3757, -1687.8939, 13.5221}
};
Код:
if (strcmp(cmd, "/buy", true) == 0)
	{
	    for (new i = 0; i < MAX_BUY_PLACES; i++)
		{
			if (IsPlayerInRangeOfPoint(playerid, 5.0, buyPlaces[i][0], buyPlaces[i][1], buyPlaces[i][2]))
			{
			    ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST,"Weapons","1. Deagle (250$)\n2.MP5 (500$)\n3.m4 (1000$)\n4. AK-47 (1000$)\n5. SD Pistol (150$)\n6. 9mm (150$)\n7. Shotgun (300$)\n8. Micro SMG (500$)\n9. Sawnoff Shotgun (700$)\n10.Combat Shotgun (1000$)\n11. Tec-9 (500$)\n12.Country Rifle (1000$)\n13. Sniper Rifle (2000$)\n14. RPG (5000$)\n14. Flame Thrower (4000$)", "Buy", "Close");
			}
		}
	    return 1;
	}
Код:
#define MAX_BUY_PLACES 3
Код:
error 017: undefined symbol "MAX_BUY_PLACES"
Reply
#5

#define MAX_BUY_PLACES

at top of new Float:buyPlaces[MAX_BUY_PLACES][3] =
Reply
#6

Yeah... Just saw i've placed it wrong area .....

Ty a lot <3

Both of you repped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)