Getting KPH for a speedo.
#1

Hey guys, i'm posting here as i have no idea on how to get the players speed using GetVehicleVolcity. So if possible could i get some advice on what i need that would be helpful.

Cheers and thanks in advance.
Reply
#2

pawn Код:
stock GetPlayerSpeed(playerid, bool:kmh) // by misco
{
    new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
    if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
    rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
    return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}
Use it like: GetPlayerSpeed(playerid,true); (True = KPM and false is MPH.. I think)
Reply
#3

command:
pawn Код:
if(!strcmp(cmdtext, "/myself", true))
{
    format(string,sizeof(string),"My speed is %d km/h",GetPlayerSpeed(playerid));
    return GameTextForPlayer(playerid, string, 5000, 5);
}
pawn Код:
stock GetPlayerSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
        GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
        else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 100.3;
    return floatround(ST[3]);
}
Reply
#4

Quote:
Originally Posted by Fj0rtizFredde
Посмотреть сообщение
pawn Код:
stock GetPlayerSpeed(playerid, bool:kmh) // by misco
{
    new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
    if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
    rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
    return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}
Use it like: GetPlayerSpeed(playerid,true); (True = KPM and false is MPH.. I think)
Cheers, works like a charm.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)