Distance :)
#1

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 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
Reply
#2

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.
Reply
#3

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)); 
Reply
#4

...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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)