Altitude command not working correctly
#1

Hello,

I've just created a fairly simple /getaltitude command just for testing the altitude stock before I develop it into a proper, updating altitude meter that works in helicopters and planes.

pawn Код:
CMD:altitude(playerid, params[])
{
    new alt[2];
    format(alt, sizeof(alt), "%d", GetAltitude(playerid));
    SendClientMessage(playerid, Col_Blue, alt);
    return 1;
}

stock GetAltitude(playerid)
{
    new Float:x, Float:y, Float:z, currentvehicle;
    currentvehicle = GetPlayerVehicleID(playerid);
    GetVehiclePos(currentvehicle, x, y, z);
    return floatround(z);
}
It works when I'm on an NRG for example, it works fine then, but when I get into a helicopter and fly up a bit, it definitely displays my Z position wrong.

Can anyone see any errors in the above code, or know why it's not working?
Reply
#2

What Does It Display When Your In The Helicopter?

Is It + or - From The NRG Z Coord?
Reply
#3

This should work, took me about 10 minutes to test and script the function. also based on my research they use GetPlayerPos not GetVehiclePos

pawn Код:
stock GetAltitude(playerid)
{
    new Float:Pos[3], _ReturnAltitude[ 12 ] ;
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    format(_ReturnAltitude, sizeof(_ReturnAltitude), "%.3f", Pos[2]);
    return _ReturnAltitude;
}
Sample of Usage
pawn Код:
CMD:altitude(playerid, params[])
{
    new alt[ 12 ];
    format( alt, sizeof( alt ), "%s", GetAltitude( playerid ) ); //use placeholder %s because we formatted it in GetAltitude
    SendClientMessage( playerid, -1, alt );
    return 1;
}
Result
pawn Код:
[22:49:13] 31.170766 //Helicopter in the roof
[22:49:20] 41.092250 //Increasing Height
[22:49:24] 63.062202 //Increasing Height
[22:49:33] 112.650802 //Increasing Height
[22:49:41] 150.716812 //Height the I've reached, then I descended
[22:49:51] 138.731140 //Descending heigh.
This

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
You need to use something like map andreas otherwise your altitude will never be accurate.
Reply
#4

You need to use something like map andreas otherwise your altitude will never be accurate.
Reply
#5

Thanks guys, for the help.

EDIT: I found out why my version wasn't working, I was only allowing 2 characters, so 1 of them being the null, only the first digit was being shown. On a bike it was showing them since it was less than 2 digits, in a helicopter it went to 4 or 3 when it meant 40 something or 30 something.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)