Save and load GangZones
#1

How to make SaveZones and LoadZones for gamemode Gammix?: https://sampforum.blast.hk/showthread.php?tid=590991

Код:
SaveZones()
{
	new idx;
	new File: file2;
	while (idx < sizeof(ZoneInfo))
	{
		new FileString[128];
		format(FileString, sizeof(FileString), "%d,%s,%d,%d\r\n",
		ZoneInfo[idx][ZoneID],
		ZoneInfo[idx][ZoneOwner],
		ZoneInfo[idx][ZoneOwnerID],
		print(FileString);

		if(idx == 0) file2 = fopen("TurfWar/Turfs/GWturfs.ini", io_write);
		else file2 = fopen("TurfWar/Turfs/GWturfs.ini", io_append);

		fwrite(file2, FileString);
		idx++;
		fclose(file2);
	}
	return 1;
}

LoadZones()
{
	new PartOfString[12][64];
	new FileString[128];
	new File: file = fopen("TurfWar/Turfs/GWturfs.ini", io_read);
	if (file)
	{
		new idx;
		while (idx < sizeof(ZoneInfo)-1)
		{
			fread(file, FileString);
			split(FileString, PartOfString, ',');

			ZoneInfo[idx][ZoneID] = strval(PartOfString[0]);
			strmid(ZoneInfo[idx][ZoneOwner], PartOfString[1], 0, strlen(PartOfString[1]), MAX_PLAYER_NAME);
			ZoneInfo[idx][ZoneOwnerID] = strval(PartOfString[2]);

			idx++;
		}
		fclose(file);
	}
	return 1;
}
Reply
#2

https://sampwiki.blast.hk/wiki/GangZoneCreate
Reply
#3

is this code not working or what?
Reply
#4

you`ve shown us the load gangzones...whats the problem?is it taken from another gm and you want to adapt it for you or what?
Reply
#5

SaveZones and LoadZones were downloaded from another GM from Lethal. I would like to add it to GM
Gammix just do not know how. When turning off the server, gangzones are not saved.
Reply
#6

just adding the other gamemode's code in your gamemode doesn't makes anything in such a situation.
you must create a saving system by yourself or atleast give us a codes about your gangzones variables.
Reply
#7

lsgw.pwn
Код:
enum e_TEAM {
	teamId,
	teamName[45],
	teamSkin,
	teamColor,
	teamWeapon1[2],
	teamWeapon2[2],
	teamWeapon3[2],
	teamWeaponThrown[2],
	teamWeaponMelle
};

new const g_Team[][e_TEAM] = {
	{0,	"Groves",   105,    0x00FF00AA, {30, 300},  {25, 100},  {24, 100},  {17, 3}, 1},
	{0,	"Groves",   106,    0x00FF00AA, {34, 300},  {25, 100},  {24, 100},  {17, 3}, 1},
	{0,	"Groves",   107,    0x00FF00AA, {29, 300},  {27, 100},  {24, 100},  {17, 3}, 1},

	{1,	"Ballas",	102,    0x800080AA, {30, 300},  {25, 100},  {22, 100},  {16, 3}, 2},
	{1,	"Ballas",	102,    0x800080AA, {34, 300},  {25, 100},  {22, 100},  {16, 3}, 2},
	{1,	"Ballas",	102,    0x800080AA, {29, 300},  {26, 100},  {22, 100},  {16, 3}, 2},

	{2,	"Cops",	283,    0x0080FFAA, {31, 300},  {25, 100},  {24, 100},  {17, 3}, 3},
	{2,	"Cops",	285,    0x0080FFAA, {34, 300},  {25, 100},  {24, 100},  {17, 3}, 3},
	{2,	"Cops",	286,    0x0080FFAA, {29, 300},  {27, 100},  {24, 100},  {17, 3}, 3},

	{3,	"Vagos",	 108,    0xFFFF00AA, {29, 300},  {27, 100},  {23, 100},  {18, 3}, 4},
	{3,	"Vagos",	 109,    0xFFFF00AA, {34, 300},  {27, 100},  {23, 100},  {18, 3}, 4},
	{3,	"Vagos",	 110,    0xFFFF00AA, {30, 300},  {26, 100},  {23, 100},  {18, 3}, 4},

	{4,	"Aztecas",  114,    0x00FFFFAA, {30, 300},  {26, 100},  {22, 100},  {16, 3}, 5},
	{4,	"Aztecas",  115,    0x00FFFFAA, {34, 300},  {26, 100},  {22, 100},  {16, 3}, 5},
	{4,	"Aztecas",  116,    0x00FFFFAA, {29, 300},  {27, 100},  {22, 100},  {16, 3}, 5},

	{5,	"Bikers",	 247,    0xFF4B00AA, {30, 300},  {25, 100},  {24, 100},  {17, 3}, 6},
	{5,	"Bikers",	 248,    0xFF4B00AA, {34, 300},  {25, 100},  {24, 100},  {17, 3}, 6},
	{5,	"Bikers",	 249,    0xFF4B00AA, {33, 300},  {27, 100},  {24, 100},  {17, 5}, 6},

	{6,	"Barbers",  156,    0xA52A2AAA, {32, 300},  {25, 100},  {23, 100},  {16, 3}, 8},
	{6,	"Barbers",  176,    0xA52A2AAA, {34, 300},  {25, 100},  {23, 100},  {16, 3}, 8},
	{6,	"Barbers",  177,    0xA52A2AAA, {31, 300},  {27, 100},  {23, 100},  {16, 3}, 8}
};
turfs.pwn
Код:
enum e_TEAM {
	teamName[35],
	teamColor
};

enum e_TURF {
	turfName[35],
	turfOwner,
	turfAttacker,
Float:	turfPos[4],
	turfOwnerKills,
	turfAttackerKills,
	turfState,
	turfTimer,
	turfId
};

new const g_Team[][e_TEAM] = {
	{"Groves",	0x00FF00FF},
	{"Ballas", 	0x800080FF},
	{"Cops",	              0x0080FFFF},
	{"Vagos",	0xFFFF00FF},
	{"Aztecas",	0x00FFFFFF},
	{"Bikers",	0xFF4B00FF},
	{"Barbers",	0xA52A2AFF}
};

new const g_Turf[][e_TURF] = {
	{"Ganton",          0, 	NO_TEAM,    {2222.50, -1852.80, 2632.80, -1722.30}},
	{"Ganton",          0, 	NO_TEAM,    {2222.50, -1722.30, 2632.80, -1628.50}},
	{"Idlewood",        0, 	NO_TEAM,    {2124.60, -1742.30, 2222.50, -1494.00}},
	{"Idlewood",        0, 	NO_TEAM,    {1971.60, -1852.80, 2222.50, -1742.30}},
	{"Willow Field",    0, 	NO_TEAM,    {2324.00, -2059.20, 2541.70, -1852.80}},
	{"East Los Santos", 0, 	NO_TEAM,    {2421.00, -1628.50, 2632.80, -1454.30}},
	{"East Los Santos", 0, 	NO_TEAM,    {2222.50, -1628.50, 2421.00, -1494.00}},
	
	{"Jefferson",       1, 	NO_TEAM,    {2056.80, -1372.00, 2281.40, -1210.70}},
	{"Jefferson",       1, 	NO_TEAM,    {2056.80, -1210.70, 2185.30, -1126.30}},
	{"Jefferson",       1, 	NO_TEAM,    {2056.80, -1449.60, 2266.20, -1372.00}},
	{"Las Colinas",     1, 	NO_TEAM,    {1994.30, -1100.80, 2056.80,  -920.80}},
	{"Las Colinas",     1, 	NO_TEAM,    {2056.80, -1126.30, 2126.80,  -920.80}},
	{"Las Colinas",     1, 	NO_TEAM,    {2185.30, -1154.50, 2281.40,  -934.40}},
	{"Las Colinas",     1, 	NO_TEAM,    {2126.80, -1126.30, 2185.30,  -934.40}},
	{"Las Colinas",     1, 	NO_TEAM,    {2632.70, -1135.00, 2747.70,  -945.00}},
	{"Glen Park",       1, 	NO_TEAM,    {1812.60, -1350.70, 2056.80, -1100.80}},
	
	{"Idlewood",        2, 	NO_TEAM,    {1812.60, -1852.80, 1971.60, -1742.30}},
	{"Idlewood",        2, 	NO_TEAM,    {1951.60, -1742.30, 2124.60, -1602.30}},
	{"Idlewood",        2, 	NO_TEAM,    {1812.60, -1602.30, 2124.60, -1449.60}},
	{"Idlewood",        2, 	NO_TEAM,    {1812.60, -1742.30, 1951.60, -1602.30}},
	{"Pershing Square", 2, 	NO_TEAM,    {1327.8929,-1729.3352,1821.7725,-1573.5878}},

	{"East Beach",      3, 	NO_TEAM,    {2747.70, -1498.60, 2959.30, -1120.00}},
	{"Los Flores",      3, 	NO_TEAM,    {2581.70, -1393.40, 2747.70, -1135.00}},
	{"Las Colinas",     3, 	NO_TEAM,    {2281.40, -1135.00, 2632.70,  -945.00}},
	{"East Los Santos", 3, 	NO_TEAM,    {2266.20, -1494.00, 2381.60, -1372.00}},
	{"East Los Santos", 3, 	NO_TEAM,    {2281.60, -1372.00, 2381.60, -1135.00}},
	{"East Los Santos", 3, 	NO_TEAM,    {2381.60, -1454.30, 2462.10, -1135.00}},
	{"East Los Santos", 3, 	NO_TEAM,    {2462.10, -1454.30, 2581.70, -1135.00}},

	{"Willow Field",    5, 	NO_TEAM,    {1970.60, -2179.20, 2089.00, -1852.80}},
	{"Willow Field",    5, 	NO_TEAM,    {2089.00, -1989.90, 2324.00, -1852.80}},
	{"Willow Field",    5, 	NO_TEAM,    {2089.00, -2235.80, 2201.80, -1989.90}},
	{"El Corona",       5, 	NO_TEAM,    {1812.60, -2179.20, 1970.60, -1852.80}},
	{"El Corona",       5, 	NO_TEAM,    {1692.60, -2179.20, 1812.60, -1842.20}},
              {"Rodeo",    5, 	NO_TEAM,    {-187.7, -1596.76, 17.0632, -1276.6}},
              {"Rodeo",    5, 	NO_TEAM,    {422.68, -1570.2, 466.223, -1406.05}},
              {"Rodeo",    5, 	NO_TEAM,    {466.223, -1570.2, 558.099, -1385.07}},
              {"Rodeo",    5, 	NO_TEAM,    {558.099, -1684.65, 647.522, -1384.93}},
              {"Rodeo",    5, 	NO_TEAM,    {422.68, -1684.65, 558.099, -1570.2}},
              {"Rodeo",    5, 	NO_TEAM,    {312.803, -1684.65, 422.68, -1501.95}},
              {"Rodeo",    5, 	NO_TEAM,    {334.503, -1501.95, 422.68, -1406.05}},
              {"Rodeo",    5, 	NO_TEAM,    {647.712, -1804.21, 851.449, -1577.59}},

              {"Market",      	6, 	NO_TEAM,    {1252.33, -926.999, 1357.0, -910.17}},
              {"Market",      	6, 	NO_TEAM,    {1252.33, -1026.33, 1391.05, -926.999}},
              {"Market",      	6, 	NO_TEAM,    {1252.33, -1130.85, 1378.33, -1026.33}},
              {"Market",      	6, 	NO_TEAM,    {1072.66, -1416.25, 1370.85, -1130.85}},
              {"Temple",      	6, 	NO_TEAM,    {1391.05, -1026.33, 1463.9, -926.999}},
              {"Temple",      	6, 	NO_TEAM,    {1378.33, -1130.85, 1463.9, -1026.33}},
              {"Downtown LS.",    6, 	NO_TEAM,    {1370.85, -1170.87, 1463.9, -1130.85}},
              {"Downtown LS.",    6, 	NO_TEAM,    {1370.85, -1384.95, 1463.9, -1170.87}}
};
Reply
#8

Something is badly saved and loaded in a file. Will anyone help me?
Код:
LoadZones()
{
	new PartOfString[12][64];
	new FileString[128];
	new File: file = fopen("TurfWar/Turfs/GWturfs.ini", io_read);
	if (file)
	{
		new idx;
		while (idx < sizeof(g_Turf)-1)
		while (idx < sizeof(g_Team)-1)
		{
			fread(file, FileString);
			split(FileString, PartOfString, ',');

			g_Turf[idx][turfId] = strval(PartOfString[0]);
			strmid(g_Team[idx][teamName], PartOfString[1], 0, strlen(PartOfString[1]), MAX_PLAYER_NAME);
			g_Turf[idx][turfOwner] = strval(PartOfString[2]);
			g_Team[idx][teamColor] = strval(PartOfString[3]);

			printf("ZoneID: %d   ZoneOwner: %s   ZoneOwnerID: %d   Colour: %d", g_Turf[idx][turfId], g_Team[idx][teamName], g_Turf[idx][turfOwner], g_Team[idx][teamColor] );

			idx++;
		}
		fclose(file);
	}
	return 1;
}

SaveZones()
{
	new idx;
	new File: file2;
	while (idx < sizeof(g_Turf))
	while (idx < sizeof(g_Team))
	{
		new FileString[128];
		format(FileString, sizeof(FileString), "%d,%s,%d,%d\r\n",
		
		g_Turf[idx][turfId],
		g_Team[idx][teamName],
		g_Turf[idx][turfOwner],
		g_Team[idx][teamColor] );
		print(FileString);

		if(idx == 0) file2 = fopen("TurfWar/Turfs/GWturfs.ini", io_write);
		else file2 = fopen("TurfWar/Turfs/GWturfs.ini", io_append);

		fwrite(file2, FileString);
		idx++;
		fclose(file2);
	}
	return 1;
}
Reply
#9

You just need to save zone owner ID, and load when the gangzones are made.

Here is an example how you save, just do similar for loading (instead of Set, use Get).
PHP код:
public OnFilterScriptExit() {
    
// save owner
    // example with dini2
    
    
new name[35 3]; // 35 for name and 3 for id 
    
for (new isizeof(g_Turf); ji++) {
        
format(namesizeof(name), "%s%i"g_Turf[i][turfName], i);
        
dini_SetInt("filename"nameg_Turf[i][turfOwner]);
    }

Reply
#10

Quote:
Originally Posted by Gammix
Посмотреть сообщение
You just need to save zone owner ID, and load when the gangzones are made.

Here is an example how you save, just do similar for loading (instead of Set, use Get).
PHP код:
public OnFilterScriptExit() {
    
// save owner
    // example with dini2
    
    
new name[35 3]; // 35 for name and 3 for id 
    
for (new isizeof(g_Turf); ji++) {
        
format(namesizeof(name), "%s%i"g_Turf[i][turfName], i);
        
dini_SetInt("filename"nameg_Turf[i][turfOwner]);
    }

Please help!

I do not know why nothing works. Do I do something wrong?
Код:
public OnFilterScriptExit()
{
         new name[35 + 3];  

         for (new i, j = sizeof(g_Turf); i < j; i++)
         {
                 format(name, sizeof(name), "%s%i", g_Turf[i][turfName], i); 
                 dini_Set("turfs.txt", name, g_Turf[i][turfOwner]); 
         }
         return 1;
}

public OnFilterScriptInit()
{
         new name[35 + 3]; 

         for (new i, j = sizeof(g_Turf); i < j; i++) 
         {
                 format(name, sizeof(name), "%s%i", g_Turf[i][turfName], i);
                 dini_Get("turfs.txt", name);
         }
         return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)