Array + Loop
#1

Код:
Text3D:GangZoneLabel[MAX_GANG_ZONES];

new GW_Name_ID[][] =
{
	{"Glen Park", 0},
	{"Upper Grove", 1},
	{"Grove Street", 2},
	{"Car Wash", 3},
	{"LSPD Headquarters", 4},
	{"LS Medical Center", 5},
	{"Ferris Wheel", 6},
	{"Vinewood", 7},
	{"Filmstudios", 8},
	{"Fuel Station", 9},
	{"Tram STation", 10},
	{"Burger Shot LS North", 11},
	{"LS Parking Lot", 12},
	{"Walk of Fame", 13},
	{"LS Mall", 14},
	{"LS Beach Canal", 15},
	{"The Pig Pen Brothel", 16},
	{"Complex of Buildings", 17},
	{"Fashion Corner", 18},
	{"Lighthouse", 19},
	{"Vinewood Barracks", 20},
	{"LS North-East Building", 21}, //could use a rename
	{"Tram Barracks", 22},
	{"LS Airport", 23},
	{"Mansion", 24},
	{"Ammunation LS Canals", 25},
	{"Leisure Center", 26},
	{"LS Docks Canals", 27},
	{"LS Southside Bridge", 28},
	{"LS Cluckin' Bell Quarters", 29},
	{"LS Docks", 30},
	{"LS South-East Beach Quarters", 31},
	{"SF Building Lot", 32},
	{"Wang Cars", 33},
	{"SF Warehouse Area", 34},
	{"SF Baseball Quarters", 35},
	{"Missionary Hill", 36},
	{"Foster Valley", 37},
	{"SF Airport", 38},
	{"SF Industrial", 39},
	{"SF Harborside", 40},
	{"SF Ship", 41},
	{"Hippie Quarters", 42},
	{"SF West Beach Quarters", 43},
	{"SF Hotel", 44},
	{"SFPD Headquarters", 45},
	{"SF Government", 46},
	{"SF Medical Center", 47},
	{"SF North-West Quarters", 48},
	{"China Town", 49},
	{"Snake Road", 50},
	{"Pier 69", 51},
	{"Otto's Autos", 52},
	{"SF Skyscrapers", 53},
	{"SF North Quarters", 54},
	{"Gant Bridge Diner and Museum", 55},
	{"Whetstone Small Farm", 56},
	{"Whetstone Grand Farm", 57}
};

public OnGameModeInit()
{
	new string[80];
	for(new i=0; i < MAX_GANG_ZONES; i++) 
	{
		format(string, sizeof(string), "» GANG ZONE «\nID: %i\nName: %s", GW_Name_ID[i][1], GW_Name_ID[i][0]);
		GangZoneLabel[i] = CreateDynamic3DTextLabel(string, C_WHITE, GW_CaptureCPs[i][0], GW_CaptureCPs[i][1], GW_CaptureCPs[i][2], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, -1, -1, 100.0);
		GangZone[i] = GangZoneCreate(GW_ZoneCoordinates[i][0], GW_ZoneCoordinates[i][1], GW_ZoneCoordinates[i][2], GW_ZoneCoordinates[i][3]);
	}
	return 1;
}
Hi people,

I'm trying to create dynamic 3DTextLabels, and I want them to show the zone's name and ID. The name works fine, but it just won't show the correct ID. Zone1, for instance, should be ID 0, but it shows me the ID 114. I'm guessing, it has something to do with the arrys for I can absolutely not find any mistake inside of the loop...

I appreciate your help!
Reply
#2

Try using enums
pawn Код:
Text3D:GangZoneLabel[MAX_GANG_ZONES];
 
 enum e_GW
 {
    GW_Name[100],
    GW_ID
}

