SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 03/08/2009, 12:29 PM   #1
Paranoja
Big Clucker
 
Join Date: Jul 2008
Posts: 67
Reputation: 0
Default SetVehicleHealth problem (Angle problem SOLVED)

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.
Paranoja is offline  
Old 03/08/2009, 12:45 PM   #2
mamorunl
High-roller
 
mamorunl's Avatar
 
Join Date: Feb 2007
Location: Groningen/Netherlands
Posts: 1,938
Reputation: 2246
Default Re: Angle of the Vehicle problem

cars that have not been entered are not synced therefore you may find them at the wrong position or angle.
mamorunl is offline  
Old 03/08/2009, 12:48 PM   #3
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default Re: Angle of the Vehicle problem

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.
Joe Staff is offline  
Old 03/08/2009, 12:53 PM   #4
Jason_Gregory
Big Clucker
 
Join Date: Sep 2008
Posts: 52
Reputation: 1
Default Re: Angle of the Vehicle problem

Yeah but http://wiki.sa-mp.com/wiki/GetVehicleZAngle]GetVehicleZAngle[/url] is bugged

Quote:
This function does not return a specific value, it's best to simply ignore it.
Jason_Gregory is offline  
Old 03/08/2009, 01:01 PM   #5
dice7
High-roller
 
Join Date: Apr 2009
Location: Slovenia
Posts: 2,200
Reputation: 22
Default Re: Angle of the Vehicle problem

It doesn't return the value, it stores it in It's second parameter
dice7 is offline  
Old 03/08/2009, 01:06 PM   #6
Paranoja
Big Clucker
 
Join Date: Jul 2008
Posts: 67
Reputation: 0
Default Re: Angle of the Vehicle problem

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?
Paranoja is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vehicle angle problem Kar Help Archive 3 18/05/2010 02:06 PM
Setting a bot's facing angle problem bpeterson Help Archive 2 14/05/2010 09:35 PM
Info Pickup problem [SOLVED] New problem now..... Juanxz Help Archive 2 22/01/2010 07:19 AM
SetVehicleHealth dont work on first time? BMW_M3_GTR Help Archive 1 20/09/2009 05:07 PM


All times are GMT. The time now is 05:08 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.