Wierd loading bug.
#1

I have this simple enum:

Код:
enum uVeh
{
	vID,
	vModelID,
	Float:vPosX,
	Float:vPosY,
	Float:vPosZ,
	Float:vPosR,
	vOwnerID,
	vOwnerName[MAX_PLAYER_NAME],
	vMod1,
	vMod2,
	vMod3,
	vMod4,
	vMod5,
	vMod6,
	vMod7,
	vMod8,
	vMod9,
	vMod10,
	vMod11,
	vMod12,
	vMod13,
	vMod14,
	vMod15,
	vColor1,
	vColor2,
	vCarPlate[256],
	vPurch[256]
}
new vehStat[MAX_VEHICLES][uVeh];
And this is how I load the vehicles.

Код:
forward IniUserVeh();
public IniUserVeh()
{
	new quer[128];
	format(quer, sizeof(quer), "SELECT * FROM `uservehicles`");
	new Cache: result4 = mysql_query(handle, quer);
	new x, count, countveh, c;
	for(new z = 0; z < MAX_VEHICLES; z++)
	{
		c = GetVehicleModel(z);
		if(c >= 400)
		{
			countveh++;
			printf("%d", countveh);
		}
	}
 	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		x = countveh++;
		cache_get_field_content(i, "vehicleModelID", result); vehStat[x][vModelID] = strval(result);
		cache_get_field_content(i, "vehiclePosX", result); vehStat[x][vPosX] = floatstr(result);
		cache_get_field_content(i, "vehiclePosY", result); vehStat[x][vPosY] = floatstr(result);
		cache_get_field_content(i, "vehiclePosZ", result); vehStat[x][vPosZ] = floatstr(result);
		cache_get_field_content(i, "vehiclePosRot", result); vehStat[x][vPosR] = floatstr(result);
		cache_get_field_content(i, "vehicleOwner", result); vehStat[x][vOwnerID] = strval(result);
		cache_get_field_content(i, "vehicleOwnerName", result); format(vehStat[x][vOwnerName], MAX_PLAYER_NAME, "%s", result);
		cache_get_field_content(i, "vehicleMod1", result); vehStat[x][vMod1] = strval(result);
		cache_get_field_content(i, "vehicleMod2", result); vehStat[x][vMod2] = strval(result);
		cache_get_field_content(i, "vehicleMod3", result); vehStat[x][vMod3] = strval(result);
		cache_get_field_content(i, "vehicleMod4", result); vehStat[x][vMod4] = strval(result);
		cache_get_field_content(i, "vehicleMod5", result); vehStat[x][vMod5] = strval(result);
		cache_get_field_content(i, "vehicleMod6", result); vehStat[x][vMod6] = strval(result);
		cache_get_field_content(i, "vehicleMod7", result); vehStat[x][vMod7] = strval(result);
		cache_get_field_content(i, "vehicleMod8", result); vehStat[x][vMod8] = strval(result);
		cache_get_field_content(i, "vehicleMod9", result); vehStat[x][vMod9] = strval(result);
		cache_get_field_content(i, "vehicleMod10", result); vehStat[x][vMod10] = strval(result);
		cache_get_field_content(i, "vehicleMod11", result); vehStat[x][vMod11] = strval(result);
		cache_get_field_content(i, "vehicleMod12", result); vehStat[x][vMod12] = strval(result);
		cache_get_field_content(i, "vehicleMod13", result); vehStat[x][vMod13] = strval(result);
		cache_get_field_content(i, "vehicleMod14", result); vehStat[x][vMod14] = strval(result);
		cache_get_field_content(i, "vehicleMod15", result); vehStat[x][vMod15] = strval(result);
		cache_get_field_content(i, "vehicleColor1", result); vehStat[x][vColor1] = strval(result);
		cache_get_field_content(i, "vehicleColor2", result); vehStat[x][vColor2] = strval(result);
		cache_get_field_content(i, "vehicleCarPlate", result); format(vehStat[x][vCarPlate], 32, "%s", result);
		cache_get_field_content(i, "vehiclePurchaseDate", result); format(vehStat[x][vPurch], 32, "%s", result);
		count++;
		CreateVehicle(vehStat[x][vModelID], vehStat[x][vPosX], vehStat[x][vPosY], vehStat[x][vPosZ], vehStat[x][vPosR], vehStat[x][vColor1], vehStat[x][vColor2], -1);
		SetVehicleNumberPlate(x, vehStat[x][vCarPlate]);
		printf("#2 %d | %s", countveh, vehStat[x][vOwnerName]);
	}
	printf("[DEBUG] Loaded %d user vehicles.", count);
	cache_delete(result4);
	return 1;
}
Everything loads up fine, even the "printf("#2 %d | %s", countveh, vehStat[x][vOwnerName]);" displays the right values.
But when I go ingame and enter a vehicle, I should get this message: Aceasta %s este detinuta de %s. Foloseste /vehinfo pentru mai multe detalii.

