Distance :) - 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: Distance :) (
/showthread.php?tid=418561)
Distance :) -
audriuxxx - 25.02.2013
Hi,
Code:
new Float:vPOS[ MAX_PLAYERS ][ 3 ];
public OnPlayerStateChange( playerid, newstate, oldstate )
{
if( newstate == PLAYER_STATE_DRIVER )
{
GetVehiclePos( GetPlayerVehicleID( playerid ), vPOS[ playerid ][ 0 ], vPOS[ playerid ][ 1 ], vPOS[ playerid ][ 1 ] );
SetTimerEx("Speed", 1000, true, "d", playerid );
}
return 1;
}
forward Speed( playerid );
public Speed( playerid )
{
new STRINGSPPEED[ 50 ];
format(STRINGSPPEED,50,"* Speed: %f",GetVehicleDistanceFromPoint(GetPlayerVehicleID( playerid ),vPOS[ playerid ][ 0 ],vPOS[ playerid ][ 1 ],vPOS[ playerid ][ 2 ] ) );
SendClientMessage( playerid, -1, STRINGSPPEED );
GetVehiclePos( GetPlayerVehicleID( playerid ), vPOS[ playerid ][ 0 ], vPOS[ playerid ][ 1 ], vPOS[ playerid ][ 1 ] );
}
I drive by the car, and when 1 sec is pass i get
* Speed: 1578 about that, but i go forward about 5 metres
![Cheesy](images/smilies/biggrin.png)
and when am not moving distance is about 1000-1600. But i think this have to be zero, because from last point distance don't change, please look at code, maybe you see any mistakes.
Sorry for my bad English
AW: Distance :) -
NaS - 25.02.2013
Last line:
Code:
GetVehiclePos( GetPlayerVehicleID( playerid ), vPOS[ playerid ][ 0 ], vPOS[ playerid ][ 1 ], vPOS[ playerid ][ 1 ] );
Should be
Code:
GetVehiclePos( GetPlayerVehicleID( playerid ), vPOS[ playerid ][ 0 ], vPOS[ playerid ][ 1 ], vPOS[ playerid ][ 2 ] );
You used the Y slot for the Z coordinate too.
PS: Use the method sscarface said, it's clearly better.
Re: Distance :) -
sscarface - 25.02.2013
remove ur old and add this.
PHP Code:
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)) * 200.28625;
return floatround(ST[3]);
}
and here is
PHP Code:
format(STRINGSPPEED,50,"* Speed: %f", GetPlayerSpeed(playerID));
Re: Distance :) -
Babul - 25.02.2013
...and feel free to remove any "floatabs" - since a negative number powered gets a positive number as result, i dont see any sense in it.