SetVehicleHealth problem (Angle problem SOLVED)
#1

As you can see in the title i have a problem with the angle of the vehicle after gamemode restart,i have writen a script myself to save the coordinates on the callback onPlayerExitVehicle, it saves the coordinates into arrays and than onGameModeExit it updates the mysql with the new angle, and after restart on onGameModeInit i have a new mysql select for the cars. So the problem is that when i go to my server i find the car in the correct position, but just the angle is not right, where is the problem? There is my scripts:

OnGameModeInit:
Code:
//---------------------------------User Cars----------------------------
	new ucarsquery[128];
	new usercar[12][10];
	new ucarsn;
	format(ucarsquery, sizeof(ucarsquery), "SELECT id,owner,modelid,spawn_x,spawn_y,spawn_z,angle,color1,color2,health,tune,locked FROM `ucars`");
	samp_mysql_query(ucarsquery);
	samp_mysql_store_result();
	while(samp_mysql_fetch_row(ucarsquery)) {
		split(ucarsquery, usercar, '|');
		format(playercar[ucarsn][car_uniqueid],256,"%s",usercar[0]);
		format(playercar[ucarsn][car_owner],256,"%s",usercar[1]);
		playercar[ucarsn][car_modelid] = strval(usercar[2]);
		playercar[ucarsn][car_spawnX] = floatstr(usercar[3]);
		playercar[ucarsn][car_spawnY] = floatstr(usercar[4]);
		playercar[ucarsn][car_spawnZ] = floatstr(usercar[5]);
		playercar[ucarsn][car_spawnA] = floatstr(usercar[6]);
		playercar[ucarsn][car_color1] = strval(usercar[7]);
		playercar[ucarsn][car_color2] = strval(usercar[8]);
		playercar[ucarsn][car_health] = floatstr(usercar[9]);
		playercar[ucarsn][car_tune] = strval(usercar[10]);
		playercar[ucarsn][car_locked] = strval(usercar[11]);
		playercar[ucarsn][car_id] = CreateVehicle(playercar[ucarsn][car_modelid],playercar[ucarsn][car_spawnX],playercar[ucarsn][car_spawnY],playercar[ucarsn][car_spawnZ],playercar[ucarsn][car_spawnA],playercar[ucarsn][car_color1],playercar[ucarsn][car_color2],-1);
		SetVehicleHealth(playercar[ucarsn][car_id],playercar[ucarsn][car_health]);
		ucarsn++;
	}
OnGameModeExit:
Code:
	new ucarsn;
	new saveucarslocation[256];
	new saveucarsinformation[256];
	for (ucarsn=0;ucarsn<MAX_CARS; ucarsn++) {
		format(saveucarslocation, sizeof(saveucarslocation), "UPDATE `ucars` SET `spawn_x` = '%f', `spawn_y` = '%f', `spawn_z` = '%f', `angle` = '%f' WHERE `owner` = '%s';",playercar[ucarsn][car_spawnX],playercar[ucarsn][car_spawnY],playercar[ucarsn][car_spawnZ],playercar[ucarsn][car_spawnA],playercar[ucarsn][car_owner]);
		format(saveucarsinformation, sizeof(saveucarsinformation), "UPDATE `ucars` SET `color1` = '%i', `color2` = '%i', `health` = '%f', `tune` = '%s', `locked` = '%i' WHERE `owner` = '%s';",playercar[ucarsn][car_color1],playercar[ucarsn][car_color2],playercar[ucarsn][car_health],playercar[ucarsn][car_tune],playercar[ucarsn][car_locked],playercar[ucarsn][car_owner]);
		samp_mysql_query(saveucarslocation);
		samp_mysql_query(saveucarsinformation);
	}
	return 1;
}
OnPlayerExitVehicle:
Code:
	new ucarsn;
	new Float:x, Float:y, Float:z, Float:a, Float:health;
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, a);
	GetVehicleHealth(vehicleid, health);
	for (ucarsn=0;ucarsn<MAX_CARS; ucarsn++) {
		if (vehicleid == playercar[ucarsn][car_id]) {
			playercar[ucarsn][car_spawnX] = x;
			playercar[ucarsn][car_spawnY] = y;
			playercar[ucarsn][car_spawnZ] = z;
			playercar[ucarsn][car_spawnA] = a;
			playercar[ucarsn][car_health] = health;
		}
	}
	return 1;
}
Second question: I save the health of the car when the player exits the car, and i set the health of the car on gamemodeinit but the health is still 1000.00 of the car.. even know in database there is 364.4654 (the car was almsot on fire), but it doesn't work, any ideas?

Thank you for you help.
Reply
#2

cars that have not been entered are not synced therefore you may find them at the wrong position or angle.
Reply
#3

You're using GetPlayerFacingAngle, Try using GetVehicleZAngle. Player Angle is the same as when the player went in the vehicle, where as the Vehicle Angle is where the vehicle is currently looking based on the Player's Update.
Reply
#4

Yeah but https://sampwiki.blast.hk/wiki/GetVehicleZAngle]GetVehicleZAngle[/url] is bugged

Quote:

This function does not return a specific value, it's best to simply ignore it.

Reply
#5

It doesn't return the value, it stores it in It's second parameter
Reply
#6

Thank you for your answers, i'm going to try GetVehicleZAngle and i will give u a feedback.

Edit: GetVehicleZAngle + GetVehiclePos worked perfectly, thank you very much.

Second question: I save the health of the car when the player exits the car, and i set the health of the car on gamemodeinit but the health is still 1000.00 of the car.. even know in database there is 364.4654 (the car was almsot on fire), but it doesn't work, any ideas?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)