Shooting vehicle - 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: Shooting vehicle (
/showthread.php?tid=488094)
Shooting vehicle -
KubiPL - 16.01.2014
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
AW: Shooting vehicle -
BloodyEric - 16.01.2014
It should be the offset relative to the center of the vehicle, not the actual world position.
Re: Shooting vehicle -
IstuntmanI - 16.01.2014
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;
}
Re: Shooting vehicle -
KubiPL - 16.01.2014
Ah, okay thanks
Now work fine.