new GW_Name_ID[][e_GW] =
{
    {"Glen Park", 0},
    {"Upper Grove", 1},
    {"Grove Street", 2},
    {"Car Wash", 3},
    {"LSPD Headquarters", 4},
    {"LS Medical Center", 5},
    {"Ferris Wheel", 6},
    {"Vinewood", 7},
    {"Filmstudios", 8},
    {"Fuel Station", 9},
    {"Tram STation", 10},
    {"Burger Shot LS North", 11},
    {"LS Parking Lot", 12},
    {"Walk of Fame", 13},
    {"LS Mall", 14},
    {"LS Beach Canal", 15},
    {"The Pig Pen Brothel", 16},
    {"Complex of Buildings", 17},
    {"Fashion Corner", 18},
    {"Lighthouse", 19},
    {"Vinewood Barracks", 20},
    {"LS North-East Building", 21}, //could use a rename
    {"Tram Barracks", 22},
    {"LS Airport", 23},
    {"Mansion", 24},
    {"Ammunation LS Canals", 25},
    {"Leisure Center", 26},
    {"LS Docks Canals", 27},
    {"LS Southside Bridge", 28},
    {"LS Cluckin' Bell Quarters", 29},
    {"LS Docks", 30},
    {"LS South-East Beach Quarters", 31},
    {"SF Building Lot", 32},
    {"Wang Cars", 33},
    {"SF Warehouse Area", 34},
    {"SF Baseball Quarters", 35},
    {"Missionary Hill", 36},
    {"Foster Valley", 37},
    {"SF Airport", 38},
    {"SF Industrial", 39},
    {"SF Harborside", 40},
    {"SF Ship", 41},
    {"Hippie Quarters", 42},
    {"SF West Beach Quarters", 43},
    {"SF Hotel", 44},
    {"SFPD Headquarters", 45},
    {"SF Government", 46},
    {"SF Medical Center", 47},
    {"SF North-West Quarters", 48},
    {"China Town", 49},
    {"Snake Road", 50},
    {"Pier 69", 51},
    {"Otto's Autos", 52},
    {"SF Skyscrapers", 53},
    {"SF North Quarters", 54},
    {"Gant Bridge Diner and Museum", 55},
    {"Whetstone Small Farm", 56},
    {"Whetstone Grand Farm", 57}
};

public OnGameModeInit()
{
    new string[80];
    for(new i=0; i < MAX_GANG_ZONES; i++)
    {
        format(string, sizeof(string), "» GANG ZONE «\nID: %i\nName: %s", GW_Name_ID[i][GW_Name], GW_Name_ID[i][GW_ID]);
        GangZoneLabel[i] = CreateDynamic3DTextLabel(string, C_WHITE, GW_CaptureCPs[i][0], GW_CaptureCPs[i][1], GW_CaptureCPs[i][2], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, -1, -1, 100.0);
        GangZone[i] = GangZoneCreate(GW_ZoneCoordinates[i][0], GW_ZoneCoordinates[i][1], GW_ZoneCoordinates[i][2], GW_ZoneCoordinates[i][3]);
    }
    return 1;
}
Fixed my last problem on my fishing system.
Reply
#3

Remove the numbers in the array; really unnecessary. You could just do it like:
pawn Код:
for(new i = 0; i < sizeof(GW_Name_ID); ++i)
{
       printf("ID: %i Name: %s", i, GW_Name_ID[i]);
}
Reply
#4

