Speed-O-Meter problem
#1

It is solved!

Jo,

I'm trying to learn more about float functions etc. (I'm not good in math :/)
However I made a speed-o-meter, but it's only working for 50% : It's only working when I drive to the North or the East. (It displays the speed okay)
Here's the function:

pawn Код:
func:GetVehicleSpeed(vehicleid)
{
    new Float:v_vX, Float:v_vY, Float:v_vZ, Float:XYZ, Float:_ret;
    GetVehicleVelocity(vehicleid, v_vX, v_vY, v_vZ);
   
    _ret = floatmul( ( ( (v_vX) + (v_vX) ) * 2 ) + ( ( (v_vY) + (v_vY) ) * 2 ) + ( ( (v_vZ) + (v_vZ) ) * 2 ) , v_vX + v_vY + v_vZ);
    _ret = floatpower(_ret, 2);
    XYZ = v_vX + v_vY + v_vZ;
   
    return floatround(_ret + XYZ * 99, floatround_ceil);
}
And this is where I update the textdraw:

pawn Код:
CB:UpdateVehicles()
{
    new str[15];
    loop:MAX_VEHICLES(i, 0){
        if(!IsAnyPlayerInVehicle(i)) continue;
        if(GetVehicleSpeed(i) == 0) format(str, 15, "Speed: 0");
        else if(GetVehicleSpeed(i) > 0 && GetVehicleSpeed(i) < 80) format(str, 15, "Speed: ~g~%d", GetVehicleSpeed(i));
        elseif(GetVehicleSpeed(i) > 80 && GetVehicleSpeed(i) < 120) format(str, 15, "Speed: ~y~%d", GetVehicleSpeed(i));
        elseif(GetVehicleSpeed(i) > 120) format(str, 15, "Speed: ~r~%d", GetVehicleSpeed(i));
    }
    ploop(i) TextDrawSetString(VehicleSpeed[i], str);
    return 1;
}
ps I made the next macro's that I'm using:
pawn Код:
#define func:%0(%1) stock %0(%1)
#define CB:%0(%1) forward %0(%1); public %0(%1)
#define loop:%0(%1, %2) for(new %1 = %2; %1 < %0; %1++)
#define ploop(%0) for(new %0 = 0; %0 < MAX_SLOTS; %0++) if(IsPlayerConnected(%0) && !IsPlayerNPC(%0))
Does anyone know why this's happening?

- Kevin
Reply
#2

I guess X and Y is only East and North, maybe you need to add -X and -Y for West and South
Reply
#3

Ehm okay I'll try

EDIT:
Thanks, it worked
This's the function btw

pawn Код:
func:GetVehicleSpeed(vehicleid)
{
    new Float:v_vX, Float:v_vY, Float:v_vZ, Float:XYZ, Float:_ret;
    GetVehicleVelocity(vehicleid, v_vX, v_vY, v_vZ);

    _ret = floatmul( ( ( (v_vX) + (v_vX) ) * 2 ) + ( ( (v_vY) + (v_vY) ) * 2 ) + ( ( (v_vZ) + (v_vZ) ) * 2 ) , v_vX + v_vY + v_vZ);
    _ret = floatpower(_ret, 2);
    XYZ = v_vX + v_vY + v_vZ;

    if(v_vX > 0 || v_vY > 0 || v_vX == 0 || v_vY == 0)
        return floatround(floatabs(_ret + XYZ * 99), floatround_ceil);
    elseif(v_vX < 0 || v_vY < 0)
        return floatround(floatabs(_ret + -XYZ * 99), floatround_ceil);
    return floatround(floatabs(_ret + XYZ * 99), floatround_ceil);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)