SA-MP Forums Archive
GetVehicleVelocity help. - 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: GetVehicleVelocity help. (/showthread.php?tid=114619)



GetVehicleVelocity help. - Christopher. - 20.12.2009

Ok, So heres my code:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/speed", cmdtext, true, 10) == 0)
	{
	    new Float:XX, Float:YY, Float:ZZ, Speed[MAX_PLAYERS], SpeedMessage[128];
		GetVehicleVelocity(GetPlayerVehicleID(playerid), XX, YY, ZZ);
		Speed[playerid] = XX+YY+ZZ;
        format(SpeedMessage, sizeof(SpeedMessage), "Your current speed: %d", Speed[playerid]);
		return 1;
	}
	return 0;
}
Heres the error:

Код:
E:\Users\Chris\Desktop\speed.pwn(36) : warning 213: tag mismatch
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Line i'm getting the error on:

Код:
Speed[playerid] = XX+YY+ZZ;
I'm not sure why im getting the error, I thought i was doing it correctly, Help is much obliged.



Re: GetVehicleVelocity help. - s0nic - 20.12.2009

You can just use it like this:
pawn Код:
format(SpeedMessage, sizeof(SpeedMessage), "Your current speed: %d", XX+YY+ZZ);
Should work how you would want it..


Re: GetVehicleVelocity help. - Christopher. - 20.12.2009

Hmmm, This gives some strange readings :




Re: GetVehicleVelocity help. - s0nic - 20.12.2009

Well first of all your adding them together..And ive never messed with the velocity functions so idk what to tell you..but are you trying to get the speed as in to make it return as what a speedometer would do?


Re: GetVehicleVelocity help. - Christopher. - 20.12.2009

Quote:
Originally Posted by Killaz/s0nic
Well first of all your adding them together..And ive never messed with the velocity functions so idk what to tell you..but are you trying to get the speed as in to make it return as what a speedometer would do?
Yea, I'm trying to make it return what a speedo would, And seif thanks, It just returns minus numbers now haha : /.


Re: GetVehicleVelocity help. - lolumadd - 20.12.2009

pawn Код:
stock GetPlayerSpeedSpeedo(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);
}
This will get mph or kmh of your vehicle. Good luck on scripting!


Re: GetVehicleVelocity help. - Christopher. - 20.12.2009

Quote:
Originally Posted by lolumadd [cod5server.tk
]
pawn Код:
stock GetPlayerSpeedSpeedo(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);
}
This will get mph or kmh of your vehicle. Good luck on scripting!
How would i use this, Thanks chris.


Re: GetVehicleVelocity help. - cptnsausage - 20.12.2009

try this

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/speed", cmdtext, true, 10) == 0)
	{
	    new Float:XX, Float:YY, Float:ZZ, Float:Speed[MAX_PLAYERS], SpeedMessage[128];
		GetVehicleVelocity(GetPlayerVehicleID(playerid), XX, YY, ZZ);
		Speed[playerid] = XX+YY+ZZ;
        format(SpeedMessage, sizeof(SpeedMessage), "Your current speed: %f", Speed[playerid]);
		return 1;
	}
	return 0;
}
OR

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/speed", cmdtext, true, 10) == 0)
	{
	    new Float:XX, Float:YY, Float:ZZ, Float:Speed[MAX_PLAYERS], SpeedMessage[128];
		GetVehicleVelocity(GetPlayerVehicleID(playerid), XX, YY, ZZ);
		Speed[playerid] = XX+YY+ZZ;
        format(SpeedMessage, sizeof(SpeedMessage), "Your current speed: %d", floatround(Speed[playerid]));
		return 1;
	}
	return 0;
}
I've been out of things for a couple years here but if I remember correctly then ur prob is trying to assign a float value to an integer based variable array so one of thwe 2 options above should fix it for ya


Re: GetVehicleVelocity help. - lolumadd - 20.12.2009

Quote:
Originally Posted by Chris - X-Host
Quote:
Originally Posted by lolumadd [cod5server.tk
]
pawn Код:
stock GetPlayerSpeedSpeedo(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);
}
This will get mph or kmh of your vehicle. Good luck on scripting!
How would i use this, Thanks chris.
MPH:
pawn Код:
format(string, sizeof(string), You're speed: %d", GetPlayerSpeedSpeedo(playerid, false));
KMH:
pawn Код:
format(string, sizeof(string), You're speed: %d", GetPlayerSpeedSpeedo(playerid, true));