Linhas em Array como Saber???
#1

pessoal, tenho um arquivo que utiliza uma array para guardar seus conteudos, mas o problema й que por exemplo meu arquivo tem uma 1 linha, ai eu coloco para o Loop ficar atй que idx < sizeof(minhaarray), o problema й que o tamanho da array nгo й igual a 1 й maior ai ele faz 500 vezes a mesma coisa causando lags
Reply
#2

poste oq a funзгo tem que fazer, porque nгo entendi nada.
Reply
#3

Код:
///-----------------------------------------------------------------------------
public LoadCars()
{
	new carrCoords[16][64];
	new strFromFile2[256];
	new File: file = fopen("vehicles/spawns.cfg", io_read);
	if (file)
	{
		new idx;
		new total_car = 0;
		fread(file, strFromFile2);
		split(strFromFile2, carrCoords, '|');
		while (idx < sizeof(carrCoords))
		{
			new  modelid, Float:x,Float:y,Float:z,Float:angle,color1,color2,respawn_delay,use_random_colors;
			modelid = strval(carrCoords[0]);
			x = floatstr(carrCoords[1]);
			y = floatstr(carrCoords[2]);
			z = floatstr(carrCoords[3]);
			angle = floatstr(carrCoords[4]);
			color1 = strval(carrCoords[5]);
			color2 = strval(carrCoords[6]);
			respawn_delay = strval(carrCoords[7]);
			use_random_colors = strval(carrCoords[8]);
			
		 	if (use_random_colors == 1)
			 {
			   color1 = random(255);
			   color2 = random(255);
			 }
			if (LastCarID == 0)
			{
				LastCarID = CreateVehicle(modelid ,x,y,z,angle,color1,color2,respawn_delay);
				if(total_car == 0)
				{
					total_car = 1;
				}
				else if (total_car > 0)
				{
					total_car++;
				}
			}
			else
			{
				new Float:XLastVehicle;
				new Float:YLastVehicle;
				new Float:ZLastVehicle;
				GetVehiclePos(LastCarID, XLastVehicle,YLastVehicle,ZLastVehicle);
				if (floatcmp(x,XLastVehicle) == 1 && floatcmp(y,YLastVehicle) == 1 && floatcmp(z,ZLastVehicle) == 1)
				{
					LastCarID = CreateVehicle(modelid ,x,y,z,angle,color1,color2,respawn_delay);
					if(total_car == 0)
					{
						total_car = 1;
					}
					else if (total_car > 0)
					{
						total_car++;
					}
				}
			}
			idx++;
		}
		fclose(file);
		new string[128];
		format(string, sizeof(string), "Foram Carregados: %i", total_car);
		print(string);
		return 1;
	}
	return 0;
}

//------------------------------------------------------------------------------
public split(const strsrc[], strdest[][], delimiter)
{
	new i, li;
	new aNum;
	new len;
	while(i <= strlen(strsrc)){
	    if(strsrc[i]==delimiter || i==strlen(strsrc)){
	        len = strmid(strdest[aNum], strsrc, li, i, 128);
	        strdest[aNum][len] = 0;
	        li = i+1;
	        aNum++;
		}
		i++;
	}
	return 1;
}
ela simplesmente tem que cria os carros listados no arquivo mais o problema й que ela so cria o carro da primeira linha
Reply
#4

idx < strlen(minhaarray)
Reply
#5

SAMP\Server SAMP\Servidor\samp03bsvr_R2_win32\filterscripts\Ca rSpawn.pwn(46) : error 048: array dimensions do not match

Quote:

idx < strlen(minhaarray)

Reply
#6

new line[256];
while(fread(file,line,sizeof(line),false))
Reply
#7

Quote:
Originally Posted by Programador
Посмотреть сообщение
new line[256];
while(fread(file,line,sizeof(line),false))
Nгo Funcionou

O Cуdigo Ficou Assim:

Код:
public LoadCars()
{
	new carrCoords[16][64];
	//new strFromFile2[256];
	new File: file = fopen("vehicles/spawns.cfg", io_read);
	if (file)
	{
		new line[256];
		//fread(file, strFromFile2);
		//split(strFromFile2, carrCoords, '|');
		while(fread(file,line,sizeof(line),false))
		{
			new  modelid, Float:x,Float:y,Float:z,Float:angle,color1,color2,respawn_delay,use_random_colors;
			split(line, carrCoords, '|');
			modelid = strval(carrCoords[0]);
			x = floatstr(carrCoords[1]);
			y = floatstr(carrCoords[2]);
			z = floatstr(carrCoords[3]);
			angle = floatstr(carrCoords[4]);
			color1 = strval(carrCoords[5]);
			color2 = strval(carrCoords[6]);
			respawn_delay = strval(carrCoords[7]);
			use_random_colors = strval(carrCoords[8]);
			
		 	if (use_random_colors == 1)
			 {
			   color1 = random(255);
			   color2 = random(255);
			 }
			if (LastCarID == 0)
			{
				LastCarID = CreateVehicle(modelid ,x,y,z,angle,color1,color2,respawn_delay);
			}
			else
			{
				new Float:XLastVehicle;
				new Float:YLastVehicle;
				new Float:ZLastVehicle;
				GetVehiclePos(LastCarID, XLastVehicle,YLastVehicle,ZLastVehicle);
				if (floatcmp(x,XLastVehicle) == 1 && floatcmp(y,YLastVehicle) == 1 && floatcmp(z,ZLastVehicle) == 1)
				{
					LastCarID = CreateVehicle(modelid ,x,y,z,angle,color1,color2,respawn_delay);
				}
			}
		}
		fclose(file);
		//new string[128];
		//format(string, sizeof(string), "Foram Carregados: %i", total_car);
		//print(string);
		return 1;
	}
	return 0;
}
Carregou Somente 1 Carro
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)