pawn Код:
new GW_Name[][] =
{
    !"Glen Park",
    !"Upper Grove",
    !"Grove Street",
    !"Car Wash",
    !"LSPD Headquarters",
    !"LS Medical Center",
    !"Ferris Wheel",
    !"Vinewood",
    !"Filmstudios",
    !"Fuel Station",
    !"Tram STation",
    !"Burger Shot LS North",
    !"LS Parking Lot",
    !"Walk of Fame",
    !"LS Mall",
    !"LS Beach Canal",
    !"The Pig Pen Brothel",
    !"Complex of Buildings",
    !"Fashion Corner",
    !"Lighthouse",
    !"Vinewood Barracks",
    !"LS North-East Building", //could use a rename
    !"Tram Barracks",
    !"LS Airport",
    !"Mansion",
    !"Ammunation LS Canals",
    !"Leisure Center",
    !"LS Docks Canals",
    !"LS Southside Bridge",
    !"LS Cluckin' Bell Quarters",
    !"LS Docks",
    !"LS South-East Beach Quarters",
    !"SF Building Lot",
    !"Wang Cars",
    !"SF Warehouse Area",
    !"SF Baseball Quarters",
    !"Missionary Hill",
    !"Foster Valley",
    !"SF Airport",
    !"SF Industrial",
    !"SF Harborside",
    !"SF Ship",
    !"Hippie Quarters",
    !"SF West Beach Quarters",
    !"SF Hotel",
    !"SFPD Headquarters",
    !"SF Government",
    !"SF Medical Center",
    !"SF North-West Quarters",
    !"China Town",
    !"Snake Road",
    !"Pier 69",
    !"Otto's Autos",
    !"SF Skyscrapers",
    !"SF North Quarters",
    !"Gant Bridge Diner and Museum",
    !"Whetstone Small Farm",
    !"Whetstone Grand Farm"
};

GetZoneName(zoneid)
{
    new str[35];

    str = "Unknown";

    if(0 <= zoneid < sizeof(GW_Name))
        strunpack(str,GW_Name);

    return str;
}

