Radar Command
#1

This command looks fine to me, but clearly I am missing something. It prints up to 5 and then stops. What's wrong with it?

pawn Код:
CMD:radar(playerid, params[])
{
    if(IsPlayerPolice(playerid))
    {
        new string[64];
        new vehicleid = GetNearestVehicle(playerid, 30.0);
        print("1");
       

        new Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, final_speed_int;
        if(vehicleid != 0)
        {
            print("2");
            GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
            print("3");
            final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*90;
            print("4");
            final_speed_int = floatround(final_speed,floatround_round);
            print("5");
       
            format(string, sizeof(string), "(RADAR) %s: %i mph", GetVehicleName(vehicleid), final_speed_int);
            print("6");
            SendClientMessage(playerid, COLOR_YELLOW, string);
            print("7");
        }
        else
        {
            SendClientMessage(playerid, COLOR_YELLOW, "(RADAR) No vehicles in range.");
        }
    }
    return 1;
}

stock GetNearestVehicle(playerid, Float:range)
{
    new     Float:p_X;
    new     Float:p_Y;
    new     Float:p_Z;

    new     Float:Distance;
    new     Float:vehdistance = range +1;
    new     nearestveh;

    GetPlayerPos(playerid, p_X, p_Y, p_Z);

    for(new vehicleid=1; vehicleid < MAX_VEHICLES; vehicleid++)
    {
        Distance = GetVehicleDistanceFromPoint(vehicleid, p_X, p_Y, p_Z);

        if(Distance <= range && Distance <= vehdistance)
        {
            nearestveh = vehicleid;
            vehdistance = Distance;
        }
    }

    return nearestveh;
}


stock GetVehicleName(vehicleid)
{
    new string[24];
    format(string,sizeof(string),"%s",vehNames[GetVehicleModel(vehicleid) - 400]);
    return string;
}
Reply
#2

Are you sure that your GetVehicleName function is working correctly (does it work elsewhere)?
Reply
#3

Quote:
Originally Posted by jakejohnsonusa
Посмотреть сообщение
Are you sure that your GetVehicleName function is working correctly (does it work elsewhere)?
No, actually. I'll test it real quick.

EDIT: Yes, it works.

pawn Код:
CMD:name(playerid, params[])
{
    new vehicleid;
    if(sscanf(params, "d", vehicleid)) return 1;
   
    new string[16];
    format(string, sizeof(string), "%s", GetVehicleName(vehicleid));
    SendClientMessage(playerid, -1, string);
    return 1;
}
I used this to test it.

EDIT 2: This must mean it's the GetNearestVehicle function, which also works elsewhere.

EDIT 3: I made a command to test GetNearestVehicle as well, and it's returning MAX_VEHICLES for some reason..

pawn Код:
CMD:near(playerid, params[])
{
    new vehicleid = GetNearestVehicle(playerid, 30.0);

    new string[16];
    format(string, sizeof(string), "%d", vehicleid);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)