SA-MP Forums Archive
OnPlayerWeaponShot sometimes does not react? - 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: OnPlayerWeaponShot sometimes does not react? (/showthread.php?tid=636501)



OnPlayerWeaponShot sometimes does not react? - ax1 - 28.06.2017

Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    new szString[144];
    format(szString, sizeof(szString), "Weapon %i fired. hittype: %i   hitid: %i   pos: %f, %f, %f", weaponid, hittype, hitid, fX, fY, fZ);
    SendClientMessage(playerid, -1, szString);

    return 1;
}
https://www.youtube.com/watch?v=dLGe...ature=*********

as you can see in the video, when you're shooting at certain points, OnPlayerWeaponShot doesnt react. What could be the cause of it?


Re: OnPlayerWeaponShot sometimes does not react? - Luicy. - 28.06.2017

wrong topic


Re: OnPlayerWeaponShot sometimes does not react? - Meller - 28.06.2017

Try debugging a bit further:
PHP код:
#if !defined PRESSED
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#endif

public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if (
PRESSED(KEY_FIRE) && !IsPlayerInAnyVehicle(playerid) && GetPlayerWeapon(playerid) != 0)
    {
        
SendClientMessage(playerid, -1"[Debug] Should have shot a bullet.");
        
SetTimerEx("DebugBulletInfo"500false"i"playerid);
    }
    return 
1;
}

forward DebugBulletInfo(playerid);
public 
DebugBulletInfo(playerid) {
      new 
lsString[128],
            
Float:fOriginXFloat:fOriginYFloat:fOriginZ,
            
Float:fHitPosXFloat:fHitPosYFloat:fHitPosZ;
        
GetPlayerLastShotVectors(playeridfOriginXfOriginYfOriginZfHitPosXfHitPosYfHitPosZ);
        
format(lsString128"Bullet info. launch pos: %f, %f, %f - hit pos: %f, %f, %f"fOriginXfOriginYfOriginZfHitPosXfHitPosYfHitPosZ);
        
SendClientMessage(playerid, -1lsString);

OBS: written straight from browser, might have some warnings.


Re: OnPlayerWeaponShot sometimes does not react? - NaS - 28.06.2017

If no bullet is actually shot (which is the case when you shoot the sky or a target that is too far for the collision to be loaded), the callback won't be called. Simple as that.

The cause is a lack of a bullet.

Note: this is for the Sniper (since Sniper works a bit different from other guns). Take other weapons and it works (although the hit point retrieved by GetPlayerLastShotVector will be wrong - 23.040445, 0.0, 0.0 mostly - this depends where you are).


Re: OnPlayerWeaponShot sometimes does not react? - ax1 - 28.06.2017

Quote:
Originally Posted by NaS
Посмотреть сообщение
If no bullet is actually shot (which is the case when you shoot the sky or a target that is too far for the collision to be loaded), the callback won't be called. Simple as that.

The cause is a lack of a bullet.

Note: this is for the Sniper (since Sniper works a bit different from other guns). Take other weapons and it works (although the hit point retrieved by GetPlayerLastShotVector will be wrong - 23.040445, 0.0, 0.0 mostly).
Yes, I just find that out myself.
And I also found out that OnPlayerWeaponShot is not called if a bullet connects with a dynamic object. If you shoot object created with CreateObject it works fine, but if you shoot at dynmic object OnPlayerWeaponShot doesn't react


Re: OnPlayerWeaponShot sometimes does not react? - NaS - 28.06.2017

Quote:
Originally Posted by ax1
Посмотреть сообщение
Yes, I just find that out myself.
And I also found out that OnPlayerWeaponShot is not called if a bullet connects with a dynamic object. If you shoot object created with CreateObject it works fine, but if you shoot at dynmic object OnPlayerWeaponShot doesn't react
Add the callback OnPlayerShootDynamicObject to your script (or any script) and it will work again.