SA-MP Forums Archive
SetVehicleHealth problem (Angle problem SOLVED) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: SetVehicleHealth problem (Angle problem SOLVED) (/showthread.php?tid=89633)



SetVehicleHealth problem (Angle problem SOLVED) - Paranoja - 03.08.2009

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.


Re: Angle of the Vehicle problem - mamorunl - 03.08.2009

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


Re: Angle of the Vehicle problem - Joe Staff - 03.08.2009

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.


Re: Angle of the Vehicle problem - Jason_Gregory - 03.08.2009

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.




Re: Angle of the Vehicle problem - dice7 - 03.08.2009

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


Re: Angle of the Vehicle problem - Paranoja - 03.08.2009

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?