Radar Command Sending Wrong Message
#1

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

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

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

Oh, I just noticed that you're using MP/H, not KM/H. Anyways, good thing you fixed it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)