GetPlayerDistanceFromPoint
#1

pawn Код:
forward Float:GetDistanceBetweenPlayers(p1,p2);
pawn Код:
stock Float:GetDistanceBetweenPlayers(p1,p2){
    new Float:x1,Float:y1,Float:z1,Float:x3,Float:y3,Float:z3;
    if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
        return -1.00;
    }
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x3,y3,z3);
    return floatsqroot(floatpower(floatabs(floatsub(x3,x1)),2)+floatpower(floatabs(floatsub(y3,y1)),2)+floatpower(floatabs(floatsub(z3,z1)),2));
}
pawn Код:
CMD:i( playerid, params[ ] )
{
    new ID, string[ 128 ], string2[ 128 ], name[ MAX_PLAYER_NAME ];
    new Float:Distance = GetDistanceBetweenPlayers(playerid,ID);
    if( sscanf( params, "u", ID ) ) return SendClientMessage( playerid, COLOR_WHITE, "USAGE: /i [id]" );
    if( IsPlayerConnected( ID ) == 0) return SendClientMessage( playerid, COLOR_RED, "Player is not connected!" );
    GetPlayerName( ID, name, MAX_PLAYER_NAME );

    new carid = GetPlayerVehicleID( ID );
    TextDrawShowForPlayer( playerid, info1 );
    TextDrawShowForPlayer( playerid, info0 );
    if( !IsPlayerInAnyVehicle( ID ) )
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Distance:~w~%0.2f~n~~g~Vehicle:~w~On Foot", name, ID, ReturnPlayerZone( ID ), Distance );
    }
    else
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Distance:~w~%0.2f~n~~g~Vehicle:~w~%s", name, ID, ReturnPlayerZone( ID ), Distance, VehicleNames[ GetVehicleModel( carid ) - 400 ] );
    }
    TextDrawSetString( info1, string );
    return 1;
}
Its only showing the distance between you and id 0 no matter what id you put in: http://i.imgur.com/qYr2Q.jpg
Reply
#2

Код:
new Float:X, Float:Y, Float:Z;
GetPlayerPos( ID, X, Y, Z );
and use
Код:
GetPlayerDistanceFromPoint( playerid, X, Y, Z );
Reply
#3

Don't use 256 for string value when the max on SA-MP is 128.
Max Name Length is 20, not 60.
pawn Код:
CMD:i( playerid, params[ ] )
{
    new ID, string[ 128 ], string2[ 128 ], name[ MAX_PLAYER_NAME ], Float:p_x, Float:p_y, Float:p_z;
    if( sscanf( params, "u", ID ) ) return SendClientMessage( playerid, COLOR_WHITE, "USAGE: /i [id]" );
    if( IsPlayerConnected( ID ) == 0) return SendClientMessage( playerid, COLOR_RED, "Player is not connected!" );
    GetPlayerName( ID, name, MAX_PLAYER_NAME );
    GetPlayerPos( ID, p_x, p_y, p_z );
    // Do Something;
    GetPlayerDistanceFromPoint( ID, p_x, p_y, p_z );
    new carid = GetPlayerVehicleID( ID );
    TextDrawShowForPlayer( playerid, text44 );
    TextDrawShowForPlayer( playerid, text45 );
    TextDrawShowForPlayer( playerid, PCBOX );
    if( !IsPlayerInAnyVehicle( ID ) )
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Money:~w~%d~n~~g~Wanted Level:~w~%d~n~~g~Drive:~w~none", name, ID, ReturnPlayerZone( ID ), GetPlayerMoney( ID ), GetPlayerWantedLevel( ID ) );
    }
    else
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Wanted Level:~w~%d~n~~g~Vehicle:~w~%s", name, ID, ReturnPlayerZone( ID ), GetPlayerWantedLevel( ID ), VehicleNames[ GetVehicleModel( carid ) - 400 ] );
    }
    TextDrawSetString( text44, string );
    format( string2, 128, "~n~~n~~n~~n~~n~~n~~n~~w~Type ~r~~h~LMB ~w~For Hide These~n~~w~Boxes!" );
    TextDrawSetString( text45, string2 );
    return 1;
}
Reply
#4

pawn Код:
CMD:i( playerid, params[ ] )
{
    new ID, string[ 128 ], string2[ 128 ], name[ MAX_PLAYER_NAME ];
    new Float:Distance = GetDistanceBetweenPlayers(playerid,ID);
    if( sscanf( params, "u", ID ) ) return SendClientMessage( playerid, COLOR_WHITE, "USAGE: /i [id]" );
    if( IsPlayerConnected( ID ) == 0) return SendClientMessage( playerid, COLOR_RED, "Player is not connected!" );
    GetPlayerName( ID, name, MAX_PLAYER_NAME );

    new carid = GetPlayerVehicleID( ID );
    TextDrawShowForPlayer( playerid, text44 );
    TextDrawShowForPlayer( playerid, text45 );
    TextDrawShowForPlayer( playerid, PCBOX );
    if( !IsPlayerInAnyVehicle( ID ) )
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Distance:~w~%s~n~~g~Vehicle:~w~On Foot", name, ID, ReturnPlayerZone( ID ), Distance );
    }
    else
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Distance:~w~%s~n~~g~Vehicle:~w~%s", name, ID, ReturnPlayerZone( ID ), Distance, VehicleNames[ GetVehicleModel( carid ) - 400 ] );
    }
    TextDrawSetString( text44, string );
    format( string2, 128, "~n~~n~~n~~n~~n~~n~~n~~w~Type ~r~~h~LMB ~w~For Hide These~n~~w~Boxes!" );
    TextDrawSetString( text45, string2 );
    return 1;
}
Updated to this but shows
http://i.imgur.com/D9O2p.jpg
Reply
#5

double post ;S
Reply
#6

Use %0.2f instead of %s on the distance
Reply
#7

i did and still same thing.

Look at the first code i posted i changed it
Reply
#8

pawn Код:
CMD:i( playerid, params[ ] )
{
    new ID, string[ 128 ], string2[ 128 ], name[ MAX_PLAYER_NAME ];
    if( sscanf( params, "u", ID ) ) return SendClientMessage( playerid, COLOR_WHITE, "USAGE: /i [id]" );// you had this after using GetDistance
    new Float:Distance = GetDistanceBetweenPlayers(playerid,ID);
    if( IsPlayerConnected( ID ) == 0) return SendClientMessage( playerid, COLOR_RED, "Player is not connected!" );
    GetPlayerName( ID, name, MAX_PLAYER_NAME );
    new carid = GetPlayerVehicleID( ID );
    TextDrawShowForPlayer( playerid, info1 );
    TextDrawShowForPlayer( playerid, info0 );
    if( !IsPlayerInAnyVehicle( ID ) )
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Distance:~w~%0.2f~n~~g~Vehicle:~w~On Foot", name, ID, ReturnPlayerZone( ID ), Distance );
    }
    else
    {
        format( string, 128, "~y~Player Info: ~r~~h~%s[%d]~n~~n~~g~Location:~w~%s~n~~g~Distance:~w~%0.2f~n~~g~Vehicle:~w~%s", name, ID, ReturnPlayerZone( ID ), Distance, VehicleNames[ GetVehicleModel( carid ) - 400 ] );
    }
    TextDrawSetString( info1, string );
    return 1;
}
Reply
#9

i would rep you if i could :S
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)