Function lag after while mysql_fetch_row
#1

I do this code for spawn car for each player when he spawn. The problem is that function getting weird. I know that because im testing my function by using simple print and that what i see is the problem with the while loop function and the 1 dimension of array a dont know why this function cant pass through 2d array. I can add that this function is run by global timer on gamemodeinit and it run once after few sec. MAX_PRIVATE_CARS_NO_PREMIUM have int size 2. Sorry for my bad english and thanks for help
Код:
SpawnCarForPlayer(pID)
{
	new query[256], PlayerName[MAX_PLAYER_NAME+1], Vehicle[MAX_PRIVATE_CARS_NO_PREMIUM][VEHICLES], rows, VehID, i;
	GetPlayerName(pID, PlayerName, MAX_PLAYER_NAME+1);
	format(query, sizeof(query), "SELECT * FROM vehicles WHERE owner='%s'", PlayerName);
	mysql_query(query);
	i = 1;
	rows = 0;
	mysql_store_result();
	rows = mysql_affected_rows();
	if(rows > 0)
	{
		while(mysql_fetch_row(query, "|"))
		{
			sscanf(query, "p<|>dds[25]dffffdd",
				Vehicle[i][DBVID],
				Vehicle[i][VUID],
				Vehicle[i][VOwner],
				Vehicle[i][VModel],
				Vehicle[i][VPos_x],
				Vehicle[i][VPos_y],
				Vehicle[i][VPos_z],
				Vehicle[i][VPos_angle],
				Vehicle[i][VColor1],
				Vehicle[i][VColor2]);
			i++;
		}
	}
	mysql_free_result();

	if(rows == 0) return 1;
	for(new j = 1; j < MAX_PRIVATE_CARS_NO_PREMIUM; j++)
	{
		VehID = CreateVehicle(Vehicle[j][VModel], Vehicle[j][VPos_x], Vehicle[j][VPos_y], Vehicle[j][VPos_z], Vehicle[j][VPos_angle], Vehicle[j][VColor1], Vehicle[j][VColor2], -1, 0);
		SetVehicleParamsEx(VehID, 0, 0, 0, 0, 0, 0, 0);
		format(query, sizeof(query), "UPDATE vehicles SET VUID='%d' WHERE owner='%s' AND  id='%d'", VehID, PlayerName, Vehicle[j][DBVID]);
		mysql_query(query);
		for(new k = 1; k < MAX_VEHICLES; k++)
		{
			if(pVeh[k][VUID] == 0)
			{
				pVeh[k][VUID] = VehID;
				format(pVeh[k][VOwner], MAX_PLAYER_NAME+1, "%s",  Vehicle[j][VOwner]);
				pVeh[k][VModel] = Vehicle[j][VModel];
				pVeh[k][VPos_x] = Vehicle[j][VPos_x];
				pVeh[k][VPos_y] = Vehicle[j][VPos_y];
				pVeh[k][VPos_z] = Vehicle[j][VPos_z];
				pVeh[k][VPos_angle] = Vehicle[j][VPos_angle];
				pVeh[k][VColor1] = Vehicle[j][VColor1];
				pVeh[k][VColor2] = Vehicle[j][VColor2];
				break;
			}
		}
	}

	for(new k = 0; k < MAX_VEHICLES; k++)
	{
		if(pVeh[k][VUID] != 0)
		{
			printf("%s", pVeh[k][VOwner]);
		}
	}
	return 1;
}
Reply
#2

Nvm fixed , it was problem with MAX_PRIVATE_CARS_NO_PREMIUM i has 2 size and i was set "i" variable from 1 so if query have more records than 1 the second record dont have space to put because i forgot about "0" index :/, stupid newbie mistake. Sory for take your time guys, you can close the thread.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)