SA-MP Forums Archive
GetPlayerSpeed, No timers-Player Speed instantly - 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: GetPlayerSpeed, No timers-Player Speed instantly (/showthread.php?tid=95200)

Pages: 1 2


GetPlayerSpeed, No timers-Player Speed instantly - misco - 02.09.2009

Finally the Velocity functions are here.

Код:
stock GetPlayerSpeed(playerid,bool:kmh) // by misco
{
  new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}
(edited)
Example usage:
Код:
if (!strcmp("/myspeed", cmdtext, true))
	{
		new str[128];
		format(str,128,"My speed is %d km/h and %d mph !",GetPlayerSpeed(playerid,true),GetPlayerSpeed(playerid,false));
		SendClientMessage(playerid,0xFFFFFFAA,str);
		return 1;
	}
Returned values seems real.


Re: GetPlayerSpeed, No timers-Player Speed instantly - [HUN]Gamestar - 02.09.2009

Good job.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Double-O-Seven - 02.09.2009

Is x,y and z in meters or what?


Re: GetPlayerSpeed, No timers-Player Speed instantly - [NL]Bank - 02.09.2009

hmm, very nice.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Fireburn - 02.09.2009

Can I ask why you are doing the floatsubstraction? You're substracting it with nothing so that doesn't make any sense does it?
Anyways, looks nice.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Rac3r - 02.09.2009

Quote:
Originally Posted by Double-O-Seven
Is x,y and z in meters or what?
Probably the gta metric system, SetPlayerPos( playerid , 0.1 , 0.1, 0.1);


Re: GetPlayerSpeed, No timers-Player Speed instantly - ғαιιοцт - 02.09.2009

I already had this in my speedometer, but the calculation works a little different

this is a lot better than with GetPlayerPos




Re: GetPlayerSpeed, No timers-Player Speed instantly - Rac3r - 02.09.2009

Yes.

Question : If you drive off a cliff and fall, does the function return the actual speed the vehicle is falling at, or does it return the speed the engine is reving at?
If I had SA-MP I would try myself.


Re: GetPlayerSpeed, No timers-Player Speed instantly - JaTochNietDan - 02.09.2009

Quote:
Originally Posted by [LSD
Rac3r ]
Yes.

Question : If you drive off a cliff and fall, does the function return the actual speed the vehicle is falling at, or does it return the speed the engine is reving at?
If I had SA-MP I would try myself.
The speed that it is falling at.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Jay_ - 02.09.2009

Quote:
Originally Posted by Fireburn
Can I ask why you are doing the floatsubstraction? You're substracting it with nothing so that doesn't make any sense does it?
Anyways, looks nice.
Indeed ^


Re: GetPlayerSpeed, No timers-Player Speed instantly - misco - 02.09.2009

Quote:
Originally Posted by Jay_
Quote:
Originally Posted by Fireburn
Can I ask why you are doing the floatsubstraction? You're substracting it with nothing so that doesn't make any sense does it?
Anyways, looks nice.
Indeed ^
It has something to do with distance calculation. My bad. You can edit it for yourself ill change it tomorow. Thanks for attention.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Double-O-Seven - 03.09.2009

I prefer my own GetPlayerSpeed...^^



Re: GetPlayerSpeed, No timers-Player Speed instantly - Rainmaker - 03.09.2009

Quote:
Originally Posted by Double-O-Seven
I prefer my own GetPlayerSpeed...^^
What might be the difference ? there is only one math way to get the result speed anyway. Probably different names of varibales ? lol


Re: GetPlayerSpeed, No timers-Player Speed instantly - Double-O-Seven - 03.09.2009

I mean I do not use GetVehicleVelocity to get the players speed because I don't know how to get the speed correct... Is the x, y and z meters/second or km/h for each direction or what?


Re: GetPlayerSpeed, No timers-Player Speed instantly - Harry_Gaill - 03.09.2009

Quote:
Originally Posted by Double-O-Seven
I mean I do not use GetVehicleVelocity to get the players speed because I don't know how to get the speed correct... Is the x, y and z meters/second or km/h for each direction or what?
Yeah, would be good to know what unit it uses.



Re: GetPlayerSpeed, No timers-Player Speed instantly - Westie - 03.09.2009

I thought GTA:SA units were meters? I'm slightly retarded.

Yeah, good job, but... redundant code?


Re: GetPlayerSpeed, No timers-Player Speed instantly - Harry_Gaill - 03.09.2009


Quote:

Yeah, good job, but... redundant code?

Kinda.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Zeex - 03.09.2009

Why do you use "floatabs"? Squared value is ALWAYS positive!
pawn Код:
floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
^ Looks more easier and does the same thing.


Re: GetPlayerSpeed, No timers-Player Speed instantly - Rainmaker - 03.09.2009

Zeex : Its not that simple with multiplying floats I think ...


Re: GetPlayerSpeed, No timers-Player Speed instantly - Zeex - 03.09.2009

Quote:
Originally Posted by Rainmaker
Zeex : Its not that simple with multiplying floats I think ...
OK, look into float.inc and you will see:
pawn Код:
native Float:operator*(Float:oper1, Float:oper2) = floatmul;