GetVehicleVelocity help.
#1

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

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

Hmmm, This gives some strange readings :

Reply
#4

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)