SA-MP Forums Archive
GetPlayerSpeed - 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)
+--- Thread: GetPlayerSpeed (/showthread.php?tid=322262)



GetPlayerSpeed - Dripac - 01.03.2012

This is what i currently have

pawn Код:
stock GetPlayerSpeed(playerid,bool:kmh)
{
    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);
}
What i want:
1: It should calculate in kmh, currently it's mph
2: It should count all numbers, for example 1 kmh, 2 kmh, 3 kmh etc (Currently if i press W it instantly shows 15kmh)

I will give +rep (4points) to the one who helps me!


Re: GetPlayerSpeed - iTorran - 01.03.2012

pawn Код:
public OnPlayerUpdate(playerid) // You could use something better
{
    GetPlayerSpeed(playerid, true);
    return 1;
}



Re: GetPlayerSpeed - Dripac - 01.03.2012

Quote:
Originally Posted by iTorran
Посмотреть сообщение
pawn Код:
public OnPlayerUpdate(playerid) // You could use something better
{
    GetPlayerSpeed(playerid, true);
    return 1;
}
It's still the same


Re: GetPlayerSpeed - milanosie - 01.03.2012

pawn Код:
new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*143.666667;
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i Km/h",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
    }
}



Re: GetPlayerSpeed - Dripac - 01.03.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
pawn Код:
new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*143.666667;
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i Km/h",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
    }
}
Your code is totally different


Re: GetPlayerSpeed - Ballu Miaa - 01.03.2012

Quote:
Originally Posted by Dripac
Посмотреть сообщение
This is what i currently have

pawn Код:
stock GetPlayerSpeed(playerid,bool:kmh)
{
    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);
}
What i want:
1: It should calculate in kmh, currently it's mph
2: It should count all numbers, for example 1 kmh, 2 kmh, 3 kmh etc (Currently if i press W it instantly shows 15kmh)

I will give +rep (4points) to the one who helps me!
I am not that good at Maths. To Convert it from kph to mph. I hope you get it converted soon.
But i would like to use this function for my game mode? Can i? Will keep your credits?

Can you give me the correct usage for this function as well


Re: GetPlayerSpeed - milanosie - 01.03.2012

pawn Код:
new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*143.666667;
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i Km/h",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
    }
}



Re: GetPlayerSpeed - Ballu Miaa - 01.03.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
pawn Код:
new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*143.666667;
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i Km/h",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
    }
}
This is what the author of this thread said when you first pasted this here as a reply mate:
Quote:
Originally Posted by Dripac
Посмотреть сообщение
Your code is totally different



Re: GetPlayerSpeed - milanosie - 01.03.2012

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
This is what the author of this thread said when you first pasted this here as a reply mate:
Didnt mean to double post,


Re: GetPlayerSpeed - iPLEOMAX - 01.03.2012

Paste it on top of the script:

pawn Код:
stock Float:GetPlayerSpeed(playerid, bool:KMH)
{
    new Float:Speed, Float:vX, Float:vY, Float:vZ;
    if(!IsPlayerInAnyVehicle(playerid)) GetPlayerVelocity(playerid, vX, vY, vZ);
    else GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
    Speed = floatsqroot(((vX*vX)+(vY*vY))+(vZ*vZ));
    return KMH ? (Speed*100.0) : (Speed*62.1371);
}