Problem with Speedometer
#1

I was in the midst of making an accurate speedometer for getting exact top speeds of vehicles with or without NOS, for anti speed hack purposes.

I started with a timer, that checked every 500 milliseconds (half second) for the current position. With that I used the 3D coordinate distance formula of:

Код:
D = SquareRootOf( [(X2-X)*(X2-X)] + [(Y2-Y)*(Y2-Y)] + [(Z2-Z)*(Z2-Z)] )
To measure exactly how long 1 San Andreas Measuring Unit (SAMU) was I teleported a friend to be 1 SAMU west of me and we measured the distance between heads. Conclusive of about 3.5 feet.

So 'D' * 3.5 was our answer to Feet per/Half Second. I multiplied that by 7200 (2 Halfs of a second times 60 seconds in a minute times 60 minutes in an hour) and divided that by 5280 (feet per mile). What I discovered was the CJ ran an average of about 17 MPH! That just barely beats the human sustained speed record (over 4 hours). The NRG at full speed clocked at around a normal (but surprisingly slow) 105 MPH average.

When my friend clocked it however, he was driving at 200+ MPH. I assumed it was due to the lag (server is on my laptop). So I made a formula to go to OnPlayerUpdate instead of per Half Second. What I did was:

Код:
(D * 3.5) * [1000 / (GetTickCount() - OldTickCount)] * 3600
the [1000 / (GetTickCount() - OldTickCount)] should be how many ticks it would have taken to reach 1 second times the 3600 (60 seconds per minute times 60 minutes per hour).

What I had instead of accurate speedometer was a crazed speedometer reading number far over and changing at spastic speeds.

Anyone have any ideas what happened?
Reply
#2

Units are meters (1 meter ~= 3.3 feets)
Reply
#3

Okay, doesn't solve the issue though.

EDIT* Why would they make it 1 meter? The game is based in America and Rockstar North is based in America. Seems to me like they would use the Imperial System instead of Metric
Reply
#4

It doesn't matter where they are located.. Meter is the distance unit of the international system of units.
Reply
#5

Hmm, it seems like the right formula. What would cause it to reach outrageous numbers though?
Reply
#6

Код:
public SpeedOMeter() {
	new
		Float:distance,
		Speed,
		distance2;
	foreachEx(i) {
	  if(PlayerInfo[i][bSpeedo]) {
			GetPlayerPos(i,PlayerInfo[i][fnX],PlayerInfo[i][fnY],PlayerInfo[i][fnZ]);
			if(IsPlayerInAnyVehicle(i)) {
				PlayerInfo[i][foX]-=PlayerInfo[i][fnX];
				PlayerInfo[i][foY]-=PlayerInfo[i][fnY];
				PlayerInfo[i][foZ]-=PlayerInfo[i][fnZ];
				distance=(PlayerInfo[i][foX] * PlayerInfo[i][foX]) + (PlayerInfo[i][foY] * PlayerInfo[i][foY]) + (PlayerInfo[i][foZ] * PlayerInfo[i][foZ]);
				distance2=floatround(floatpower(distance,0.5)*3600);
				#if defined DISPLAY_MODE_TD
				switch(PlayerInfo[i][speedo_type]) {
					case KMH: {
	   				Speed=floatround(distance2/1000);
						format(DisplayString,sizeof(DisplayString),"%d Kmh",Speed);
					}
					case MPH: {
	   				Speed=floatround(distance2/1609);
						format(DisplayString,sizeof(DisplayString),"%d Mph",Speed);
					}
				}
				TextDrawSetString(PlayerInfo[i][PlayerDraw],DisplayString);
				#else
				switch(PlayerInfo[i][speedo_type]) {
					case KMH: {
						Speed=floatround(distance2/1000);//KMH
						format(DisplayString,sizeof(DisplayString),"~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~%d Kmh",Speed);
					}
					case MPH: {
						Speed=floatround(distance2/1609); //MPH
						format(DisplayString,sizeof(DisplayString),"~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~%d Mph",Speed);
					}
				}
				GameTextForPlayer(i,DisplayString,gSpeedOMeterUpdate_GT,3);
				#endif
			}
			PlayerInfo[i][foX]=PlayerInfo[i][fnX];
			PlayerInfo[i][foY]=PlayerInfo[i][fnY];
			PlayerInfo[i][foZ]=PlayerInfo[i][fnZ];
		}
	}
	return 1;
}

public SpeedName() {
	new
		Float:distance,
		Speed,
		distance2;
	foreachEx(i) {
		if(PlayerInfo[i][bSpeedo]) {
			GetPlayerPos(i,PlayerInfo[i][fnX],PlayerInfo[i][fnY],PlayerInfo[i][fnZ]);
			if(IsPlayerInAnyVehicle(i)) {
				sCurrentZoneName=GetXYZZoneName(PlayerInfo[i][fnX],PlayerInfo[i][fnY],PlayerInfo[i][fnZ]);
				PlayerInfo[i][foX]-=PlayerInfo[i][fnX];
				PlayerInfo[i][foY]-=PlayerInfo[i][fnY];
				PlayerInfo[i][foZ]-=PlayerInfo[i][fnZ];
				distance=(PlayerInfo[i][foX] * PlayerInfo[i][foX]) + (PlayerInfo[i][foY] * PlayerInfo[i][foY]) + (PlayerInfo[i][foZ] * PlayerInfo[i][foZ]);
				distance2=floatround(floatpower(distance,0.5)*3600);
				#if defined DISPLAY_MODE_TD
				switch(PlayerInfo[i][speedo_type]) {
					case KMH: {
						Speed=floatround(distance2/1000); //KMH
				 		format(DisplayString,sizeof(DisplayString),"%s ~n~ %d Kmh",sCurrentZoneName,Speed);
					}
					case MPH: {
						Speed=floatround(distance2/1609);// MPH
				 		format(DisplayString,sizeof(DisplayString),"%s ~n~ %d Mph",sCurrentZoneName,Speed);
					}
				}
				TextDrawSetString(PlayerInfo[i][PlayerDraw],DisplayString);
				#else
				switch(PlayerInfo[i][speedo_type]) {
					case KMH: {
						Speed=floatround(distance2/1000); //KMH
				 		format(DisplayString,sizeof(DisplayString),"~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ %s ~n~ %d Kmh",sCurrentZoneName,Speed);
					}
					case MPH: {
						Speed=floatround(distance2/1609);// MPH
				 		format(DisplayString,sizeof(DisplayString),"~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ %s ~n~ %d Mph",sCurrentZoneName,Speed);
					}
				}
				GameTextForPlayer(i,DisplayString,gSpeedNameUpdate_GT,3);
				#endif
	  		}
	 		PlayerInfo[i][foX]=PlayerInfo[i][fnX];
			PlayerInfo[i][foY]=PlayerInfo[i][fnY];
			PlayerInfo[i][foZ]=PlayerInfo[i][fnZ];
		}
	}
	return 1;
}
Dont know if this helps but its a speedometer from a filterscript i installed ,its found in gAdmin located in filterscripts section,it shows speedometer when you are driving ,and i wonder if it shows it when you spec someone?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)