Shooting vehicle
#1

I made somethink like grep hook and when I shot vehicle, the pos in callback is 0.0

Log in console from callback:
[19:36:16] BULLET HIT type: 2 with weapon 22. HITID: 1714 POS (-0.269142, 2.660293, 0.314309)

Code:
Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
	if(fX != 0 && fY != 0 && fZ != 0)
	{
	    new Float:a;
		GetPlayerFacingAngle(playerid, a);
		fX -= floatsin(-a, degrees)/2;
		fY -= floatcos(-a, degrees)/2;
		
		SetPlayerPos(playerid, fX, fY, fZ+0.3);
	}
	printf("BULLET HIT type: %d with weapon %d. HITID: %d POS (%f, %f, %f)", hittype, weaponid, hitid, fX, fY, fZ);
	return 1;
}
Vehicle pos:
176.3295,-7.4976,1.6480,180.2088
Reply
#2

It should be the offset relative to the center of the vehicle, not the actual world position.
Reply
#3

When you hit an object/vehicle/player, the coordinates are actually offsets, so for the hitid position you have to add the offsets.
pawn Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(fX != 0 && fY != 0 && fZ != 0)
    {
        new Float:a;
        GetPlayerFacingAngle(playerid, a);
        fX -= floatsin(-a, degrees)/2;
        fY -= floatcos(-a, degrees)/2;
       
        new Float:X, Float:Y, Float:Z;
        switch( hittype )
        {
            case BULLET_HIT_TYPE_PLAYER: GetPlayerPos( hitid, X, Y, Z );
            case BULLET_HIT_TYPE_VEHICLE: GetVehiclePos( hitid, X, Y, Z );
            case BULLET_HIT_TYPE_OBJECT: GetObjectPos( hitid, X, Y, Z );
        }

        SetPlayerPos(playerid, X + fX, Y + fY, Z + fZ+0.3);
    }
    printf("BULLET HIT type: %d with weapon %d. HITID: %d POS (%f, %f, %f)", hittype, weaponid, hitid, fX, fY, fZ);
    return 1;
}
Reply
#4

Ah, okay thanks
Now work fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)