SA-MP Forums Archive
MPProjectPointOnVehicle goes wrong! - 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: MPProjectPointOnVehicle goes wrong! (/showthread.php?tid=352321)



MPProjectPointOnVehicle goes wrong! - zgintasz - 19.06.2012

Hi guys,

I'm using JernejL MathPlugin. I'm trying to use MPProjectPointOnVehicle function, but it doesn't do what it should.

pawn Код:
COMMAND:blablabla(playerid, params[])
{
    if( isnull( params ) ) return SendClientMessage( playerid, 0xFF0000FF, "wrong, bla bla bla" );
    new
        Float:x,
        Float:y,
        Float:z,
        Float:a,
        car
    ;
    GetPlayerFacingAngle( playerid, a );
    GetPlayerPos( playerid, x, y, z );
    if( IsPlayerInAnyVehicle( playerid ) )
    {
        DestroyVehicle( GetPlayerVehicleID( playerid ) );
        RemovePlayerFromVehicle( playerid );
    }
    car = CreateVehicle( strval( params ), x, y, z, a, 6, 6, 1000 );
    PutPlayerInVehicle( playerid, car, 0 );

    /*new
        obj = CreateObject( 325, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
    ;
    AttachObjectToVehicle( obj, car, 0.0, -2.89, 0.0, 0.0, 0.0, 0.0 );*/

    new
        Float:result[ 3 ]
    ;
    MPProjectPointOnVehicle( car, 0.0, -2.89, 0.0, result[ 0 ], result[ 1 ], result[ 2 ], 1 );
    CreateObject( 325, result[ 0 ], result[ 1 ], result[ 2 ], 0.0, 0.0, 0.0 );
    return 1;
}
Using AttachObjectToVehicle is perfect:


But MPProjectPointOnvehicle doesn't work(object is in different pos in different angles)


Please, help someone to fix this !

Thanks!


Re: MPProjectPointOnVehicle goes wrong! - Faisal_khan - 19.06.2012

The calculation you have done is wrong maybe. Try to take them in opp. sides.


Re: MPProjectPointOnVehicle goes wrong! - Ray0 - 19.06.2012

MPProjectPointOnVehicle doesn't work correctly for a vehicle that's just been spawned, so just introduce a timer:

pawn Код:
forward MPTimer(Vid, Float:x, Float:y, Float:z);

COMMAND:test(playerid, params[])
{
    if( isnull( params ) ) return SendClientMessage( playerid, 0xFF0000FF, "wrong, bla bla bla" );
    new
        Float:x,
        Float:y,
        Float:z,
        Float:a,
        car
    ;
    GetPlayerFacingAngle( playerid, a );
    GetPlayerPos( playerid, x, y, z );
    if( IsPlayerInAnyVehicle( playerid ) )
    {
        DestroyVehicle( GetPlayerVehicleID( playerid ) );
        RemovePlayerFromVehicle( playerid );
    }
    car = CreateVehicle( strval( params ), x, y, z, a, 6, 6, 1000 );
    PutPlayerInVehicle( playerid, car, 0 );
    SetTimerEx("MPTimer", 100, false, "ifff", car, x, y, z);
    return 1;
}

public MPTimer(Vid, Float:x, Float:y, Float:z)
{
    /*new
        obj = CreateObject( 325, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
    ;
    AttachObjectToVehicle( obj, car, 0.0, -2.89, 0.0, 0.0, 0.0, 0.0 );*/

    new
        Float:result[ 3 ]
    ;
    MPProjectPointOnVehicle( Vid, 0.0, 2.89, 0.0, result[0], result[1], result[2]);
    CreateObject( 325, result[0]+x, result[1]+y, result[2]+z, 0.0, 0.0, 0.0 );
    return 1;
}



Re: MPProjectPointOnVehicle goes wrong! - zgintasz - 19.06.2012

It works fine - thanks a lot .


Re: MPProjectPointOnVehicle goes wrong! - JernejL - 20.06.2012

Responding to your PM:

It does not take "angles"!!! It project a point on the vehicle in vehicle's world space.


Re: MPProjectPointOnVehicle goes wrong! - zgintasz - 22.06.2012

What the hell, again . It returns different coords, if I'm in vehicle or not!! If I'm in vehicle, the coords is perfect.

pawn Код:
new
    Float:offsetPos[ 6 ]
;
GetVehicleModelInfo( GetVehicleModel( vehicleid ), VEHICLE_MODEL_INFO_SIZE, offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
printf( "GetVehicleModelInfo: %f, %f, %f", offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
offsetPos[ 1 ] = offsetPos[ 1 ] / 2.0;
//offsetPos[ 1 ] = -offsetPos[ 1 ];

SetTimerEx( "fakeris", 200, false, "if", vehicleid, offsetPos[ 1 ] );
MPProjectPointOnVehicle( vehicleid, 0.0, offsetPos[ 1 ], 0.0, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 1 );
printf( "MPProjectPointOnVehicle: %f, %f, %f", offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ] );

CreateObject( 325, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 0.0, 0.0, 0.0 );



Re: MPProjectPointOnVehicle goes wrong! - JernejL - 22.06.2012

then pre-prepare coords incase you exitted the vehicle or something?


Re: MPProjectPointOnVehicle goes wrong! - zgintasz - 22.06.2012

Quote:
Originally Posted by JernejL
Посмотреть сообщение
then pre-prepare coords incase you exitted the vehicle or something?
Do you mean, when player exits vehicle, I get(using MPProjectPointOnVehicle) and save coords in to a variable? But what if vehicle will move when there is no player in it(someone will "push" it)?


Re: MPProjectPointOnVehicle goes wrong! - Ray0 - 22.06.2012

How are you getting the vehicle id?
When the player is in the vehicle it is easy using GetPlayerVehicleID(playerid)
But do you have a way to tell which vehicle id to use when the player is not in a vehicle?


Re: MPProjectPointOnVehicle goes wrong! - zgintasz - 22.06.2012

Thanks for reply, here it is:

Код:
// command
COMMAND:cmd(playerid, params[])
{
	IsPlayerNearVehicleBoot( playerid, GetPlayerVehicleID( playerid ) );
	return 1;
}
// another part
new
	Float:mPos[ 3 ]
;
for( new i; i < MAX_VEHICLES; i++ )
{
    GetVehiclePos( i, mPos[ 0 ], mPos[ 1 ], mPos[ 2 ] );
    if( IsPlayerInRangeOfPoint( playerid, 3.5, mPos[ 0 ], mPos[ 1 ], mPos[ 2 ] ) )
    {
		function( playerid, i );
		break;
	}
}

// another part
stock function( playerid, vehicleid )
{
	new
		Float:offsetPos[ 6 ]
	;
	GetVehicleModelInfo( GetVehicleModel( vehicleid ), VEHICLE_MODEL_INFO_SIZE, offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
	printf( "GetVehicleModelInfo: %f, %f, %f", offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
	offsetPos[ 1 ] = offsetPos[ 1 ] / 2.0;
	//offsetPos[ 1 ] = -offsetPos[ 1 ];

	MPProjectPointOnVehicle( vehicleid, 0.0, offsetPos[ 1 ], 0.0, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 1 );
	printf( "MPProjectPointOnVehicle: %f, %f, %f", offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ] );

	CreateObject( 325, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 0.0, 0.0, 0.0 );
	return 1;
}