public OnGameModeInit()
{
    new string[80];
    for(new i=0; i < MAX_GANG_ZONES; i++)
    {
        format(string, sizeof(string), "» GANG ZONE «\nID: %i\nName: %s", i, GetZoneName(i));
        GangZoneLabel[i] = CreateDynamic3DTextLabel(string, C_WHITE, GW_CaptureCPs[i][0], GW_CaptureCPs[i][1], GW_CaptureCPs[i][2], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, -1, -1, 100.0);
        GangZone[i] = GangZoneCreate(GW_ZoneCoordinates[i][0], GW_ZoneCoordinates[i][1], GW_ZoneCoordinates[i][2], GW_ZoneCoordinates[i][3]);
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
new GW_Name[][] =
{
    !"Glen Park",
    !"Upper Grove",
    !"Grove Street",
    !"Car Wash",
    !"LSPD Headquarters",
    !"LS Medical Center",
    !"Ferris Wheel",
    !"Vinewood",
    !"Filmstudios",
    !"Fuel Station",
    !"Tram STation",
    !"Burger Shot LS North",
    !"LS Parking Lot",
    !"Walk of Fame",
    !"LS Mall",
    !"LS Beach Canal",
    !"The Pig Pen Brothel",
    !"Complex of Buildings",
    !"Fashion Corner",
    !"Lighthouse",
    !"Vinewood Barracks",
    !"LS North-East Building", //could use a rename
    !"Tram Barracks",
    !"LS Airport",
    !"Mansion",
    !"Ammunation LS Canals",
    !"Leisure Center",
    !"LS Docks Canals",
    !"LS Southside Bridge",
    !"LS Cluckin' Bell Quarters",
    !"LS Docks",
    !"LS South-East Beach Quarters",
    !"SF Building Lot",
    !"Wang Cars",
    !"SF Warehouse Area",
    !"SF Baseball Quarters",
    !"Missionary Hill",
    !"Foster Valley",
    !"SF Airport",
    !"SF Industrial",
    !"SF Harborside",
    !"SF Ship",
    !"Hippie Quarters",
    !"SF West Beach Quarters",
    !"SF Hotel",
    !"SFPD Headquarters",
    !"SF Government",
    !"SF Medical Center",
    !"SF North-West Quarters",
    !"China Town",
    !"Snake Road",
    !"Pier 69",
    !"Otto's Autos",
    !"SF Skyscrapers",
    !"SF North Quarters",
    !"Gant Bridge Diner and Museum",
    !"Whetstone Small Farm",
    !"Whetstone Grand Farm"
};

GetZoneName(zoneid)
{
    new str[35];

    str = "Unknown";

    if(0 <= zoneid < sizeof(GW_Name))
        strunpack(str,GW_Name);

    return str;
}

public OnGameModeInit()
{
    new string[80];
    for(new i=0; i < MAX_GANG_ZONES; i++)
    {
        format(string, sizeof(string), "» GANG ZONE «\nID: %i\nName: %s", i, GetZoneName(i));
        GangZoneLabel[i] = CreateDynamic3DTextLabel(string, C_WHITE, GW_CaptureCPs[i][0], GW_CaptureCPs[i][1], GW_CaptureCPs[i][2], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, -1, -1, 100.0);
        GangZone[i] = GangZoneCreate(GW_ZoneCoordinates[i][0], GW_ZoneCoordinates[i][1], GW_ZoneCoordinates[i][2], GW_ZoneCoordinates[i][3]);
    }
    return 1;
}
Sorry if off topic.
Wow. strunpack. Never heard of that, you know any tutorials?
Btw, if I use that, how do I get zoneID from zoneName?
Reply
#6

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
new GW_Name[][] =
{
    !"Glen Park",
    !"Upper Grove",
    !"Grove Street",
    !"Car Wash",
    !"LSPD Headquarters",
    !"LS Medical Center",
    !"Ferris Wheel",
    !"Vinewood",
    !"Filmstudios",
    !"Fuel Station",
    !"Tram STation",
    !"Burger Shot LS North",
    !"LS Parking Lot",
    !"Walk of Fame",
    !"LS Mall",
    !"LS Beach Canal",
    !"The Pig Pen Brothel",
    !"Complex of Buildings",
    !"Fashion Corner",
    !"Lighthouse",
    !"Vinewood Barracks",
    !"LS North-East Building", //could use a rename
    !"Tram Barracks",
    !"LS Airport",
    !"Mansion",
    !"Ammunation LS Canals",
    !"Leisure Center",
    !"LS Docks Canals",
    !"LS Southside Bridge",
    !"LS Cluckin' Bell Quarters",
    !"LS Docks",
    !"LS South-East Beach Quarters",
    !"SF Building Lot",
    !"Wang Cars",
    !"SF Warehouse Area",
    !"SF Baseball Quarters",
    !"Missionary Hill",
    !"Foster Valley",
    !"SF Airport",
    !"SF Industrial",
    !"SF Harborside",
    !"SF Ship",
    !"Hippie Quarters",
    !"SF West Beach Quarters",
    !"SF Hotel",
    !"SFPD Headquarters",
    !"SF Government",
    !"SF Medical Center",
    !"SF North-West Quarters",
    !"China Town",
    !"Snake Road",
    !"Pier 69",
    !"Otto's Autos",
    !"SF Skyscrapers",
    !"SF North Quarters",
    !"Gant Bridge Diner and Museum",
    !"Whetstone Small Farm",
    !"Whetstone Grand Farm"
};

GetZoneName(zoneid)
{
    new str[35];

    str = "Unknown";

    if(0 <= zoneid < sizeof(GW_Name))
        strunpack(str,GW_Name);

    return str;
}

public OnGameModeInit()
{
    new string[80];
    for(new i=0; i < MAX_GANG_ZONES; i++)
    {
        format(string, sizeof(string), "» GANG ZONE «\nID: %i\nName: %s", i, GetZoneName(i));
        GangZoneLabel[i] = CreateDynamic3DTextLabel(string, C_WHITE, GW_CaptureCPs[i][0], GW_CaptureCPs[i][1], GW_CaptureCPs[i][2], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, -1, -1, 100.0);
        GangZone[i] = GangZoneCreate(GW_ZoneCoordinates[i][0], GW_ZoneCoordinates[i][1], GW_ZoneCoordinates[i][2], GW_ZoneCoordinates[i][3]);
    }
    return 1;
}
That looks quite interesting. What do the "!"s indicate?
Reply
#7

Quote:
Originally Posted by greentarch
Посмотреть сообщение
Wow. strunpack. Never heard of that, you know any tutorials?
Btw, if I use that, how do I get zoneID from zoneName?
https://sampforum.blast.hk/showthread.php?tid=480529

zoneID you need do areas then you can with loop getting id
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)