This is the hook:

Код:
Hook:45_OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER)
	{
		new vehid = GetPlayerVehicleID(playerid);
		new string[256];
		new veh = GetVehicleModel(vehid);
		new name[64];
		format(name, sizeof(name), "%s", VehicleNames[veh - 400]);
		if(strfind(name, "a", true) != -1)
		{
			format(string, sizeof(string), "Aceasta %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[vehid][vOwnerName]);
		}
		else
		{
			format(string, sizeof(string), "Acest %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[vehid][vOwnerName]);
		}
		SCM(playerid, COOL_GREEN, string);
	}
}
I get the message, but the second %s is not displaying anything. As I said, everything is loading correctly, and I'm at the right vehicle too.

Did I do something wrong?

Let's say I have 1 vehicle. If I enter it, the string doesn't display the variable.
But if I have 2 vehicles, then my first vehicle will send the message with the right variable, and the second vehicle won't.
This applies to every amount of cars. Only the last car doesn't display the variable.
Reply
#2

Actually u are doing it wrong, that what is not displaying anything its because vehid parameter in enumator, you cant use real vehicle id for ID inside enumator.

Lets say when you load vehicles and count starts from 0, and its goes on... but problem is when you have lets say 5vehicles created before that loop, so you enter car id 550, and u are searching in enumator 550 ID but actually ID is 545.

So what should you do is something like this, first add in enumator vVehicle, then replace vehicle create with this
Код:
vehStat[x][vVehicle] = CreateVehicle(vehStat[x][vModelID], vehStat[x][vPosX], vehStat[x][vPosY], vehStat[x][vPosZ], vehStat[x][vPosR], vehStat[x][vColor1], vehStat[x][vColor2], -1);
and replace hook with this:
Код:
Hook:45_OnPlayerStateChange(playerid, newstate, oldstate) {
	if(newstate == PLAYER_STATE_DRIVER) {
		new baid;
		new vehid = GetPlayerVehicleID(playerid);
		new string[256];
		new veh = GetVehicleModel(vehid);
		new name[64];
		format(name, sizeof(name), "%s", VehicleNames[veh - 400]);
		for(new b = 0; b < sizeof(vehStat); b++) {
			if(veh == vehStat[b][vVehicle]) {
				baid = b;
				break;
			}
		}
		if(strfind(name, "a", true) != -1) {
			format(string, sizeof(string), "Aceasta %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[baid][vOwnerName]);
		}
		else {
			format(string, sizeof(string), "Acest %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[baid][vOwnerName]);
		}
		SCM(playerid, COOL_GREEN, string);
	}
}
i think that should work...
Reply
#3

First you need to get arguments for createvehicle (model, color, positions)

cache_get_field_content(i, "vehicleModelID", result);
new tmp_model = strval(result);

vid = CreateVehicle(tmp_model...

After this you can add values to array.

vehStat[vid][value] = ...

By the way, why you using cache like that?
Better way:

new tmp_model = cache_get_field_content_int(row, "vehicleModelID");
Reply
#4

Quote:
Originally Posted by Dusan01
Посмотреть сообщение
Actually u are doing it wrong, that what is not displaying anything its because vehid parameter in enumator, you cant use real vehicle id for ID inside enumator.

Lets say when you load vehicles and count starts from 0, and its goes on... but problem is when you have lets say 5vehicles created before that loop, so you enter car id 550, and u are searching in enumator 550 ID but actually ID is 545.

So what should you do is something like this, first add in enumator vVehicle, then replace vehicle create with this
Код:
vehStat[x][vVehicle] = CreateVehicle(vehStat[x][vModelID], vehStat[x][vPosX], vehStat[x][vPosY], vehStat[x][vPosZ], vehStat[x][vPosR], vehStat[x][vColor1], vehStat[x][vColor2], -1);
and replace hook with this:
Код:
Hook:45_OnPlayerStateChange(playerid, newstate, oldstate) {
	if(newstate == PLAYER_STATE_DRIVER) {
		new baid;
		new vehid = GetPlayerVehicleID(playerid);
		new string[256];
		new veh = GetVehicleModel(vehid);
		new name[64];
		format(name, sizeof(name), "%s", VehicleNames[veh - 400]);
		for(new b = 0; b < sizeof(vehStat); b++) {
			if(veh == vehStat[b][vVehicle]) {
				baid = b;
				break;
			}
		}
		if(strfind(name, "a", true) != -1) {
			format(string, sizeof(string), "Aceasta %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[baid][vOwnerName]);
		}
		else {
			format(string, sizeof(string), "Acest %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[baid][vOwnerName]);
		}
		SCM(playerid, COOL_GREEN, string);
	}
}
i think that should work...
That's why I used:

Код:
	for(new z = 0; z < MAX_VEHICLES; z++)
	{
		c = GetVehicleModel(z);
		if(c >= 400)
		{
			countveh++;
			printf("%d", countveh);
		}
	}
This detects how many vehicles there are on the server.
After that, I've used "x = countveh++" to add +1 to the vehicle ids.
I went in game, and the Id's we're right.
Reply
#5

Quote:
Originally Posted by Dusan01
Посмотреть сообщение
Actually u are doing it wrong, that what is not displaying anything its because vehid parameter in enumator, you cant use real vehicle id for ID inside enumator.

Lets say when you load vehicles and count starts from 0, and its goes on... but problem is when you have lets say 5vehicles created before that loop, so you enter car id 550, and u are searching in enumator 550 ID but actually ID is 545.

So what should you do is something like this, first add in enumator vVehicle, then replace vehicle create with this
Код:
vehStat[x][vVehicle] = CreateVehicle(vehStat[x][vModelID], vehStat[x][vPosX], vehStat[x][vPosY], vehStat[x][vPosZ], vehStat[x][vPosR], vehStat[x][vColor1], vehStat[x][vColor2], -1);
and replace hook with this:
Код:
Hook:45_OnPlayerStateChange(playerid, newstate, oldstate) {
	if(newstate == PLAYER_STATE_DRIVER) {
		new baid;
		new vehid = GetPlayerVehicleID(playerid);
		new string[256];
		new veh = GetVehicleModel(vehid);
		new name[64];
		format(name, sizeof(name), "%s", VehicleNames[veh - 400]);
		for(new b = 0; b < sizeof(vehStat); b++) {
			if(veh == vehStat[b][vVehicle]) {
				baid = b;
				break;
			}
		}
		if(strfind(name, "a", true) != -1) {
			format(string, sizeof(string), "Aceasta %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[baid][vOwnerName]);
		}
		else {
			format(string, sizeof(string), "Acest %s este detinut de %s. Foloseste /vehinfo pentru mai multe detalii.", name, vehStat[baid][vOwnerName]);
		}
		SCM(playerid, COOL_GREEN, string);
	}
}
i think that should work...
Nvm, thanks. It's working.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)