SA-MP Forums Archive
Getting KPH for a speedo. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting KPH for a speedo. (/showthread.php?tid=215176)



Getting KPH for a speedo. - Haydz - 22.01.2011

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.


Re: Getting KPH for a speedo. - Fj0rtizFredde - 22.01.2011

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)


Re: Getting KPH for a speedo. - blackwave - 22.01.2011

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]);
}



Re: Getting KPH for a speedo. - Haydz - 22.01.2011

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.