Radar Command Sending Wrong Message - 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)
+--- Thread: Radar Command Sending Wrong Message (
/showthread.php?tid=534937)
Radar Command Sending Wrong Message -
austin070 - 01.09.2014
pawn Код:
CMD:radar(playerid, params[])
{
if(IsPlayerPolice(playerid))
{
new v, Float: x, Float: y, Float: z;
while(++v < MAX_VEHICLES)
{
if(GetVehiclePos(v, x, y, z) && IsPlayerInRangeOfPoint(playerid, 30.0, x, y, z))
{
if(v != 0)
{
if(v == GetPlayerVehicleID(playerid)) continue;
new Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, final_speed_int;
new str[64];
GetVehicleVelocity(v,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*90;
final_speed_int = floatround(final_speed,floatround_round);
if(final_speed_int > 0)
{
format(str, sizeof(str), "(RADAR) %s: %i mph", GetVehicleName(v), final_speed_int);
SendClientMessage(playerid, COLOR_YELLOW, str);
}
else
{
SendClientMessage(playerid, COLOR_YELLOW, "(RADAR) No vehicles in range.");
print("final_speed_int > 0");
}
}
else
{
SendClientMessage(playerid, COLOR_YELLOW, "(RADAR) No vehicles in range.");
}
}
}
}
return 1;
}
This command is detecting the right amount of cars in the given radius, but it sends the "No vehicles in range" string under "if(final_speed_int > 0)" instead of the message that shows their speed. What did I do wrong?
Re: Radar Command Sending Wrong Message -
SickAttack - 01.09.2014
Your calculations is way off. Try this:
pawn Код:
new Float:pos[3], Float:speed, speed_int;
GetVehicleVelocity(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
speed = floatsqroot(((pos[0] * pos[0]) + (pos[1] * pos[1])) + (pos[2] * pos[2])) * 181.1166672;
speed_int = floatround(speed, floatround_round);
Re: Radar Command Sending Wrong Message -
austin070 - 01.09.2014
Quote:
Originally Posted by SickAttack
Your calculations is way off. Try this:
pawn Код:
new Float:pos[3], Float:speed, speed_int; GetVehicleVelocity(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]); speed = floatsqroot(((pos[0] * pos[0]) + (pos[1] * pos[1])) + (pos[2] * pos[2])) * 181.1166672; speed_int = floatround(speed, floatround_round);
|
How would that affect my issue? Plus, 181.1166672 makes the speed look very unrealistic.
EDIT: I fixed it by changing the "if(final_speed_int > 0)" line to:
pawn Код:
if(final_speed_int == 0) return SendClientMessage(playerid, COLOR_YELLOW, "(RADAR) No vehicles in range.");
Re: Radar Command Sending Wrong Message -
SickAttack - 01.09.2014
Oh, I just noticed that you're using MP/H, not KM/H. Anyways, good thing you fixed it.