GetPlayerSpeed, No timers-Player Speed instantly
#1

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.
Reply
#2

Good job.
Reply
#3

Is x,y and z in meters or what?
Reply
#4

hmm, very nice.
Reply
#5

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.
Reply
#6

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);
Reply
#7

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

this is a lot better than with GetPlayerPos

Reply
#8

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.
Reply
#9

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.
Reply
#10

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 ^
Reply
#11

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.
Reply
#12

I prefer my own GetPlayerSpeed...^^
Reply
#13

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
Reply
#14

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?
Reply
#15

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.
Reply
#16

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

Yeah, good job, but... redundant code?
Reply
#17


Quote:

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

Kinda.
Reply
#18

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.
Reply
#19

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

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;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)